Skip to content

Commit 33f19af

Browse files
ValentinHCompuIves
authored andcommitted
Show a loader on the button while forking (#1733)
* 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? * Introduce ProgressButton to have more possibilities for the loader * Make the circles a bit smaller
1 parent 37c548b commit 33f19af

File tree

5 files changed

+75
-8
lines changed

5 files changed

+75
-8
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import SettingsIcon from 'react-icons/lib/md/settings';
88
import ShareIcon from 'react-icons/lib/md/share';
99
import SaveIcon from 'react-icons/lib/md/save';
1010
import { Button } from '@codesandbox/common/lib/components/Button';
11+
import ProgressButton from '@codesandbox/common/lib/components/ProgressButton';
1112
import SignInButton from 'app/pages/common/SignInButton';
1213

1314
import { saveAllModules } from 'app/store/modules/editor/utils';
@@ -75,20 +76,20 @@ const ForkButton = ({
7576
isForking,
7677
style,
7778
}: ForkButtonProps) => (
78-
<Button
79+
<ProgressButton
7980
onClick={() => {
8081
signals.editor.forkSandboxClicked();
8182
}}
8283
style={style}
8384
secondary={secondary}
84-
disabled={isForking}
85+
loading={isForking}
8586
small
8687
>
8788
<>
8889
<Fork style={{ marginRight: '.5rem' }} />
8990
{isForking ? 'Forking...' : 'Fork'}
9091
</>
91-
</Button>
92+
</ProgressButton>
9293
);
9394

9495
const PickButton = ({ store, signals, secondary, style }: ButtonProps) => {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { inject, observer } from 'mobx-react';
33

4-
import { Button } from '@codesandbox/common/lib/components/Button';
4+
import ProgressButton from '@codesandbox/common/lib/components/ProgressButton';
55
import SignInButton from 'app/pages/common/SignInButton';
66
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
77
import track from '@codesandbox/common/lib/utils/analytics';
@@ -35,14 +35,14 @@ class More extends React.Component<Props> {
3535
<Description>{message}</Description>
3636
<Margin margin={1}>
3737
{!owned ? (
38-
<Button
38+
<ProgressButton
3939
small
4040
block
41-
disabled={isForkingSandbox}
41+
loading={isForkingSandbox}
4242
onClick={this.forkSandbox}
4343
>
4444
{isForkingSandbox ? 'Forking Sandbox...' : 'Fork Sandbox'}
45-
</Button>
45+
</ProgressButton>
4646
) : (
4747
<SignInButton block />
4848
)}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { LinkButton, AButton, Button } from './elements';
33

4-
type Props = {
4+
export type Props = {
55
to?: string;
66
href?: string;
77
small?: boolean;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import styled, { css, keyframes } from 'styled-components';
2+
import theme from '../../theme';
3+
4+
const loaderAnimation = keyframes`
5+
0% { background-color: ${theme.secondary()}; }
6+
50%, 100% { background-color: ${theme.secondary.lighten(0.5)()}; }
7+
`;
8+
9+
export const Wrapper = styled.div`
10+
position: relative;
11+
`;
12+
13+
const circle = css`
14+
width: 8px;
15+
height: 8px;
16+
border-radius: 50%;
17+
background: ${theme.secondary()};
18+
opacity: 0.7;
19+
animation: ${loaderAnimation} 1s infinite linear alternate;
20+
`;
21+
22+
export const Loader = styled.div`
23+
position: absolute;
24+
top: 50%;
25+
left: 50%;
26+
transform: translate(-50%, -50%);
27+
${circle} animation-delay: 0.5s;
28+
29+
&:before {
30+
content: ' ';
31+
position: absolute;
32+
left: -12px;
33+
${circle};
34+
animation-delay: 0s;
35+
}
36+
37+
&:after {
38+
content: ' ';
39+
position: absolute;
40+
left: 12px;
41+
${circle};
42+
animation-delay: 1s;
43+
}
44+
`;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import { Button, Props as ButtonProps } from '../Button';
3+
import { Wrapper, Loader } from './elements';
4+
5+
type Props = ButtonProps & {
6+
loading?: boolean;
7+
};
8+
9+
function ProgressButton({
10+
loading = false,
11+
disabled = false,
12+
...props
13+
}: Props) {
14+
return (
15+
<Wrapper>
16+
<Button disabled={disabled || loading} {...props} />
17+
{loading && <Loader />}
18+
</Wrapper>
19+
);
20+
}
21+
22+
export default ProgressButton;

0 commit comments

Comments
 (0)