Skip to content

Commit 1cc2a33

Browse files
author
Valentin Hervieu
committed
Introduce ProgressButton to have more possibilities for the loader
1 parent 5e5920f commit 1cc2a33

File tree

5 files changed

+73
-9
lines changed

5 files changed

+73
-9
lines changed

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

Lines changed: 3 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,21 +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}
8585
loading={isForking}
8686
small
8787
>
8888
<>
8989
<Fork style={{ marginRight: '.5rem' }} />
9090
{isForking ? 'Forking...' : 'Fork'}
9191
</>
92-
</Button>
92+
</ProgressButton>
9393
);
9494

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

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

Lines changed: 3 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,15 +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}
4241
loading={isForkingSandbox}
4342
onClick={this.forkSandbox}
4443
>
4544
{isForkingSandbox ? 'Forking Sandbox...' : 'Fork Sandbox'}
46-
</Button>
45+
</ProgressButton>
4746
) : (
4847
<SignInButton block />
4948
)}

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

Lines changed: 1 addition & 2 deletions
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;
@@ -11,7 +11,6 @@ type Props = {
1111
children?: React.ReactElement | string;
1212
disabled?: boolean;
1313
type?: 'button' | 'reset' | 'submit';
14-
loading?: boolean;
1514
secondary?: boolean;
1615
};
1716

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: 10px;
15+
height: 10px;
16+
border-radius: 50%;
17+
background: ${theme.secondary()};
18+
opacity: 0.5;
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: -15px;
33+
${circle};
34+
animation-delay: 0s;
35+
}
36+
37+
&:after {
38+
content: ' ';
39+
position: absolute;
40+
left: 15px;
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)