2022-11-09 22:55:13 +01:00
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import { Button } from './button';
2023-01-13 22:58:09 +01:00
import { ButtonBase } from '../button-base';
import { ButtonLink } from '../button-link';
2022-11-09 22:55:13 +01:00
# Button
2023-01-13 22:58:09 +01:00
The `Button` is used for user actions. It unifies `ButtonPrimary`, `ButtonSecondary` and `ButtonLink`.
2022-11-09 22:55:13 +01:00
<Canvas>
<Story id="ui-components-component-library-button-button-stories-js--default-story" />
</Canvas>
## Props
2023-01-13 22:58:09 +01:00
The `Button` accepts all props below as well as [Box](/docs/ui-components-ui-box-box-stories-js--default-story#props) component props
2022-11-09 22:55:13 +01:00
<ArgsTable of={Button} />
2023-01-13 22:58:09 +01:00
The `Button` accepts all [ButtonBase](/docs/ui-components-component-library-button-base-button-base-stories-js--default-story) component props
<ArgsTable of={ButtonBase} />
The `Button` accepts all [ButtonPrimary](/docs/ui-components-component-library-button-primary-button-primary-stories-js--default-story), [ButtonSecondary](/docs/ui-components-component-library-button-secondary-button-secondary-stories-js--default-story), and [ButtonLink](/docs/ui-components-component-library-button-link-button-link-stories-js--default-story) component props
<ArgsTable of={ButtonLink} />
2022-11-09 22:55:13 +01:00
### Type
Use the `type` prop and the `BUTTON_TYPES` object from `./button.constants.js` to change the `Button` type.
Possible types include:
- `BUTTON_TYPES.PRIMARY`
- `BUTTON_TYPES.SECONDARY`
- `BUTTON_TYPES.LINK`
<Canvas>
<Story id="ui-components-component-library-button-button-stories-js--type" />
</Canvas>
```jsx
import { Button, BUTTON_TYPES } from '../ui/component-library/button';
<Button type={BUTTON_TYPES.PRIMARY}>Button Primary</Button>
<Button type={BUTTON_TYPES.SECONDARY}>Button Secondary</Button>
<Button type={BUTTON_TYPES.LINK}>Button Link</Button>
```
### Size
Use the `size` prop and the `SIZES` object from `./ui/helpers/constants/design-system.js` to change the size of `Button`. Defaults to `SIZES.MD`
Optional: `BUTTON_SIZES` from `./button` object can be used instead of `SIZES`.
Possible sizes include:
2023-01-13 22:58:09 +01:00
- `SIZES.AUTO` inherits the font-size of the parent element. (Only used for `ButtonLink`)
2022-11-09 22:55:13 +01:00
- `SIZES.SM` 32px
- `SIZES.MD` 40px
- `SIZES.LG` 48px
<Canvas>
<Story id="ui-components-component-library-button-button-stories-js--size" />
</Canvas>
```jsx
import { SIZES } from '../../../helpers/constants/design-system';
2023-01-13 22:58:09 +01:00
import { Button } from '../ui/component-library';
2022-11-09 22:55:13 +01:00
<Button size={SIZES.AUTO} />
<Button size={SIZES.SM} />
<Button size={SIZES.MD} />
<Button size={SIZES.LG} />
```
### Danger
Use the `danger` boolean prop to change the `Button` to danger color.
<Canvas>
<Story id="ui-components-component-library-button-button-stories-js--danger" />
</Canvas>
```jsx
2023-01-13 22:58:09 +01:00
import { Button } from '../ui/component-library';
2022-11-09 22:55:13 +01:00
<Button>Normal</Button>
<Button danger>Danger</Button>
```
### Href
2023-01-13 22:58:09 +01:00
When an `href` prop is passed it will change the element to an anchor(`a`) tag.
2022-11-09 22:55:13 +01:00
<Canvas>
<Story id="ui-components-component-library-button-button-stories-js--href" />
</Canvas>
```jsx
2023-01-13 22:58:09 +01:00
import { Button } from '../ui/component-library';
2022-11-09 22:55:13 +01:00
2023-01-13 22:58:09 +01:00
<Button href="/">Anchor Element</Button>;
2022-11-09 22:55:13 +01:00
```
### Block
Use boolean `block` prop to quickly enable a full width block button
<Canvas>
<Story id="ui-components-component-library-button-button-stories-js--block" />
</Canvas>
```jsx
import { DISPLAY } from '../../../helpers/constants/design-system';
import { Button } from '../ui/component-library';
<Button>Default Button</Button>
<Button block>Block Button</Button>
```
### As
Use the `as` box prop to change the element of `Button`. Defaults to `button`.
When an `href` prop is passed it will change the element to an anchor(`a`) tag.
Button `as` options:
- `button`
- `a`
<Canvas>
<Story id="ui-components-component-library-button-button-stories-js--as" />
</Canvas>
```jsx
import { Button } from '../ui/component-library';
<Button as="button">Button Element</Button>
<Button as="a" href="#">
Anchor Element
</Button>
```
### Disabled
Use the boolean `disabled` prop to disable button
<Canvas>
<Story id="ui-components-component-library-button-button-stories-js--disabled" />
</Canvas>
```jsx
import { Button } from '../ui/component-library';
<Button disabled>Disabled Button</Button>;
```
### Loading
Use the boolean `loading` prop to set loading spinner
<Canvas>
<Story id="ui-components-component-library-button-button-stories-js--loading" />
</Canvas>
```jsx
import { Button } from '../ui/component-library';
<Button loading>Loading Button</Button>;
```
2023-01-13 22:58:09 +01:00
### Icon Name
Use the `iconName` prop and the `ICON_NAMES` object from `./ui/components/component-library/icon` to select icon.
2022-11-09 22:55:13 +01:00
2023-01-13 22:58:09 +01:00
Use the [IconSearch](/story/ui-components-component-library-icon-icon-stories-js--default-story) story to find the icon you want to use.
2022-11-09 22:55:13 +01:00
<Canvas>
2023-01-13 22:58:09 +01:00
<Story id="ui-components-component-library-button-button-stories-js--icon-name" />
2022-11-09 22:55:13 +01:00
</Canvas>
```jsx
import { Button } from '../ui/component-library';
import { ICON_NAMES } from '../icon';
2023-01-13 22:58:09 +01:00
<Button iconName={ICON_NAMES.ADD_SQUARE_FILLED}>Button</Button>;
2022-11-09 22:55:13 +01:00
```