Skip to content

Commit

Permalink
Show a loader on the button while forking (#1733)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ValentinH authored and CompuIves committed Apr 16, 2019
1 parent 37c548b commit 33f19af
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 8 deletions.
7 changes: 4 additions & 3 deletions packages/app/src/app/pages/Sandbox/Editor/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SettingsIcon from 'react-icons/lib/md/settings';
import ShareIcon from 'react-icons/lib/md/share';
import SaveIcon from 'react-icons/lib/md/save';
import { Button } from '@codesandbox/common/lib/components/Button';
import ProgressButton from '@codesandbox/common/lib/components/ProgressButton';
import SignInButton from 'app/pages/common/SignInButton';

import { saveAllModules } from 'app/store/modules/editor/utils';
Expand Down Expand Up @@ -75,20 +76,20 @@ const ForkButton = ({
isForking,
style,
}: ForkButtonProps) => (
<Button
<ProgressButton
onClick={() => {
signals.editor.forkSandboxClicked();
}}
style={style}
secondary={secondary}
disabled={isForking}
loading={isForking}
small
>
<>
<Fork style={{ marginRight: '.5rem' }} />
{isForking ? 'Forking...' : 'Fork'}
</>
</Button>
</ProgressButton>
);

const PickButton = ({ store, signals, secondary, style }: ButtonProps) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { inject, observer } from 'mobx-react';

import { Button } from '@codesandbox/common/lib/components/Button';
import ProgressButton from '@codesandbox/common/lib/components/ProgressButton';
import SignInButton from 'app/pages/common/SignInButton';
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
import track from '@codesandbox/common/lib/utils/analytics';
Expand Down Expand Up @@ -35,14 +35,14 @@ class More extends React.Component<Props> {
<Description>{message}</Description>
<Margin margin={1}>
{!owned ? (
<Button
<ProgressButton
small
block
disabled={isForkingSandbox}
loading={isForkingSandbox}
onClick={this.forkSandbox}
>
{isForkingSandbox ? 'Forking Sandbox...' : 'Fork Sandbox'}
</Button>
</ProgressButton>
) : (
<SignInButton block />
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/components/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { LinkButton, AButton, Button } from './elements';

type Props = {
export type Props = {
to?: string;
href?: string;
small?: boolean;
Expand Down
44 changes: 44 additions & 0 deletions packages/common/src/components/ProgressButton/elements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import styled, { css, keyframes } from 'styled-components';
import theme from '../../theme';

const loaderAnimation = keyframes`
0% { background-color: ${theme.secondary()}; }
50%, 100% { background-color: ${theme.secondary.lighten(0.5)()}; }
`;

export const Wrapper = styled.div`
position: relative;
`;

const circle = css`
width: 8px;
height: 8px;
border-radius: 50%;
background: ${theme.secondary()};
opacity: 0.7;
animation: ${loaderAnimation} 1s infinite linear alternate;
`;

export const Loader = styled.div`
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
${circle} animation-delay: 0.5s;
&:before {
content: ' ';
position: absolute;
left: -12px;
${circle};
animation-delay: 0s;
}
&:after {
content: ' ';
position: absolute;
left: 12px;
${circle};
animation-delay: 1s;
}
`;
22 changes: 22 additions & 0 deletions packages/common/src/components/ProgressButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { Button, Props as ButtonProps } from '../Button';
import { Wrapper, Loader } from './elements';

type Props = ButtonProps & {
loading?: boolean;
};

function ProgressButton({
loading = false,
disabled = false,
...props
}: Props) {
return (
<Wrapper>
<Button disabled={disabled || loading} {...props} />
{loading && <Loader />}
</Wrapper>
);
}

export default ProgressButton;

0 comments on commit 33f19af

Please sign in to comment.