-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(store-ui): Loading Button molecule (#962)
* BREAKING CHANGE: Remove deprecated folders (#927) * feat(store-ui): adding list atom (#918) Create List component as an Atom. * feat(store-ui): Add Skeleton Atom (#911) * Add skeleton atom * Move animation to theme * Import tailwind utilities * Update test * Use only 1 div * Update story * Extend HTMLDivElement * Spinner exports * lint * Loading Button molecule * removing duplicated line in package.json * Remove loading prop default value * Adds component inheritance inside docs * change spread props naming Co-authored-by: Tiago Gimenes <tlgimenes@gmail.com> Co-authored-by: Bento Pereira <40964933+bentoper@users.noreply.github.com> Co-authored-by: Larícia Mota <laricia.mota@vtex.com.br>
- Loading branch information
1 parent
c515820
commit 6083ea0
Showing
7 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
packages/store-ui/src/molecules/LoadingButton/LoadingButton.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { render } from '@testing-library/react' | ||
import React from 'react' | ||
|
||
import LoadingButton from './LoadingButton' | ||
|
||
describe('Loading Button', () => { | ||
it('`data-store-loading-button` is present', () => { | ||
const { getByTestId } = render(<LoadingButton loading />) | ||
|
||
expect(getByTestId('store-loading-button')).toHaveAttribute( | ||
'data-store-loading-button' | ||
) | ||
}) | ||
}) |
36 changes: 36 additions & 0 deletions
36
packages/store-ui/src/molecules/LoadingButton/LoadingButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React, { forwardRef } from 'react' | ||
|
||
import Button from '../../atoms/Button' | ||
import type { ButtonProps } from '../../atoms/Button' | ||
import Spinner from '../../atoms/Spinner' | ||
|
||
export interface LoadingButtonProps extends ButtonProps { | ||
/** | ||
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest). | ||
*/ | ||
testId?: string | ||
/** | ||
* The current loading state of the button. | ||
*/ | ||
loading: boolean | ||
} | ||
|
||
const LoadingButton = forwardRef<HTMLButtonElement, LoadingButtonProps>( | ||
function LoadingButton( | ||
{ children, loading, testId = 'store-loading-button', ...otherProps }, | ||
ref | ||
) { | ||
return ( | ||
<Button | ||
ref={ref} | ||
data-store-loading-button | ||
testId={testId} | ||
{...otherProps} | ||
> | ||
{loading ? <Spinner /> : children} | ||
</Button> | ||
) | ||
} | ||
) | ||
|
||
export default LoadingButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from './LoadingButton' | ||
export type { LoadingButtonProps } from './LoadingButton' |
20 changes: 20 additions & 0 deletions
20
packages/store-ui/src/molecules/LoadingButton/stories/LoadingButton.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs' | ||
import LoadingButton from '../LoadingButton' | ||
|
||
# Loading Button | ||
|
||
<Canvas> | ||
<Story id="molecules-loadingbutton--loadingbutton" /> | ||
</Canvas> | ||
|
||
## Props | ||
|
||
<ArgsTable of={LoadingButton} /> | ||
|
||
## CSS Selectors | ||
|
||
```css | ||
[data-store-loading-button] {} | ||
``` | ||
|
||
This component inherits [Button](?path=/docs/atoms-button--button#css-selectors) css selectors. |
35 changes: 35 additions & 0 deletions
35
packages/store-ui/src/molecules/LoadingButton/stories/LoadingButton.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { Story } from '@storybook/react' | ||
import React from 'react' | ||
|
||
import type { ComponentArgTypes } from '../../../typings/utils' | ||
import type { LoadingButtonProps } from '../LoadingButton' | ||
import Component from '../LoadingButton' | ||
import mdx from './LoadingButton.mdx' | ||
|
||
const LoadingButtonTemplate: Story<LoadingButtonProps> = ({ | ||
loading, | ||
testId, | ||
}) => ( | ||
<Component loading={loading} testId={testId}> | ||
Loading Button | ||
</Component> | ||
) | ||
|
||
export const LoadingButton = LoadingButtonTemplate.bind({}) | ||
|
||
const argTypes: ComponentArgTypes<LoadingButtonProps> = { | ||
loading: { | ||
type: 'boolean', | ||
defaultValue: false, | ||
}, | ||
} | ||
|
||
export default { | ||
title: 'Molecules/LoadingButton', | ||
argTypes, | ||
parameters: { | ||
docs: { | ||
page: mdx, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
@import "./bullets.css"; | ||
@import "./search-input.css"; | ||
@import "./carousel.css"; | ||
@import "./icon-button.css"; | ||
@import "./loading-button.css"; | ||
@import './price-range.css'; | ||
@import "./carousel.css"; | ||
@import "./modal.css"; | ||
@import "./accordion.css"; | ||
@import "./table.css"; | ||
@import "./search-input.css"; |
10 changes: 10 additions & 0 deletions
10
themes/theme-b2c-tailwind/src/molecules/loading-button.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[data-store-loading-button] { | ||
@apply h-11 w-60 items-center justify-center flex; | ||
} | ||
|
||
[data-store-loading-button] [data-store-spinner] { | ||
border-top: 0.2em solid rgba(255, 255, 255, 0.2); | ||
border-right: 0.2em solid rgba(255, 255, 255, 0.2); | ||
border-bottom: 0.2em solid rgba(255, 255, 255, 0.2); | ||
border-left: 0.2em solid #ffffff; | ||
} |