Skip to content

Commit 5e5920f

Browse files
author
Valentin Hervieu
committed
Show a loader on the button while forking
This is a follow-up of #1667. The effect is simple because for now I didn't want to modify the markup of the button. As far as my limited CSS skills lead me, @CompuIves suggestion regarding nzbin.github.io/three-dots would require to have a div wrapper around the button and a div to display the 3 dots. Do we want to do this?
1 parent d688a85 commit 5e5920f

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

packages/app/src/app/pages/Sandbox/Editor/Header/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ const ForkButton = ({
8282
style={style}
8383
secondary={secondary}
8484
disabled={isForking}
85+
loading={isForking}
8586
small
8687
>
8788
<>

packages/app/src/app/pages/Sandbox/Editor/Workspace/items/More/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class More extends React.Component<Props> {
3939
small
4040
block
4141
disabled={isForkingSandbox}
42+
loading={isForkingSandbox}
4243
onClick={this.forkSandbox}
4344
>
4445
{isForkingSandbox ? 'Forking Sandbox...' : 'Fork Sandbox'}

packages/common/src/components/Button/elements.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import styled, { css } from 'styled-components';
1+
import styled, { css, keyframes } from 'styled-components';
22
import Link from 'react-router-dom/Link';
33
import theme from '../../theme';
44

55
export type OptionProps = {
66
theme: any;
77
disabled?: boolean;
8+
loading?: boolean;
89
red?: boolean;
910
secondary?: boolean;
1011
danger?: boolean;
@@ -97,14 +98,39 @@ const getBorder = ({
9798
return '2px solid #66B9F4';
9899
};
99100

101+
const progressAnimation = keyframes`
102+
0% { transform: scale(0); }
103+
100% { transform: scale(1); }
104+
`;
105+
106+
const getLoader = ({ disabled }: OptionProps) => css`
107+
&:before {
108+
content: ' ';
109+
position: absolute;
110+
width: 20px;
111+
height: 20px;
112+
left: 50%;
113+
top: 50%;
114+
bottom: 0;
115+
margin-left: -10px;
116+
margin-top: -10px;
117+
border-radius: 50%;
118+
opacity: 0.5;
119+
background: white;
120+
animation: ${progressAnimation} 0.7s ease-in-out infinite alternate;
121+
}
122+
`;
123+
100124
const styles = css<{
101125
disabled?: boolean;
126+
loading?: boolean;
102127
secondary?: boolean;
103128
danger?: boolean;
104129
red?: boolean;
105130
block?: boolean;
106131
small?: boolean;
107132
}>`
133+
position: relative;
108134
transition: 0.3s ease all;
109135
font-family: Poppins, Roboto, sans-serif;
110136
@@ -150,6 +176,8 @@ const styles = css<{
150176
${props => getBackgroundHoverColor(props)};
151177
${props => getHoverColor(props)};
152178
}
179+
180+
${props => props.loading && getLoader(props)};
153181
`;
154182

155183
export const LinkButton = styled(Link)`

packages/common/src/components/Button/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Props = {
1111
children?: React.ReactElement | string;
1212
disabled?: boolean;
1313
type?: 'button' | 'reset' | 'submit';
14+
loading?: boolean;
1415
secondary?: boolean;
1516
};
1617

0 commit comments

Comments
 (0)