Skip to content

Commit

Permalink
feat(store-ui): Loading Button molecule (#962)
Browse files Browse the repository at this point in the history
* 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
4 people authored Oct 21, 2021
1 parent c515820 commit 6083ea0
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 2 deletions.
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 packages/store-ui/src/molecules/LoadingButton/LoadingButton.tsx
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
2 changes: 2 additions & 0 deletions packages/store-ui/src/molecules/LoadingButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './LoadingButton'
export type { LoadingButtonProps } from './LoadingButton'
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.
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,
},
},
}
5 changes: 3 additions & 2 deletions themes/theme-b2c-tailwind/src/molecules/index.css
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 themes/theme-b2c-tailwind/src/molecules/loading-button.css
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;
}

0 comments on commit 6083ea0

Please sign in to comment.