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>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-button--default-story" />
2022-11-09 22:55:13 +01:00
</Canvas>
## Props
2023-01-20 20:27:46 +01:00
The `Button` accepts all props below as well as all [ButtonPrimary](/docs/components-componentlibrary-buttonprimary--default-story), [ButtonSecondary](/docs/components-componentlibrary-buttonsecondary--default-story), [ButtonLink](/docs/components-componentlibrary-buttonlink--default-story), and [Box](/docs/components-ui-box--default-story#props) component props
2022-11-09 22:55:13 +01:00
<ArgsTable of={Button} />
2023-01-20 20:27:46 +01:00
The `Button` accepts all [ButtonBase](/docs/components-componentlibrary-buttonbase--default-story#props) component props
2023-01-13 22:58:09 +01:00
<ArgsTable of={ButtonBase} />
2023-01-20 20:27:46 +01:00
The `Button` accepts all [ButtonPrimary](/docs/components-componentlibrary-buttonprimary--default-story), [ButtonSecondary](/docs/components-componentlibrary-buttonsecondary--default-story), [ButtonLink](/docs/components-componentlibrary-buttonlink--default-story), and [Box](/docs/components-ui-box--default-story#props) component props
2023-01-13 22:58:09 +01:00
<ArgsTable of={ButtonLink} />
2023-04-26 18:17:25 +02:00
### Variant
2022-11-09 22:55:13 +01:00
2023-04-26 18:17:25 +02:00
Use the `variant` prop and the `BUTTON_VARIANT` object from `./button.constants.js` to change the `Button` variant.
2022-11-09 22:55:13 +01:00
2023-04-26 18:17:25 +02:00
Possible variants include:
2022-11-09 22:55:13 +01:00
2023-04-26 18:17:25 +02:00
- `BUTTON_VARIANT.PRIMARY`
- `BUTTON_VARIANT.SECONDARY`
- `BUTTON_VARIANT.LINK`
2022-11-09 22:55:13 +01:00
<Canvas>
2023-04-26 18:17:25 +02:00
<Story id="components-componentlibrary-button--variant" />
2022-11-09 22:55:13 +01:00
</Canvas>
```jsx
2023-04-26 18:17:25 +02:00
import { Button, BUTTON_VARIANT } from '../ui/component-library/button';
2022-11-09 22:55:13 +01:00
2023-04-26 18:17:25 +02:00
<Button variant={BUTTON_VARIANT.PRIMARY}>Button Primary</Button>
<Button variant={BUTTON_VARIANT.SECONDARY}>Button Secondary</Button>
<Button variant={BUTTON_VARIANT.LINK}>Button Link</Button>
2022-11-09 22:55:13 +01:00
```
### Size
2023-02-14 18:33:04 +01:00
Use the `size` prop and the `Size` object from `./ui/helpers/constants/design-system.js` to change the size of `Button`. Defaults to `Size.MD`
2022-11-09 22:55:13 +01:00
2023-02-14 18:33:04 +01:00
Optional: `BUTTON_SIZES` from `./button` object can be used instead of `Size`.
2022-11-09 22:55:13 +01:00
Possible sizes include:
2023-02-02 21:15:26 +01:00
- `Size.inherit` inherits the font-size of the parent element. For [ButtonLink](/docs/components-componentlibrary-buttonlink--default-story) uses only
2023-02-14 18:33:04 +01:00
- `Size.auto` inherits auto height, but keeps the same button font-size. For [ButtonLink](/docs/components-componentlibrary-buttonlink--default-story) uses only
2023-02-02 21:15:26 +01:00
- `Size.SM` 32px
- `Size.MD` 40px
- `Size.LG` 48px
2022-11-09 22:55:13 +01:00
<Canvas>
2023-02-14 18:33:04 +01:00
<Story id="components-componentlibrary-button--size-story" />
2022-11-09 22:55:13 +01:00
</Canvas>
```jsx
2023-02-14 18:33:04 +01:00
import { Size } 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
2023-02-14 18:33:04 +01:00
<Button size={Size.inherit} />
<Button size={Size.SM} />
<Button size={Size.MD} />
<Button size={Size.LG} />
2022-11-09 22:55:13 +01:00
```
### Danger
Use the `danger` boolean prop to change the `Button` to danger color.
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-button--danger" />
2022-11-09 22:55:13 +01:00
</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>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-button--href" />
2022-11-09 22:55:13 +01:00
</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>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-button--block" />
2022-11-09 22:55:13 +01:00
</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>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-button--as" />
2022-11-09 22:55:13 +01:00
</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>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-button--disabled" />
2022-11-09 22:55:13 +01:00
</Canvas>
```jsx
import { Button } from '../ui/component-library';
<Button disabled>Disabled Button</Button>;
```
### Loading
Use the boolean `loading` prop to set loading spinner
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-button--loading" />
2022-11-09 22:55:13 +01:00
</Canvas>
```jsx
import { Button } from '../ui/component-library';
<Button loading>Loading Button</Button>;
```
2023-01-13 22:58:09 +01:00
### Icon Name
2023-04-05 18:11:10 +02:00
Use the `startIconName` and/or `endIconName` prop and the `IconName` enum from `./ui/components/component-library/icon` to select icon.
2022-11-09 22:55:13 +01:00
2023-01-25 20:51:25 +01:00
Use the [IconSearch](/story/components-componentlibrary-icon--default-story) story to find the icon you want to use.
2022-11-09 22:55:13 +01:00
<Canvas>
2023-02-22 18:42:06 +01:00
<Story id="components-componentlibrary-button--start-icon-name" />
2022-11-09 22:55:13 +01:00
</Canvas>
```jsx
import { Button } from '../ui/component-library';
2023-04-05 18:11:10 +02:00
import { IconName } from '../icon';
2022-11-09 22:55:13 +01:00
2023-04-05 18:11:10 +02:00
<Button startIconName={IconName.AddSquare}>Button</Button>;
2023-02-22 18:42:06 +01:00
```
<Canvas>
<Story id="components-componentlibrary-button--end-icon-name" />
</Canvas>
```jsx
import { Button } from '../ui/component-library';
2023-04-05 18:11:10 +02:00
import { IconName } from '../icon';
2023-02-22 18:42:06 +01:00
2023-04-05 18:11:10 +02:00
<Button endIconName={IconName.Arrow2Right}>Button</Button>;
2022-11-09 22:55:13 +01:00
```