1
0
mirror of https://github.com/trezor/trezor-wallet synced 2025-01-28 17:01:02 +00:00
trezor-wallet/src/components/buttons/Button/index.js

156 lines
3.7 KiB
JavaScript
Raw Normal View History

import React from 'react';
2018-08-16 12:04:40 +00:00
import styled, { css } from 'styled-components';
import PropTypes from 'prop-types';
import Icon from 'components/Icon';
2018-08-16 12:04:40 +00:00
import colors from 'config/colors';
2018-08-24 07:10:13 +00:00
import { TRANSITION } from 'config/variables';
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;
font-size: 14px;
font-weight: 300;
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
2018-08-16 12:04:40 +00:00
${props => props.disabled && css`
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 {
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 IconWrapper = styled.span`
2018-08-31 10:38:35 +00:00
${props => (props.hasChildren ? 'margin: 0 8px 0 -4px;' : '')};
`;
2018-08-16 12:04:40 +00:00
const Button = ({
2018-08-30 12:30:29 +00:00
children, className, icon, onClick = () => { }, disabled, isWhite = false, isWebUsb = false, isTransparent = false,
2018-08-16 12:04:40 +00:00
}) => (
<Wrapper
2018-08-24 07:10:13 +00:00
className={className}
icon={icon}
2018-08-16 12:04:40 +00:00
onClick={onClick}
disabled={disabled}
2018-08-24 07:10:13 +00:00
isWhite={isWhite}
isWebUsb={isWebUsb}
isTransparent={isTransparent}
>
{icon && (
<IconWrapper
2018-08-30 12:35:35 +00:00
hasChildren={!!children}
>
<Icon
icon={icon.type}
color={icon.color}
size={icon.size}
/>
</IconWrapper>
)}
{children}
2018-08-16 12:04:40 +00:00
</Wrapper>
);
Button.propTypes = {
children: PropTypes.element.isRequired,
2018-08-24 07:10:13 +00:00
className: PropTypes.string,
2018-08-16 12:04:40 +00:00
onClick: PropTypes.func,
disabled: PropTypes.bool,
2018-08-24 07:10:13 +00:00
isWhite: PropTypes.bool,
isWebUsb: PropTypes.bool,
isTransparent: PropTypes.bool,
icon: PropTypes.shape({
type: PropTypes.arrayOf(PropTypes.string).isRequired,
color: PropTypes.string,
size: PropTypes.number,
}),
2018-08-16 12:04:40 +00:00
};
export default Button;