1
0
mirror of https://github.com/trezor/trezor-wallet synced 2025-01-27 08:21:27 +00:00
trezor-wallet/src/components/Button/index.js

167 lines
3.9 KiB
JavaScript
Raw Normal View History

2018-10-10 08:06:32 +00:00
/* @flow */
import * as React from 'react';
2018-08-16 12:04:40 +00:00
import styled, { css } from 'styled-components';
import PropTypes from 'prop-types';
import colors from 'config/colors';
2018-09-26 10:36:36 +00:00
import { TRANSITION, FONT_WEIGHT, FONT_SIZE } from 'config/variables';
2018-08-16 12:04:40 +00:00
2018-10-10 08:06:32 +00:00
type Props = {
children: React.Node,
className?: string,
2018-10-10 08:20:31 +00:00
onClick?: () => any,
2018-10-10 08:06:32 +00:00
onMouseEnter?: () => void,
onMouseLeave?: () => void,
onFocus?: () => void,
isDisabled?: boolean,
isWhite?: boolean,
isWebUsb?: boolean,
isTransparent?: boolean,
}
2018-08-16 12:04:40 +00:00
const Wrapper = styled.button`
padding: ${props => (props.icon ? '4px 24px 4px 15px' : '11px 24px')};
2018-08-16 12:04:40 +00:00
border-radius: 3px;
2018-09-26 10:36:36 +00:00
font-size: ${FONT_SIZE.SMALL};
font-weight: ${FONT_WEIGHT.SMALLEST};
2018-08-16 12:04:40 +00:00
cursor: pointer;
background: ${colors.GREEN_PRIMARY};
color: ${colors.WHITE};
border: 0;
2018-08-23 12:01:30 +00:00
2018-08-16 12:04:40 +00:00
&:hover {
background: ${colors.GREEN_SECONDARY};
}
2018-08-23 12:01:30 +00:00
2018-08-16 12:04:40 +00:00
&:active {
background: ${colors.GREEN_TERTIARY};
}
2018-08-23 12:01:30 +00:00
${props => props.isDisabled && css`
2018-08-16 12:04:40 +00:00
pointer-events: none;
color: ${colors.TEXT_SECONDARY};
background: ${colors.GRAY_LIGHT};
`}
2018-08-24 07:10:13 +00:00
2018-08-30 11:07:34 +00:00
${props => props.isWhite && css`
2018-08-28 14:27:59 +00:00
background: ${colors.WHITE};
2018-08-23 12:01:30 +00:00
color: ${colors.TEXT_SECONDARY};
border: 1px solid ${colors.DIVIDER};
2018-08-23 12:01:30 +00:00
&:hover {
color: ${colors.TEXT_PRIMARY};
background: ${colors.DIVIDER};
}
2018-08-23 12:01:30 +00:00
&:active {
color: ${colors.TEXT_PRIMARY};
background: ${colors.DIVIDER};
}
`}
${props => props.isTransparent && css`
2018-08-23 12:01:30 +00:00
background: transparent;
border: 0px;
color: ${colors.TEXT_SECONDARY};
&:hover,
&:active {
color: ${colors.TEXT_PRIMARY};
background: transparent;
}
`}
2018-08-24 07:10:13 +00:00
${props => props.isWebUsb && css`
position: relative;
padding: 12px 24px 12px 40px;
background: transparent;
color: ${colors.GREEN_PRIMARY};
border: 1px solid ${colors.GREEN_PRIMARY};
transition: ${TRANSITION.HOVER};
&:before,
&:after {
content: '';
position: absolute;
background: ${colors.GREEN_PRIMARY};
top: 0;
bottom: 0;
margin: auto;
transition: ${TRANSITION.HOVER};
}
&:before {
width: 12px;
height: 2px;
left: 18px;
}
&:after {
2018-08-24 07:10:13 +00:00
width: 2px;
height: 12px;
left: 23px;
}
&:hover {
background: ${colors.GREEN_PRIMARY};
color: ${colors.WHITE};
&:before,
&:after {
background: ${colors.WHITE};
}
}
iframe {
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
`}
2018-08-16 12:04:40 +00:00
`;
const Button = ({
children,
2018-10-10 08:06:32 +00:00
className = '',
onClick,
2018-09-04 12:17:51 +00:00
onMouseEnter,
onMouseLeave,
onFocus,
isDisabled = false,
isWhite = false,
isWebUsb = false,
isTransparent = false,
2018-10-10 08:06:32 +00:00
}: Props) => {
2018-09-06 15:04:28 +00:00
const newClassName = isWebUsb ? `${className} trezor-webusb-button` : className;
return (
<Wrapper
className={newClassName}
onClick={onClick}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onFocus={onFocus}
isDisabled={isDisabled}
isWhite={isWhite}
isWebUsb={isWebUsb}
isTransparent={isTransparent}
>
{children}
</Wrapper>
);
};
2018-08-16 12:04:40 +00:00
Button.propTypes = {
children: PropTypes.node.isRequired,
2018-08-24 07:10:13 +00:00
className: PropTypes.string,
2018-08-16 12:04:40 +00:00
onClick: PropTypes.func,
2018-09-04 12:17:51 +00:00
onMouseEnter: PropTypes.func,
onMouseLeave: PropTypes.func,
onFocus: PropTypes.func,
isDisabled: PropTypes.bool,
2018-08-24 07:10:13 +00:00
isWhite: PropTypes.bool,
isWebUsb: PropTypes.bool,
isTransparent: PropTypes.bool,
2018-08-16 12:04:40 +00:00
};
export default Button;