1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-30 20:28:09 +00:00

Merge pull request #307 from trezor/fix/notification-loading-button

Added loading state for acquire button
This commit is contained in:
Vladimir Volek 2019-01-09 16:10:35 +01:00 committed by GitHub
commit c371159e00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 30 deletions

View File

@ -25,13 +25,14 @@ const SvgWrapper = styled.svg`
const CircleWrapper = styled.circle` const CircleWrapper = styled.circle`
${props => props.isRoute && css` ${props => props.isRoute && css`
stroke: ${colors.GRAY_LIGHT}; stroke: ${props.transparentRoute ? 'transparent' : colors.GRAY_LIGHT};
`} `}
${props => props.isPath && css` ${props => props.isPath && css`
stroke-width: ${props.transparentRoute ? '2px' : '1px'};
stroke-dasharray: 1, 200; stroke-dasharray: 1, 200;
stroke-dashoffset: 0; stroke-dashoffset: 0;
animation: ${DASH} 1.5s ease-in-out infinite, ${GREEN_COLOR} 6s ease-in-out infinite; animation: ${DASH} 1.5s ease-in-out infinite, ${props.animationColor || GREEN_COLOR} 6s ease-in-out infinite;
stroke-linecap: round; stroke-linecap: round;
`}; `};
`; `;
@ -42,29 +43,31 @@ const StyledParagraph = styled(Paragraph)`
`; `;
const Loader = ({ const Loader = ({
className, text, isWhiteText = false, isSmallText, size = 100, className, text, isWhiteText = false, isSmallText, size = 100, animationColor, transparentRoute,
}) => ( }) => (
<Wrapper className={className} size={size}> <Wrapper className={className} size={size}>
<StyledParagraph isSmallText={isSmallText} isWhiteText={isWhiteText}>{text}</StyledParagraph> <StyledParagraph isSmallText={isSmallText} isWhiteText={isWhiteText}>{text}</StyledParagraph>
<SvgWrapper viewBox="25 25 50 50"> <SvgWrapper viewBox="25 25 50 50">
<CircleWrapper <CircleWrapper
animationColor={animationColor}
cx="50" cx="50"
cy="50" cy="50"
r="20" r="20"
fill="none" fill="none"
stroke="" stroke=""
strokeWidth="1"
strokeMiterlimit="10" strokeMiterlimit="10"
isRoute isRoute
transparentRoute={transparentRoute}
/> />
<CircleWrapper <CircleWrapper
animationColor={animationColor}
cx="50" cx="50"
cy="50" cy="50"
r="20" r="20"
fill="none" fill="none"
strokeWidth="1"
strokeMiterlimit="10" strokeMiterlimit="10"
isPath isPath
transparentRoute={transparentRoute}
/> />
</SvgWrapper> </SvgWrapper>
</Wrapper> </Wrapper>
@ -75,6 +78,8 @@ Loader.propTypes = {
isSmallText: PropTypes.bool, isSmallText: PropTypes.bool,
className: PropTypes.string, className: PropTypes.string,
text: PropTypes.string, text: PropTypes.string,
animationColor: PropTypes.string,
transparentRoute: PropTypes.bool,
size: PropTypes.number, size: PropTypes.number,
}; };

View File

@ -5,7 +5,8 @@ import styled from 'styled-components';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Icon from 'components/Icon'; import Icon from 'components/Icon';
import colors from 'config/colors'; import colors from 'config/colors';
import { getPrimaryColor, getSecondaryColor } from 'utils/notification'; import { WHITE_COLOR } from 'config/animations';
import { getPrimaryColor } from 'utils/notification';
import Loader from 'components/Loader'; import Loader from 'components/Loader';
import { TRANSITION, FONT_SIZE, FONT_WEIGHT } from 'config/variables'; import { TRANSITION, FONT_SIZE, FONT_WEIGHT } from 'config/variables';
@ -31,7 +32,8 @@ const LoaderContent = styled.div`
justify-content: center; justify-content: center;
align-items: center; align-items: center;
cursor: default; cursor: default;
background: ${props => getSecondaryColor(props.type)}; color: ${colors.WHITE};
background: ${props => getPrimaryColor(props.type)};
`; `;
const Wrapper = styled.button` const Wrapper = styled.button`
@ -66,7 +68,7 @@ const NotificationButton = ({
> >
{isLoading && ( {isLoading && (
<LoaderContent type={type}> <LoaderContent type={type}>
<Loader size={30} /> <Loader transparentRoute animationColor={WHITE_COLOR} size={30} />
</LoaderContent> </LoaderContent>
)} )}
{icon && ( {icon && (

View File

@ -19,6 +19,7 @@ type Props = {
className?: string; className?: string;
message?: ?string; message?: ?string;
actions?: Array<CallbackAction>; actions?: Array<CallbackAction>;
isActionInProgress?: boolean;
close?: typeof NotificationActions.close, close?: typeof NotificationActions.close,
loading?: boolean loading?: boolean
}; };
@ -122,6 +123,7 @@ const Notification = (props: Props): React$Element<string> => {
<NotificationButton <NotificationButton
key={action.label} key={action.label}
type={props.type} type={props.type}
isLoading={props.isActionInProgress}
onClick={() => { close(); action.callback(); }} onClick={() => { close(); action.callback(); }}
>{action.label} >{action.label}
</NotificationButton> </NotificationButton>

View File

@ -49,6 +49,12 @@ export const GREEN_COLOR = keyframes`
} }
`; `;
export const WHITE_COLOR = keyframes`
0%, 100% {
stroke: white;
}
`;
export const PULSATE = keyframes` export const PULSATE = keyframes`
0%, 100% { 0%, 100% {
opacity: 0.5; opacity: 0.5;

View File

@ -21,28 +21,27 @@ const Wrapper = styled.div`
flex: 1; flex: 1;
`; `;
const Acquire = (props: Props) => { const Acquire = (props: Props) => (
const actions = props.acquiring ? [] : [ <Wrapper>
{ <Notification
label: 'Acquire device', title="Device is used in other window"
callback: () => { message="Do you want to use your device in this window?"
props.acquireDevice(); type="info"
}, cancelable={false}
}, isActionInProgress={props.acquiring}
]; actions={
[
return ( {
<Wrapper> label: 'Acquire device',
<Notification callback: () => {
title="Device is used in other window" props.acquireDevice();
message="Do you want to use your device in this window?" },
type="info" },
cancelable={false} ]
actions={actions} }
/> />
</Wrapper> </Wrapper>
); );
};
export default connect( export default connect(
(state: State) => ({ (state: State) => ({