1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/components/ui/button
2022-01-19 11:14:32 -06:00
..
button.component.js Create "inline" type for Button component (#13304) 2022-01-19 11:14:32 -06:00
button.stories.js Create "inline" type for Button component (#13304) 2022-01-19 11:14:32 -06:00
button.stories.test.js Add storybook render tests with CI integration (#12477) 2021-11-23 16:41:30 -08:00
buttons.scss Create "inline" type for Button component (#13304) 2022-01-19 11:14:32 -06:00
index.js remove the ui/app and ui/lib folders (#10911) 2021-04-28 14:53:59 -05:00
README.mdx Updating storybook docs (#13055) 2022-01-07 12:30:37 -08:00

import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';

import Button from '.';

# Button

Buttons communicate actions that users can take.

<Canvas>
  <Story id="ui-components-ui-button-button-stories-js--default-story" />
</Canvas>

## Component API

<ArgsTable of={Button} />

## Usage

The following describes the props and example usage for this component.

### Type

By changing the `type` prop you can use different styles of the button.

| type              | Description                                                                                           |
| ----------------- | ----------------------------------------------------------------------------------------------------- |
| `default`         | default style of the button                                                                           |
| `primary`         | the principle call to action on the page                                                              |
| `secondary`       | secondary actions on each page                                                                        |
| `warning`         | a warning action in the page                                                                          |
| `danger`          | a negative action (such as Delete) on the page                                                        |
| `danger--primary` | a negative principle call to action (such as Delete) on the page                                      |
| `link`            | an optional action or navigation action out of the app changes root html tag from `<button>` to `<a>` |

<Canvas>
  <Story id="ui-components-ui-button-button-stories-js--type" />
</Canvas>

### Type Link

By changing the `type` to `"link"` the root html element of the button changes from `<button>` to `<a>`.

Rendered html

```html
<a class="button btn-link">Click me</a>
```

<Canvas>
  <Story id="ui-components-ui-button-button-stories-js--type-link" />
</Canvas>

### Icon

Pass an icon component to `icon` prop to add an icon to the left side of the Button.

<Canvas>
  <Story id="ui-components-ui-button-button-stories-js--icon" />
</Canvas>

## Submit

If the `submit` prop is set to `true` the html type attribute will be set to `type="submit"`

```html
<button class="button btn--rounded btn-primary" type="submit">Submit</button>
```

<Canvas>
  <Story id="ui-components-ui-button-button-stories-js--submit" />
</Canvas>

## OnClick

If the `onClick` prop is provided and is of type `function` the button html will render with `role="button"` and `tabIndex="0"` attributes. It also provides keyboard functionality on press of the "Enter" key.

```html
<button class="button btn--rounded btn-default" role="button" tabindex="0">
  Click me
</button>
```