Skip to content

Commit

Permalink
feat(button-loading): adjust spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
matheushdsbr committed Nov 22, 2023
1 parent 8a74705 commit 55911ce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

```javascript
<Box display="flex" justifyContent="space-evenly" width="100%">
<Button.Loading isLoading loadingLabel="Spinner here">Find an activity</Button.Loading>
<Button.Loading isLoading>Find an activity</Button.Loading>
<Button.Loading>Find an activity</Button.Loading>
</Box>
```
Expand Down
38 changes: 33 additions & 5 deletions packages/yoga/src/Button/web/Loading.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import React from 'react';
import { bool, string, node } from 'prop-types';
import styled from 'styled-components';
import Button from './Button';
import ButtonOutline from './Outline';
import ButtonIcon from './Icon';
import Spinner from '../../Spinner';

const ButtonLoading = ({
isLoading,
loadingLabel,
children,
disabled,
variant,
...props
}) => {
const commonProps = {
isLoading,
disabled: isLoading,
disabled: isLoading || disabled,
...props,
};

Expand All @@ -26,25 +26,53 @@ const ButtonLoading = ({

const ButtonComponent = variantToComponent[variant] || Button;

const LoadingContainer = styled.div`
position: relative;
& > span {
color: transparent;
}
`;

const SpinnerContainer = styled.div`
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
`;

const renderLoading = () => {
return (
<LoadingContainer>
<span>{children}</span>
<SpinnerContainer>
<Spinner size="small" />
</SpinnerContainer>
</LoadingContainer>
);
};

const renderLoadingLabel = () => {
return <span>{children}</span>;
};

return (
<ButtonComponent {...commonProps}>
{isLoading ? <Spinner size="small" /> : children}
{isLoading ? renderLoading() : renderLoadingLabel()}
</ButtonComponent>
);
};

ButtonLoading.propTypes = {
isLoading: bool,
disabled: bool,
loadingLabel: string,
children: node,
variant: string,
};

ButtonLoading.defaultProps = {
isLoading: false,
disabled: false,
loadingLabel: undefined,
children: 'Button',
variant: 'default',
};
Expand Down

0 comments on commit 55911ce

Please sign in to comment.