1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-24 09:18:09 +00:00

Refactored notification buttons

This commit is contained in:
Vladimir Volek 2018-08-28 16:27:59 +02:00
parent 73f62d82f9
commit a4720fc2e3
3 changed files with 63 additions and 67 deletions

View File

@ -29,7 +29,7 @@ const Wrapper = styled.button`
background: ${colors.GRAY_LIGHT}; background: ${colors.GRAY_LIGHT};
`} `}
${props => props.isBlue && css` ${props => props.color === 'blue' && css`
background: transparent; background: transparent;
border: 1px solid ${colors.INFO_PRIMARY}; border: 1px solid ${colors.INFO_PRIMARY};
color: ${colors.INFO_PRIMARY}; color: ${colors.INFO_PRIMARY};
@ -41,8 +41,8 @@ const Wrapper = styled.button`
} }
`} `}
${props => props.isWhite && css` ${props => props.color === 'white' && css`
background: @color_white; background: ${colors.WHITE};
color: ${colors.TEXT_SECONDARY}; color: ${colors.TEXT_SECONDARY};
border: 1px solid ${colors.DIVIDER}; border: 1px solid ${colors.DIVIDER};
@ -125,14 +125,14 @@ const IconWrapper = styled.span`
`; `;
const Button = ({ const Button = ({
className, text, icon, onClick = () => { }, disabled, isBlue = false, isWhite = false, isWebUsb = false, isTransparent = false, className, text, icon, onClick = () => { }, disabled, color = null, isWhite = false, isWebUsb = false, isTransparent = false,
}) => ( }) => (
<Wrapper <Wrapper
className={className} className={className}
icon={icon} icon={icon}
onClick={onClick} onClick={onClick}
disabled={disabled} disabled={disabled}
isBlue={isBlue} color={color}
isWhite={isWhite} isWhite={isWhite}
isWebUsb={isWebUsb} isWebUsb={isWebUsb}
isTransparent={isTransparent} isTransparent={isTransparent}
@ -154,7 +154,7 @@ Button.propTypes = {
className: PropTypes.string, className: PropTypes.string,
onClick: PropTypes.func, onClick: PropTypes.func,
disabled: PropTypes.bool, disabled: PropTypes.bool,
isBlue: PropTypes.bool, color: PropTypes.string,
isWhite: PropTypes.bool, isWhite: PropTypes.bool,
isWebUsb: PropTypes.bool, isWebUsb: PropTypes.bool,
isTransparent: PropTypes.bool, isTransparent: PropTypes.bool,

View File

@ -5,8 +5,11 @@ import React from 'react';
import { H2 } from 'components/Heading'; import { H2 } from 'components/Heading';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import styled from 'styled-components'; import styled, { css } from 'styled-components';
import colors from 'config/colors'; import colors from 'config/colors';
import Button from 'components/Button';
import Icon from 'components/Icon';
import icons from 'config/icons';
import * as NOTIFICATION from 'actions/constants/notification'; import * as NOTIFICATION from 'actions/constants/notification';
import * as NotificationActions from 'actions/NotificationActions'; import * as NotificationActions from 'actions/NotificationActions';
@ -31,45 +34,77 @@ type NProps = {
const Wrapper = styled.div` const Wrapper = styled.div`
position: relative; position: relative;
color: ${colors.INFO_PRIMARY}; color: ${colors.TEXT_PRIMARY};
background: ${colors.INFO_SECONDARY}; background: ${colors.TEXT_SECONDARY};
padding: 24px 48px 24px 80px; padding: 24px 48px 24px 80px;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
flex-wrap: wrap; flex-wrap: wrap;
justify-content: space-between; justify-content: space-between;
text-align: left; text-align: left;
${props => props.type === 'info' && css`
color: ${colors.INFO_PRIMARY};
background: ${colors.INFO_SECONDARY};
`}
${props => props.type === 'success' && css`
color: ${colors.SUCCESS_PRIMARY};
background: ${colors.SUCCESS_SECONDARY};
`}
${props => props.type === 'warning' && css`
color: ${colors.WARNING_PRIMARY};
background: ${colors.WARNING_SECONDARY};
`}
${props => props.type === 'error' && css`
color: ${colors.ERROR_PRIMARY};
background: ${colors.ERROR_SECONDARY};
`}
`; `;
const Body = styled.div`
flex: 1;
margin-right: 24px;
`;
const ActionContent = styled.div`
`;
const CloseClick = styled.div``;
export const Notification = (props: NProps): React$Element<string> => { export const Notification = (props: NProps): React$Element<string> => {
const className = `notification ${props.className}`;
const close: Function = typeof props.close === 'function' ? props.close : () => {}; // TODO: add default close action const close: Function = typeof props.close === 'function' ? props.close : () => {}; // TODO: add default close action
const actionButtons = props.actions ? props.actions.map((a, i) => ( const actionButtons = props.actions ? props.actions.map((a, i) => (
<button key={i} onClick={(event) => { close(); a.callback(); }} className="transparent">{ a.label }</button> <button key={i} onClick={(event) => { close(); a.callback(); }} className="transparent">{ a.label }</button>
)) : null; )) : null;
return ( return (
<Wrapper className={className}> <Wrapper type={props.className}>
{ props.cancelable ? ( { props.cancelable && (
<button <CloseClick onClick={() => close()}>
className="notification-close transparent" <Icon icon={icons.CLOSE} size={25} />
onClick={event => close()} </CloseClick>
/> )
) : null } }
<div className="notification-body"> <Body>
<H2>{ props.title }</H2> <H2>{ props.title }</H2>
{ props.message ? (<p dangerouslySetInnerHTML={{ __html: props.message }} />) : null } { props.message && <p dangerouslySetInnerHTML={{ __html: props.message }} /> }
</div> </Body>
{ props.actions && props.actions.length > 0 ? ( { props.actions && props.actions.length > 0 ? (
<div className="notification-action"> <ActionContent>
{ actionButtons } {props.actions
</div> .map(action => (
) : null } <Button
{ props.loading ? ( color={props.className}
<Loader text={action.label}
size={50} onClick={() => { close(); action.callback(); }}
/> />
))}
</ActionContent>
) : null } ) : null }
{ props.loading && <Loader size={50} /> }
</Wrapper> </Wrapper>
); );

View File

@ -1,10 +1,5 @@
.notification { .notification {
.notification-body {
flex: 1;
margin-right: 24px;
}
.notification-action button { .notification-action button {
padding: 12px 58px; padding: 12px 58px;
} }
@ -28,26 +23,6 @@
} }
} }
h2 {
font-size: 14px;
font-weight: bold;
padding: 0px;
&:before {
.icomoon-info;
position: absolute;
top: 17px;
left: 40px;
font-size: 32px !important;
}
}
p {
padding: 0px;
margin: 8px 0px;
color: inherit;
}
&.info { &.info {
.notification-action button { .notification-action button {
border: 1px solid @color_info_primary; border: 1px solid @color_info_primary;
@ -59,11 +34,7 @@
} }
} }
&.success { &.success {
color: @color_success_primary;
background: @color_success_secondary;
.notification-action button { .notification-action button {
border: 1px solid @color_success_primary; border: 1px solid @color_success_primary;
@ -76,11 +47,6 @@
} }
&.warning { &.warning {
color: @color_warning_primary;
background: @color_warning_secondary;
h2:before {
.icomoon-warning;
}
.notification-action button { .notification-action button {
border: 1px solid @color_warning_primary; border: 1px solid @color_warning_primary;
@ -93,11 +59,6 @@
} }
&.error { &.error {
color: @color_error_primary;
background: @color_error_secondary;
h2:before {
.icomoon-error;
}
.notification-close { .notification-close {
color: @color_error_primary; color: @color_error_primary;