1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 16:18:07 +01:00
metamask-extension/ui/components/component-library/button
2023-04-05 09:11:10 -07:00
..
__snapshots__ update text component color to use box color (#18246) 2023-03-23 13:00:37 -07:00
button.constants.js feature: migrate design-system.ts (#17518) 2023-02-02 20:15:26 +00:00
button.js Feat/16290/add button component (#16305) 2022-11-09 13:55:13 -08:00
button.stories.js Updating icon imports to TS version in component-library folder (#18449) 2023-04-05 09:11:10 -07:00
button.test.js Updating icon imports to TS version in component-library folder (#18449) 2023-04-05 09:11:10 -07:00
index.js Feat/16637/button housekeeping (#16872) 2023-01-13 13:58:09 -08:00
README.mdx Updating icon imports to TS version in component-library folder (#18449) 2023-04-05 09:11:10 -07:00

import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import { Button } from './button';
import { ButtonBase } from '../button-base';
import { ButtonLink } from '../button-link';

# Button

The `Button` is used for user actions. It unifies `ButtonPrimary`, `ButtonSecondary` and `ButtonLink`.

<Canvas>
  <Story id="components-componentlibrary-button--default-story" />
</Canvas>

## Props

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

<ArgsTable of={Button} />

The `Button` accepts all [ButtonBase](/docs/components-componentlibrary-buttonbase--default-story#props) component props

<ArgsTable of={ButtonBase} />

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

<ArgsTable of={ButtonLink} />

### 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="components-componentlibrary-button--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 `Size` object from `./ui/helpers/constants/design-system.js` to change the size of `Button`. Defaults to `Size.MD`

Optional: `BUTTON_SIZES` from `./button` object can be used instead of `Size`.

Possible sizes include:

- `Size.inherit` inherits the font-size of the parent element. For [ButtonLink](/docs/components-componentlibrary-buttonlink--default-story) uses only
- `Size.auto` inherits auto height, but keeps the same button font-size. For [ButtonLink](/docs/components-componentlibrary-buttonlink--default-story) uses only
- `Size.SM` 32px
- `Size.MD` 40px
- `Size.LG` 48px

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

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

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

### Danger

Use the `danger` boolean prop to change the `Button` to danger color.

<Canvas>
  <Story id="components-componentlibrary-button--danger" />
</Canvas>

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

<Button>Normal</Button>
<Button danger>Danger</Button>
```

### Href

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

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

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

<Button href="/">Anchor Element</Button>;
```

### Block

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

<Canvas>
  <Story id="components-componentlibrary-button--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="components-componentlibrary-button--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="components-componentlibrary-button--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="components-componentlibrary-button--loading" />
</Canvas>

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

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

### Icon Name

Use the `startIconName` and/or `endIconName` prop and the `IconName` enum from `./ui/components/component-library/icon` to select icon.

Use the [IconSearch](/story/components-componentlibrary-icon--default-story) story to find the icon you want to use.

<Canvas>
  <Story id="components-componentlibrary-button--start-icon-name" />
</Canvas>

```jsx
import { Button } from '../ui/component-library';
import { IconName } from '../icon';

<Button startIconName={IconName.AddSquare}>Button</Button>;
```

<Canvas>
  <Story id="components-componentlibrary-button--end-icon-name" />
</Canvas>

```jsx
import { Button } from '../ui/component-library';
import { IconName } from '../icon';

<Button endIconName={IconName.Arrow2Right}>Button</Button>;
```