2022-10-04 18:55:51 +02:00
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import { ButtonBase } from './button-base';
### This is a base component. It should not be used in your feature code directly but as a "base" for other UI components
# ButtonBase
The `ButtonBase` is the base component for buttons.
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-buttonbase--default-story" />
2022-10-04 18:55:51 +02:00
</Canvas>
## Props
2023-01-20 20:27:46 +01:00
The `ButtonBase` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) component props
2022-10-04 18:55:51 +02:00
<ArgsTable of={ButtonBase} />
### 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 `ButtonBase`. Defaults to `Size.MD`
2022-10-04 18:55:51 +02:00
2023-02-14 18:33:04 +01:00
Optional: `BUTTON_BASE_SIZES` from `./button-base` object can be used instead of `Size`.
2022-10-04 18:55:51 +02:00
Possible sizes include:
2023-02-14 18:33:04 +01:00
- `Size.SM` 32px
- `Size.MD` 40px
- `Size.LG` 48px
2022-10-04 18:55:51 +02:00
<Canvas>
2023-02-14 18:33:04 +01:00
<Story id="components-componentlibrary-buttonbase--size-story" />
2022-10-04 18:55:51 +02:00
</Canvas>
```jsx
2023-02-02 21:15:26 +01:00
import { Size } from '../../../helpers/constants/design-system';
2023-01-25 20:54:08 +01:00
import { ButtonBase } from '../../component-library';
2022-10-04 18:55:51 +02:00
2023-02-02 21:15:26 +01:00
<ButtonBase size={Size.SM} />
<ButtonBase size={Size.MD} />
<ButtonBase size={Size.LG} />
2022-10-04 18:55:51 +02: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-buttonbase--block" />
2022-10-04 18:55:51 +02:00
</Canvas>
```jsx
import { DISPLAY } from '../../../helpers/constants/design-system';
2023-01-25 20:54:08 +01:00
import { ButtonBase } from '../../component-library';
2022-10-04 18:55:51 +02:00
<ButtonBase>Default Button</ButtonBase>
<ButtonBase block>Block Button</ButtonBase>
```
### As
Use the `as` box prop to change the element of `ButtonBase`. Defaults to `button`.
2022-10-14 00:39:22 +02:00
When an `href` prop is passed it will change the element to an anchor(`a`) tag.
2022-10-04 18:55:51 +02:00
Button `as` options:
- `button`
- `a`
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-buttonbase--as" />
2022-10-04 18:55:51 +02:00
</Canvas>
```jsx
2023-01-25 20:54:08 +01:00
import { ButtonBase } from '../../component-library';
2022-10-04 18:55:51 +02:00
<ButtonBase as="button">Button Element</ButtonBase>
<ButtonBase as="a" href="#">
Anchor Element
</ButtonBase>
```
2022-11-03 19:41:16 +01:00
### Href
When an `href` prop is passed it will change the element to an anchor(`a`) tag.
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-buttonbase--href" />
2022-11-03 19:41:16 +01:00
</Canvas>
```jsx
2023-01-25 20:54:08 +01:00
import { ButtonBase } from '../../component-library';
2022-11-03 19:41:16 +01:00
<ButtonBase href="/metamask">Anchor Element</ButtonBase>;
```
2023-03-10 18:47:01 +01:00
### External link
When an `externalLink` prop is passed it will change the element to an anchor(`a`) tag and add the `target="_blank"` and `rel="noopener noreferrer"` attributes.
2023-03-22 03:19:49 +01:00
<Canvas>
2023-03-10 18:47:01 +01:00
<Story id="components-componentlibrary-buttonbase--external-link" />
2023-03-22 03:19:49 +01:00
</Canvas>
2023-03-10 18:47:01 +01:00
```jsx
import { ButtonBase } from '../../component-library';
<ButtonBase href="https://metamask.io" externalLink>
Anchor element with external link
</ButtonBase>;
```
2022-10-04 18:55:51 +02:00
### Disabled
Use the boolean `disabled` prop to disable button
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-buttonbase--disabled" />
2022-10-04 18:55:51 +02:00
</Canvas>
```jsx
2023-01-25 20:54:08 +01:00
import { ButtonBase } from '../../component-library';
2022-10-04 18:55:51 +02:00
<ButtonBase disabled>Disabled Button</ButtonBase>;
```
### Loading
Use the boolean `loading` prop to set loading spinner
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-buttonbase--loading" />
2022-10-04 18:55:51 +02:00
</Canvas>
```jsx
2023-01-25 20:54:08 +01:00
import { ButtonBase } from '../../component-library';
2022-10-04 18:55:51 +02:00
<ButtonBase loading>Loading Button</ButtonBase>;
```
2023-01-13 22:58:09 +01:00
### Icon Name
2022-10-04 18:55:51 +02:00
2023-02-22 18:42:06 +01:00
Use the `startIconName` and/or `endIconName` prop with the `ICON_NAMES` object from `./ui/components/component-library` to select icon.
2022-10-04 18:55:51 +02:00
<Canvas>
2023-02-22 18:42:06 +01:00
<Story id="components-componentlibrary-buttonbase--start-icon-name" />
2022-10-04 18:55:51 +02:00
</Canvas>
```jsx
2023-01-25 20:54:08 +01:00
import { ButtonBase } from '../../component-library';
2022-10-04 18:55:51 +02:00
import { ICON_NAMES } from '../icon';
2023-02-22 18:42:06 +01:00
<ButtonBase startIconName={ICON_NAMES.ADD_SQUARE}>Button</ButtonBase>;
```
<Canvas>
<Story id="components-componentlibrary-buttonbase--end-icon-name" />
</Canvas>
```jsx
import { ButtonBase } from '../../component-library';
import { ICON_NAMES } from '../icon';
<ButtonBase endIconName={ICON_NAMES.ARROW_2_RIGHT}>Button</ButtonBase>;
```
### RTL
2023-03-22 03:19:49 +01:00
For RTL language support use the `textDirection` prop.
2023-02-22 18:42:06 +01:00
<Canvas>
<Story id="components-componentlibrary-buttonbase--rtl" />
</Canvas>
```jsx
import { ButtonBase, ICON_NAMES } from '../../component-library';
<>
<ButtonBase
startIconName={ICON_NAMES.ADD_SQUARE}
endIconName={ICON_NAMES.ARROW_2_RIGHT}
>
Button Demo
</ButtonBase>
<ButtonBase
startIconName={ICON_NAMES.ADD_SQUARE}
endIconName={ICON_NAMES.ARROW_2_RIGHT}
2023-03-22 03:19:49 +01:00
textDirection={TEXT_DIRECTIONS.RIGHT_TO_LEFT}
2023-02-22 18:42:06 +01:00
>
Button Demo
</ButtonBase>
</>;
2022-10-04 18:55:51 +02:00
```
2023-03-22 03:19:49 +01:00
### Ellipsis
Use the boolean `ellipsis` prop to change the if the `ButtonBase` component to have an ellipsis.
Note: this should only be used for dynamic/user generated content or addresses. Generally, button text should be succinct and only contain one or two words.
<Canvas>
<Story id="components-componentlibrary-buttonbase--ellipsis" />
</Canvas>
```jsx
import { ButtonBase } from '../../component-library';
<Box style={{ width: 180 }}>
<ButtonBase>This is long text example without ellipsis</ButtonBase>
<ButtonBase ellipsis>This is long text example with ellipsis</ButtonBase>
</Box>;
```