2018-09-21 13:04:24 +00:00
|
|
|
import React from 'react';
|
2018-08-22 12:31:16 +00:00
|
|
|
import styled, { css } from 'styled-components';
|
2018-08-21 15:02:06 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-08-27 10:17:27 +00:00
|
|
|
import {
|
|
|
|
getStatusColor,
|
|
|
|
getStatusName,
|
|
|
|
getStatus,
|
|
|
|
getVersion,
|
|
|
|
} from 'utils/device';
|
2018-08-30 17:40:35 +00:00
|
|
|
import TrezorImage from 'components/images/TrezorImage';
|
2018-08-21 15:02:06 +00:00
|
|
|
import colors from 'config/colors';
|
2018-12-11 15:44:32 +00:00
|
|
|
import { FONT_SIZE, FONT_WEIGHT } from 'config/variables';
|
2018-08-21 15:02:06 +00:00
|
|
|
|
|
|
|
const Wrapper = styled.div`
|
|
|
|
position: relative;
|
2018-09-24 14:40:38 +00:00
|
|
|
height: 70px;
|
2018-08-21 15:02:06 +00:00
|
|
|
width: 320px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2018-09-21 13:04:24 +00:00
|
|
|
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;
|
2018-09-21 13:04:24 +00:00
|
|
|
box-shadow: ${props => (props.disabled ? 'none' : '0 3px 8px rgba(0, 0, 0, 0.04)')};
|
2018-08-22 14:20:56 +00:00
|
|
|
|
2018-09-21 13:04:24 +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
|
|
|
|
2018-09-25 12:36:07 +00:00
|
|
|
${props => props.isHoverable && !props.disabled && css`
|
2018-08-27 10:17:27 +00:00
|
|
|
&:hover {
|
|
|
|
background: ${colors.GRAY_LIGHT};
|
|
|
|
}
|
|
|
|
`}
|
2018-08-21 15:02:06 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const ClickWrapper = styled.div`
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
2018-08-22 10:59:22 +00:00
|
|
|
padding-left: 25px;
|
2018-08-21 15:02:06 +00:00
|
|
|
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
|
|
|
`}
|
2018-08-21 15:02:06 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const LabelWrapper = styled.div`
|
2019-01-08 14:20:16 +00:00
|
|
|
flex: 1 1 auto;
|
2018-08-21 15:02:06 +00:00
|
|
|
padding-left: 18px;
|
2019-01-08 14:20:16 +00:00
|
|
|
overflow: hidden;
|
2018-08-21 15:02:06 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
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};
|
2018-08-21 15:02:06 +00:00
|
|
|
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};
|
2018-08-21 15:02:06 +00:00
|
|
|
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-21 15:02:06 +00:00
|
|
|
`;
|
|
|
|
|
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;
|
|
|
|
`;
|
|
|
|
|
2018-09-21 13:04:24 +00:00
|
|
|
|
|
|
|
const DeviceHeader = ({
|
2018-10-03 13:50:24 +00:00
|
|
|
isOpen,
|
|
|
|
icon,
|
|
|
|
device,
|
|
|
|
isHoverable = true,
|
|
|
|
onClickWrapper,
|
2018-10-04 20:59:39 +00:00
|
|
|
isAccessible = true,
|
2018-10-03 13:50:24 +00:00
|
|
|
disabled = false,
|
|
|
|
isSelected = false,
|
2018-12-18 09:58:12 +00:00
|
|
|
className,
|
2018-09-21 13:04:24 +00:00
|
|
|
}) => {
|
|
|
|
const status = getStatus(device);
|
|
|
|
return (
|
|
|
|
<Wrapper
|
|
|
|
isSelected={isSelected}
|
|
|
|
isOpen={isOpen}
|
|
|
|
isHoverable={isHoverable}
|
|
|
|
disabled={disabled}
|
2018-12-18 09:58:12 +00:00
|
|
|
className={className}
|
2018-09-21 13:04:24 +00:00
|
|
|
>
|
2018-09-25 12:36:07 +00:00
|
|
|
<ClickWrapper
|
|
|
|
disabled={disabled}
|
|
|
|
onClick={onClickWrapper}
|
|
|
|
>
|
2018-09-21 13:04:24 +00:00
|
|
|
<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>
|
2018-09-21 13:04:24 +00:00
|
|
|
</LabelWrapper>
|
|
|
|
<IconWrapper>
|
2018-10-04 20:59:39 +00:00
|
|
|
{icon && !disabled && isAccessible && icon}
|
2018-09-21 13:04:24 +00:00
|
|
|
</IconWrapper>
|
|
|
|
</ClickWrapper>
|
|
|
|
</Wrapper>
|
|
|
|
);
|
|
|
|
};
|
2018-08-22 13:45:00 +00:00
|
|
|
|
2018-08-21 15:02:06 +00:00
|
|
|
DeviceHeader.propTypes = {
|
2018-10-04 20:59:39 +00:00
|
|
|
isAccessible: PropTypes.bool,
|
2018-08-27 12:44:57 +00:00
|
|
|
device: PropTypes.object,
|
|
|
|
icon: PropTypes.element,
|
|
|
|
isHoverable: PropTypes.bool,
|
2018-08-21 15:02:06 +00:00
|
|
|
disabled: PropTypes.bool,
|
|
|
|
isOpen: PropTypes.bool,
|
2018-09-21 13:04:24 +00:00
|
|
|
isSelected: PropTypes.bool,
|
2018-08-25 13:48:55 +00:00
|
|
|
onClickWrapper: PropTypes.func.isRequired,
|
2018-12-18 09:58:12 +00:00
|
|
|
className: PropTypes.string,
|
2018-08-21 15:02:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default DeviceHeader;
|