feat(Login): add spinner on login

This commit is contained in:
FernTheDev 2020-09-21 22:13:17 -04:00 committed by Jordan Knott
parent 4277b7b2a8
commit 0c7d2e2c9f
4 changed files with 109 additions and 0 deletions

View File

@ -0,0 +1,24 @@
import React from 'react';
import NormalizeStyles from 'App/NormalizeStyles';
import BaseStyles from 'App/BaseStyles';
import LoadingSpinner from '.';
export default {
component: LoadingSpinner,
title: 'Login',
parameters: {
backgrounds: [
{ name: 'white', value: '#ffffff' },
{ name: 'gray', value: '#cdd3e1', default: true },
],
},
};
export const Default = () => {
return (
<>
<NormalizeStyles />
<BaseStyles />
<LoadingSpinner />
</>
);
};

View File

@ -0,0 +1,42 @@
import styled, { keyframes } from 'styled-components';
const LoadingSpinnerKeyframes = keyframes`
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
`;
export const LoadingSpinnerWrapper = styled.div<{ color: string; size: string; borderSize: string; thickness: string }>`
display: inline-block;
position: relative;
width: ${props => props.borderSize};
height: ${props => props.borderSize};
& > div {
box-sizing: border-box;
display: block;
position: absolute;
width: ${props => props.size};
height: ${props => props.size};
margin: ${props => props.thickness};
border: ${props => props.thickness} solid rgba(${props => props.theme.colors[props.color]});
border-radius: 50%;
animation: 1.2s ${LoadingSpinnerKeyframes} cubic-bezier(0.5, 0, 0.5, 1) infinite;
border-color: rgba(${props => props.theme.colors[props.color]}) transparent transparent transparent;
}
& > div:nth-child(1) {
animation-delay: -0.45s;
}
& > div:nth-child(2) {
animation-delay: -0.3s;
}
& > div:nth-child(3) {
animation-delay: -0.15s;
}
`;
export default LoadingSpinnerWrapper;

View File

@ -0,0 +1,41 @@
import React from 'react';
import { LoadingSpinnerWrapper} from './Styles';
type LoadingSpinnerProps = {
color?: 'primary' | 'danger' | 'success' | 'warning' | 'dark';
size?: string;
borderSize?: string;
thickness?: string;
};
/**
* The default parameters may not be applicable to every scenario
*
* While borderSize and size should be a single prop,
* it is currently not as such because it would require math to be done to strings
* e.g "80px - 16"
*
*
* @param color
* @param size The size of the spinner. It is recommended to be at least 16 px less than the borderSize
* @param thickness
* @param borderSize Border size affects the size of the border which if is too small may break the spinner.
* @constructor
*/
const LoadingSpinner: React.FC<LoadingSpinnerProps> = ({
color = 'primary',
size = '64px',
thickness = '8px',
borderSize = '80px',
}) => {
return (
<LoadingSpinnerWrapper color={color} size={size} thickness={thickness} borderSize={borderSize}>
<div />
<div />
<div />
</LoadingSpinnerWrapper>
);
};
export default LoadingSpinner;

View File

@ -3,6 +3,7 @@ import AccessAccount from 'shared/undraw/AccessAccount';
import { User, Lock, Taskcafe } from 'shared/icons';
import { useForm } from 'react-hook-form';
import LoadingSpinner from 'shared/components/LoadingSpinner';
import {
Form,
LogoWrapper,
@ -73,6 +74,7 @@ const Login = ({ onSubmit }: LoginProps) => {
<ActionButtons>
<RegisterButton variant="outline">Register</RegisterButton>
{!isComplete && <LoadingSpinner size="32px" thickness="2px" borderSize="48px" />}
<LoginButton type="submit" disabled={!isComplete}>
Login
</LoginButton>