Skip to content

Commit

Permalink
feat(app-components): button not change width on loading
Browse files Browse the repository at this point in the history
  • Loading branch information
rams23 committed Feb 4, 2021
1 parent ae72740 commit 6e8e633
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import styled from 'styled-components';
import styled, { css } from 'styled-components';
import { variant, color } from 'styled-system';
import Icon from '../Icon';
import Spinner from '../Spinner';
import Typography from '../Typography';

export type Variants = 'default' | 'clear';

Expand Down Expand Up @@ -69,3 +71,19 @@ export const NotHoverIconWrapper = styled(IconWrapper)`
`;

NotHoverIconWrapper.displayName = 'NotHoverIconWrapper';

export const ButtonSpinner = styled(Spinner)`
position: absolute;
`;

ButtonSpinner.displayName = 'ButtonSpinner';

export const ButtonLabel = styled(Typography)<{ loading?: boolean }>`
${props =>
props.loading &&
css`
visibility: hidden;
`}
`;

ButtonLabel.displayName = 'ButtonLabel';
13 changes: 10 additions & 3 deletions packages/game-app/src/_shared/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React from 'react';
import { ButtonContent, NotHoverIconWrapper, StyledButton, Variants } from './Button.styled';
import Spinner from '../Spinner';
import {
ButtonContent,
ButtonLabel,
ButtonSpinner,
NotHoverIconWrapper,
StyledButton,
Variants,
} from './Button.styled';

type Props = {
id?: string;
Expand Down Expand Up @@ -37,7 +43,8 @@ const Button: React.FC<Props> = ({
>
<ButtonContent>
{leftIcon ? <NotHoverIconWrapper>{leftIcon}</NotHoverIconWrapper> : null}
{loading ? <Spinner /> : label}
{loading && <ButtonSpinner />}
<ButtonLabel loading={loading}>{label}</ButtonLabel>
</ButtonContent>
</StyledButton>
);
Expand Down
8 changes: 5 additions & 3 deletions packages/game-app/src/_shared/components/Spinner/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from 'react';
import { StyledSpinner } from './Spinner.styled';

type Props = {};
type Props = {
className?: string;
};

const Spinner: React.FC<Props> = ({}) => {
const Spinner: React.FC<Props> = ({ className }) => {
return (
<StyledSpinner>
<StyledSpinner className={className}>
<div className="thumb"></div>
<div className="placeholder"></div>
</StyledSpinner>
Expand Down

0 comments on commit 6e8e633

Please sign in to comment.