1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-12-29 10:28:08 +00:00

Merge branch 'styled-components-refactor' of https://github.com/satoshilabs/trezor-wallet into styled-components-refactor

This commit is contained in:
Vasek Mlejnsky 2018-08-27 13:00:31 +02:00
commit b7c3a98176
3 changed files with 38 additions and 24 deletions

View File

@ -38,13 +38,16 @@ const RowAccountWrapper = styled.div`
font-size: ${FONT_SIZE.SMALL}; font-size: ${FONT_SIZE.SMALL};
color: ${colors.TEXT_PRIMARY}; color: ${colors.TEXT_PRIMARY};
border-left: ${BORDER_WIDTH.SELECTED} solid transparent; border-left: ${BORDER_WIDTH.SELECTED} solid transparent;
${props => props.borderTop && css`
border-top: 1px solid ${colors.DIVIDER};
`}
border-bottom: 1px solid ${colors.DIVIDER}; border-bottom: 1px solid ${colors.DIVIDER};
&:hover { &:hover {
background-color: ${colors.GRAY_LIGHT}; background-color: ${colors.GRAY_LIGHT};
} }
${props => props.borderTop && css`
border-top: 1px solid ${colors.DIVIDER};
`}
${props => props.isSelected && css` ${props => props.isSelected && css`
border-left: ${BORDER_WIDTH.SELECTED} solid ${colors.GREEN_PRIMARY}; border-left: ${BORDER_WIDTH.SELECTED} solid ${colors.GREEN_PRIMARY};
background: ${colors.WHITE}; background: ${colors.WHITE};

View File

@ -3,9 +3,14 @@ import styled, { css } from 'styled-components';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Icon from 'components/Icon'; import Icon from 'components/Icon';
import icons from 'config/icons'; import icons from 'config/icons';
import { getStatusColor, getStatusName } from 'utils/device'; import {
getStatusColor,
getStatusName,
isDisabled,
getStatus,
getVersion,
} from 'utils/device';
import TrezorImage from 'components/TrezorImage'; import TrezorImage from 'components/TrezorImage';
import colors from 'config/colors'; import colors from 'config/colors';
const Wrapper = styled.div` const Wrapper = styled.div`
@ -21,6 +26,12 @@ const Wrapper = styled.div`
${props => props.isOpen && css` ${props => props.isOpen && css`
box-shadow: none; box-shadow: none;
`} `}
${props => props.isHoverable && css`
&:hover {
background: ${colors.GRAY_LIGHT};
}
`}
`; `;
const ClickWrapper = styled.div` const ClickWrapper = styled.div`
@ -101,6 +112,10 @@ class DeviceHeader extends Component {
}; };
} }
isDisabled(device, devices, transport) {
return isDisabled(device, devices, transport);
}
handleClickWrapper() { handleClickWrapper() {
this.setState({ clicked: true }); this.setState({ clicked: true });
if (!this.props.disabled) { if (!this.props.disabled) {
@ -110,17 +125,21 @@ class DeviceHeader extends Component {
render() { render() {
const { const {
status, label, deviceCount, isOpen, trezorModel, disabled, icon, isOpen, icon, device, devices, transport, isHoverable,
} = this.props; } = this.props;
const status = getStatus(device);
const disabled = isDisabled(device, devices, transport);
const deviceCount = devices.length;
return ( return (
<Wrapper isOpen={isOpen}> <Wrapper isOpen={isOpen} isHoverable={isHoverable}>
<ClickWrapper disabled={disabled} onClick={() => this.handleClickWrapper()}> <ClickWrapper disabled={disabled} onClick={() => this.handleClickWrapper()}>
<ImageWrapper> <ImageWrapper>
<Dot color={getStatusColor(status)} /> <Dot color={getStatusColor(status)} />
<TrezorImage model={trezorModel} /> <TrezorImage model={getVersion(device)} />
</ImageWrapper> </ImageWrapper>
<LabelWrapper> <LabelWrapper>
<Name>{label}</Name> <Name>{device.instanceLabel}</Name>
<Status>{getStatusName(status)}</Status> <Status>{getStatusName(status)}</Status>
</LabelWrapper> </LabelWrapper>
<IconWrapper> <IconWrapper>

View File

@ -6,7 +6,6 @@ import colors from 'config/colors';
import Icon from 'components/Icon'; import Icon from 'components/Icon';
import TrezorConnect from 'trezor-connect'; import TrezorConnect from 'trezor-connect';
import type { TrezorDevice } from 'flowtype'; import type { TrezorDevice } from 'flowtype';
import { getStatus, getVersion, isDisabled } from 'utils/device';
import DeviceHeader from './components/DeviceHeader'; import DeviceHeader from './components/DeviceHeader';
@ -19,11 +18,6 @@ const Wrapper = styled.div``;
const IconClick = styled.div``; const IconClick = styled.div``;
export const DeviceSelect = (props: Props) => { export const DeviceSelect = (props: Props) => {
const { devices } = props;
const { transport } = props.connect;
const { selectedDevice } = props.wallet;
const disabled = isDisabled(selectedDevice, devices, transport);
const handleOpen = () => { const handleOpen = () => {
props.toggleDeviceDropdown(!props.deviceDropdownOpened); props.toggleDeviceDropdown(!props.deviceDropdownOpened);
}; };
@ -31,12 +25,10 @@ export const DeviceSelect = (props: Props) => {
return ( return (
<DeviceHeader <DeviceHeader
onClickWrapper={handleOpen} onClickWrapper={handleOpen}
disabled={disabled} device={props.wallet.selectedDevice}
label={selectedDevice.instanceLabel} transport={props.connect.transport}
status={getStatus(selectedDevice)} devices={props.devices.length}
deviceCount={devices.length}
isOpen={props.deviceDropdownOpened} isOpen={props.deviceDropdownOpened}
trezorModel={getVersion(selectedDevice)}
/> />
); );
}; };
@ -152,7 +144,7 @@ export class DeviceDropdown extends Component<Props> {
}; };
const deviceList = devices.sort(sortByInstance) const deviceList = devices.sort(sortByInstance)
.map((dev, index) => { .map((dev) => {
if (dev === selected) return null; if (dev === selected) return null;
return ( return (
<DeviceHeader <DeviceHeader
@ -173,9 +165,9 @@ export class DeviceDropdown extends Component<Props> {
/> />
</IconClick> </IconClick>
)} )}
label={dev.instanceLabel} device={dev}
status={getStatus(dev)} devices={devices}
trezorModel={getVersion(dev)} isHoverable
/> />
); );
}); });