Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸš€ feat(button): add prop loading #705

Merged
merged 30 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
429b733
feat(button): add loading struture
matheushdsbr Oct 10, 2023
ca340ef
feat(button): add button loading component
matheushdsbr Oct 10, 2023
46b09b1
doc(button): add button loading doc
matheushdsbr Oct 10, 2023
a616010
feat(button): add outline and icon button
matheushdsbr Oct 10, 2023
8a74705
feat(button): add spinner
matheushdsbr Oct 10, 2023
55911ce
feat(button-loading): adjust spinner
matheushdsbr Oct 16, 2023
c725e65
doc(button-loading): update doc
matheushdsbr Oct 17, 2023
967ba9e
refactor(button-loading): remove button-icon variant
matheushdsbr Oct 17, 2023
a144fa9
test(button-loading): add tests
matheushdsbr Oct 17, 2023
4e521f0
test(button-loading): update snapshot
matheushdsbr Oct 18, 2023
270ed60
feat(button-loading): add ref
matheushdsbr Oct 18, 2023
b651eb3
test(button): update snapshot and add tests to isLoading prop
matheushdsbr Oct 19, 2023
52d6556
refactor(button-loading): remove button loading
matheushdsbr Oct 19, 2023
44ac7f8
feat(button): add isLoading prop
matheushdsbr Oct 19, 2023
9e35cbe
style(button): add isLoading prop to style svg when disabled
matheushdsbr Oct 19, 2023
fb9ff2e
docs(button): add loading section
matheushdsbr Oct 19, 2023
22f2dc3
refactor(button): adjust prop isLoading and structures, add aria-labe…
matheushdsbr Oct 23, 2023
cf53f65
docs(button): add inverted button and loading prop
matheushdsbr Oct 23, 2023
61b6cad
test(button): add tests to prop loading
matheushdsbr Oct 23, 2023
47c6ce2
refactor(button): adjust position relative when loading is true
matheushdsbr Oct 23, 2023
b86d823
test(button): update snapshot
matheushdsbr Oct 23, 2023
3449f6e
feat(button): add ref
matheushdsbr Oct 23, 2023
118962e
refactor(button): remove button loading mdx file
matheushdsbr Oct 23, 2023
f9b8c0d
refactor(button): refactor remove isLoading props to button.link and …
matheushdsbr Oct 24, 2023
9da1fd0
docs(button): update button loading example
matheushdsbr Oct 25, 2023
62f81d1
refactor(button): refactor struture to loading button prop and styles
matheushdsbr Oct 25, 2023
8098a29
test(button): update snapshots
matheushdsbr Oct 25, 2023
479900c
refactor(button-loading): adjust SpinnerContainer render
matheushdsbr Nov 8, 2023
abb514f
refactor(button-loading): add SpinnerContainer outside button functio…
matheushdsbr Nov 9, 2023
a4f5cf6
fix(button-loading): update snapshot
matheushdsbr Nov 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions packages/doc/content/components/components/button/default-web.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ You can use all differente compounds like `<Button.Outline />` and `<Button.Text
</Box>
```

#### Inverted
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ…

```javascript
<Box display="flex" justifyContent="space-evenly" width="100%">
<Button inverted>Find an activity</Button>
<Button secondary inverted>Find an activity</Button>
</Box>
```

#### As an anchor

```javascript
Expand All @@ -35,6 +43,31 @@ You can use all differente compounds like `<Button.Outline />` and `<Button.Text
</Box>
```

#### With Loading

```javascript state
render(() => {
const [loading, setLoading] = useState(true);
const onChange = () => setLoading(!loading);

return (
<Box display="flex" flexDirection="column" justifyContent="center" alignItems="start" width="auto" gap="medium">
<Box>
<Text>Loading</Text>
<Checkbox.Switch checked={loading} onChange={onChange} />
</Box>

<Box display="flex" gap="medium">
<Button isLoading={loading}>Find an activity</Button>
<Button icon={Booking} inverted isLoading={loading}>Find an activity</Button>
<Button icon={Booking} secondary isLoading={loading}>Find an activity</Button>
<Button secondary inverted isLoading={loading}>Find an activity</Button>
</Box>
</Box>
);
});
```

### Props

<PropsTable component="Button" platform="web" />
27 changes: 27 additions & 0 deletions packages/doc/content/components/components/button/icon-web.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,33 @@
</Box>
```

