1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 20:39:08 +01:00
metamask-extension/ui/components/component-library/button-base
2023-02-14 11:33:04 -06:00
..
__snapshots__ Feat/16637/button housekeeping (#16872) 2023-01-13 13:58:09 -08:00
button-base.constants.js feature: migrate design-system.ts (#17518) 2023-02-02 20:15:26 +00:00
button-base.js feature: migrate design-system.ts (#17518) 2023-02-02 20:15:26 +00:00
button-base.scss button link housekeeping (#16885) 2023-01-26 10:32:11 -08:00
button-base.stories.js feature: migrate design-system.ts (#17518) 2023-02-02 20:15:26 +00:00
button-base.test.js button link housekeeping (#16885) 2023-01-26 10:32:11 -08:00
index.js button base housekeeping (#16336) 2022-11-03 11:41:16 -07:00
README.mdx fix broken stories and readme from TS update (#17703) 2023-02-14 11:33:04 -06: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>
  <Story id="components-componentlibrary-buttonbase--default-story" />
</Canvas>

## Props

The `ButtonBase` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) component props

<ArgsTable of={ButtonBase} />

### Size

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`

Optional: `BUTTON_BASE_SIZES` from `./button-base` object can be used instead of `Size`.

Possible sizes include:

- `Size.SM` 32px
- `Size.MD` 40px
- `Size.LG` 48px

<Canvas>
  <Story id="components-componentlibrary-buttonbase--size-story" />
</Canvas>

```jsx
import { Size } from '../../../helpers/constants/design-system';
import { ButtonBase } from '../../component-library';

<ButtonBase size={Size.SM} />
<ButtonBase size={Size.MD} />
<ButtonBase size={Size.LG} />
```

### Block

Use boolean `block` prop to quickly enable a full width block button

<Canvas>
  <Story id="components-componentlibrary-buttonbase--block" />
</Canvas>

```jsx
import { DISPLAY } from '../../../helpers/constants/design-system';
import { ButtonBase } from '../../component-library';

<ButtonBase>Default Button</ButtonBase>
<ButtonBase block>Block Button</ButtonBase>
```

### As

Use the `as` box prop to change the element of `ButtonBase`. 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="components-componentlibrary-buttonbase--as" />
</Canvas>

```jsx
import { ButtonBase } from '../../component-library';


<ButtonBase as="button">Button Element</ButtonBase>
<ButtonBase as="a" href="#">
  Anchor Element
</ButtonBase>
```

### Href

When an `href` prop is passed it will change the element to an anchor(`a`) tag.

<Canvas>
  <Story id="components-componentlibrary-buttonbase--href" />
</Canvas>

```jsx
import { ButtonBase } from '../../component-library';

<ButtonBase href="/metamask">Anchor Element</ButtonBase>;
```

### Disabled

Use the boolean `disabled` prop to disable button

<Canvas>
  <Story id="components-componentlibrary-buttonbase--disabled" />
</Canvas>

```jsx
import { ButtonBase } from '../../component-library';

<ButtonBase disabled>Disabled Button</ButtonBase>;
```

### Loading

Use the boolean `loading` prop to set loading spinner

<Canvas>
  <Story id="components-componentlibrary-buttonbase--loading" />
</Canvas>

```jsx
import { ButtonBase } from '../../component-library';

<ButtonBase loading>Loading Button</ButtonBase>;
```

### Icon Name

Use the `iconName` prop and the `ICON_NAMES` object from `./ui/components/component-library` to select icon.

<Canvas>
  <Story id="components-componentlibrary-buttonbase--icon" />
</Canvas>

```jsx
import { ButtonBase } from '../../component-library';
import { ICON_NAMES } from '../icon';

<ButtonBase icon={ICON_NAMES.ADD_SQUARE}>Button</ButtonBase>;
```