1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-12 11:28:56 +00:00
trezor-wallet/src/components/DeviceHeader/index.js

151 lines
3.6 KiB
JavaScript
Raw Normal View History

import React from 'react';
2018-08-22 12:31:16 +00:00
import styled, { css } from 'styled-components';
import PropTypes from 'prop-types';
2018-08-27 10:17:27 +00:00
import {
getStatusColor,
getStatusName,
getStatus,
getVersion,
} from 'utils/device';
import TrezorImage from 'components/images/TrezorImage';
import colors from 'config/colors';
2018-12-11 15:44:32 +00:00
import { FONT_SIZE, FONT_WEIGHT } from 'config/variables';
const Wrapper = styled.div`
position: relative;
2018-09-24 14:40:38 +00:00
height: 70px;
width: 320px;
display: flex;
align-items: center;
background: ${props => (props.disabled ? colors.GRAY_LIGHT : 'transparent')};
background: ${props => (props.isSelected ? colors.WHITE : 'transparent')};
2018-08-23 15:26:29 +00:00
border-radius: 4px 0 0 0;
box-shadow: ${props => (props.disabled ? 'none' : '0 3px 8px rgba(0, 0, 0, 0.04)')};
2018-08-22 14:20:56 +00:00
${props => (props.isOpen || !props.isSelected) && css`
2018-08-22 14:20:56 +00:00
box-shadow: none;
`}
2018-08-27 10:17:27 +00:00
${props => props.isHoverable && !props.disabled && css`
2018-08-27 10:17:27 +00:00
&:hover {
background: ${colors.GRAY_LIGHT};
}
`}
`;
const ClickWrapper = styled.div`
width: 100%;
display: flex;
2018-08-22 10:59:22 +00:00
padding-left: 25px;
height: 100%;
align-items: center;
cursor: pointer;
2018-08-22 14:20:56 +00:00
${props => props.disabled && css`
2018-10-03 13:50:24 +00:00
cursor: default;
2018-08-22 14:20:56 +00:00
`}
`;
const LabelWrapper = styled.div`
2019-01-08 14:20:16 +00:00
flex: 1 1 auto;
padding-left: 18px;
2019-01-08 14:20:16 +00:00
overflow: hidden;
`;
const Name = styled.div`
display: block;
text-overflow: ellipsis;
overflow: hidden;
2018-09-23 10:59:06 +00:00
white-space: nowrap;
2018-12-11 15:44:32 +00:00
font-weight: ${FONT_WEIGHT.MEDIUM};
color: ${colors.TEXT_PRIMARY};
`;
const Status = styled.div`
display: block;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
2018-12-13 12:42:52 +00:00
font-size: ${FONT_SIZE.SMALL};
color: ${colors.TEXT_SECONDARY};
`;
const IconWrapper = styled.div`
padding-right: 25px;
display: flex;
2019-01-08 14:20:16 +00:00
flex: 1 0 0;
justify-content: flex-end;
`;
2018-08-22 10:59:22 +00:00
const ImageWrapper = styled.div`
position: relative;
`;
const Dot = styled.div`
border: 2px solid ${colors.WHITE};
border-radius: 50%;
position: absolute;
z-index: 10;
background: ${props => props.color};
top: -4px;
right: -3px;
width: 10px;
height: 10px;
`;
const DeviceHeader = ({
2018-10-03 13:50:24 +00:00
isOpen,
icon,
device,
isHoverable = true,
onClickWrapper,
isAccessible = true,
2018-10-03 13:50:24 +00:00
disabled = false,
isSelected = false,
className,
}) => {
const status = getStatus(device);
return (
<Wrapper
isSelected={isSelected}
isOpen={isOpen}
isHoverable={isHoverable}
disabled={disabled}
className={className}
>
<ClickWrapper
disabled={disabled}
onClick={onClickWrapper}
>
<ImageWrapper>
<Dot color={getStatusColor(status)} />
<TrezorImage model={getVersion(device)} />
</ImageWrapper>
<LabelWrapper>
<Name>{device.instanceLabel}</Name>
2019-01-08 14:20:16 +00:00
<Status title={getStatusName(status)}>{getStatusName(status)}</Status>
</LabelWrapper>
<IconWrapper>
{icon && !disabled && isAccessible && icon}
</IconWrapper>
</ClickWrapper>
</Wrapper>
);
};
2018-08-22 13:45:00 +00:00
DeviceHeader.propTypes = {
isAccessible: PropTypes.bool,
device: PropTypes.object,
icon: PropTypes.element,
isHoverable: PropTypes.bool,
disabled: PropTypes.bool,
isOpen: PropTypes.bool,
isSelected: PropTypes.bool,
onClickWrapper: PropTypes.func.isRequired,
className: PropTypes.string,
};
export default DeviceHeader;