#### With Loading

```javascript state
render(() => {
const [loading, setLoading] = useState(true);
const onChange = () => setLoading(!loading);

return (
<Box display="flex" flexDirection="column" justifyContent="center" alignItems="start" width="auto" gap="large">
<Box>
<Text>Loading</Text>
<Checkbox.Switch checked={loading} onChange={onChange} />
</Box>

<Box display="flex" justifyContent="center" alignItems="center" gap="xxxlarge">
<Button.Icon icon={Booking} isLoading={loading} />
<Button.Icon icon={Edit} secondary isLoading={loading} />
<Button.Icon icon={Add} small isLoading={loading} />
<Button.Icon icon={Check} small secondary isLoading={loading} />
<Button.Icon icon={ChevronLeft} inverted isLoading={loading} />
<Button.Icon icon={Close} inverted secondary isLoading={loading} />
</Box>
</Box>
);
});
```

### Props

<PropsTable component="Button.Icon" platform="web" />
27 changes: 27 additions & 0 deletions packages/doc/content/components/components/button/outline.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,33 @@ You can use all differente compounds like `<Button />` and `<Button.Text />` com
</Box>
```

#### With Loading

```javascript state
render(() => {
const [loading, setLoading] = useState(true);
const onChange = () => setLoading(!loading);

return (
<Box display="flex" flexDirection="column" justifyContent="center" alignItems="start" width="auto" gap="large">
<Box>
<Text>Loading</Text>
<Checkbox.Switch checked={loading} onChange={onChange} />
</Box>

<Box display="flex" justifyContent="center" alignItems="center" gap="xxlarge">
<Button.Outline isLoading={loading}>Find an activity</Button.Outline>
<Button.Outline secondary isLoading={loading}>Find an activity</Button.Outline>
<Button.Outline icon={Booking} isLoading={loading}>Find an activity</Button.Outline>
<Button.Outline icon={Booking} secondary isLoading={loading}>
Find an activity
</Button.Outline>
</Box>
</Box>
);
});
```

### Props

<PropsTable component="Button" platform="web" />
25 changes: 23 additions & 2 deletions packages/yoga/src/Button/web/Button.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import React, { forwardRef } from 'react';
import { func, node, oneOfType, bool, string } from 'prop-types';
import styled from 'styled-components';
import StyledButton from './StyledButton';
import Spinner from '../../Spinner';

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

/** Buttons make common actions more obvious and help users more easily perform them. Buttons use labels and sometimes icons to communicate the action that will occur when the user touches them. */
const Button = forwardRef(
Expand All @@ -14,6 +23,7 @@ const Button = forwardRef(
small,
secondary,
icon: Icon,
isLoading,
...props
},
ref,
Expand All @@ -29,27 +39,36 @@ const Button = forwardRef(
return (
<StyledButton
ref={ref}
disabled={disabled}
disabled={disabled || isLoading}
aria-disabled={disabled}
full={full}
inverted={inverted}
onClick={onClick}
small={small}
secondary={secondary}
isLoading={isLoading}
{...finalProps}
>
{Icon && <Icon />}
{Icon && <Icon role="img" />}
{children}

{isLoading && (
<SpinnerContainer>
<Spinner color="deep" size={small ? 'small' : 'medium'} />
</SpinnerContainer>
)}
</StyledButton>
);
},
);

Button.propTypes = {
ariaLabel: string,
children: node,
disabled: bool,
full: bool,
inverted: bool,
isLoading: bool,
onClick: func,
small: bool,
secondary: bool,
Expand All @@ -59,10 +78,12 @@ Button.propTypes = {
};

Button.defaultProps = {
ariaLabel: undefined,
children: 'Button',
disabled: undefined,
full: false,
inverted: false,
isLoading: false,
onClick: () => {},
small: false,
secondary: false,
Expand Down
Loading
Loading