1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00
metamask-extension/ui/components/component-library/button-icon
Garrett Bear 03af17747b
Feat/15088/add button icon (#16277)
* 15088: add button icon

* button icon story updates

* add primary type

* update button icon docs

* add test

* button icon updates

* button icon and test updates

* button icon border radius and test update

* remove padding prop

* button icon updates

* Update ui/components/component-library/button-icon/button-icon.stories.js

Co-authored-by: George Marshall <george.marshall@consensys.net>

* Update ui/components/component-library/button-icon/button-icon.stories.js

Co-authored-by: George Marshall <george.marshall@consensys.net>

* Update ui/components/component-library/button-icon/button-icon.stories.js

Co-authored-by: George Marshall <george.marshall@consensys.net>

* add aria label for storybook demo

Co-authored-by: George Marshall <george.marshall@consensys.net>
2022-11-09 13:57:21 -08:00
..
__snapshots__ Feat/15088/add button icon (#16277) 2022-11-09 13:57:21 -08:00
button-icon.constants.js Feat/15088/add button icon (#16277) 2022-11-09 13:57:21 -08:00
button-icon.js Feat/15088/add button icon (#16277) 2022-11-09 13:57:21 -08:00
button-icon.scss Feat/15088/add button icon (#16277) 2022-11-09 13:57:21 -08:00
button-icon.stories.js Feat/15088/add button icon (#16277) 2022-11-09 13:57:21 -08:00
button-icon.test.js Feat/15088/add button icon (#16277) 2022-11-09 13:57:21 -08:00
index.js Feat/15088/add button icon (#16277) 2022-11-09 13:57:21 -08:00
README.mdx Feat/15088/add button icon (#16277) 2022-11-09 13:57:21 -08:00

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

# ButtonIcon

The `ButtonIcon` is used for icons associated with a user action.

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

## Props

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

<ArgsTable of={ButtonIcon} />

### Icon<span style={{ color: 'red' }}>\*</span>

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

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

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

<ButtonIcon icon={ICON_NAMES.CLOSE_OUTLINE} ariaLabel="Close" />;
```

### Size

Use the `size` prop and the `SIZES` object from `./ui/helpers/constants/design-system.js`
to change the size of `ButtonIcon`. Defaults to `SIZES.SM`

Optional: `BUTTON_ICON_SIZES` from `./button-icon` object can be used instead of `SIZES`.

Possible sizes include:

- `SIZES.SM` 24px
- `SIZES.LG` 32px

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

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

<ButtonIcon size={SIZES.SM} icon={ICON_NAMES.CLOSE_OUTLINE} ariaLabel="Close"/>
<ButtonIcon size={SIZES.LG} icon={ICON_NAMES.CLOSE_OUTLINE} ariaLabel="Close"/>
```

### Aria Label

Use the `ariaLabel` prop to set the name of the ButtonIcon for proper accessibility

<Canvas>
  <Story id="ui-components-component-library-button-icon-button-icon-stories-js--aria-label" />
</Canvas>

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


<ButtonIcon as="button" icon={ICON_NAMES.CLOSE_OUTLINE} ariaLabel="Close"/>
<ButtonIcon as="a" href="https://metamask.io/" target="_blank" icon={ICON_NAMES.EXPORT} color={COLORS.PRIMARY_DEFAULT} ariaLabel="Visit MetaMask.io"/>
```

### As

Use the `as` box prop to change the element of `ButtonIcon`. Defaults to `button`.

Button `as` options:

- `button`
- `a`

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

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


<ButtonIcon as="button" icon={ICON_NAMES.CLOSE_OUTLINE} ariaLabel="Close"/>
<ButtonIcon as="a" href="https://metamask.io/" target="_blank" icon={ICON_NAMES.EXPORT} color={COLORS.PRIMARY_DEFAULT} ariaLabel="Visit MetaMask.io"/>
```

### Href

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

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

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

<ButtonIcon
  href="https://metamask.io/"
  target="_blank"
  icon={ICON_NAMES.EXPORT}
  color={COLORS.PRIMARY_DEFAULT}
  ariaLabel="Visit MetaMask.io"
/>;
```

### Color

Use the `color` prop and the `COLORS` object to change the color of the `ButtonIcon`. Defaults to `COLORS.ICON_DEFAULT`.

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

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

<ButtonIcon
  icon={ICON_NAMES.EXPORT}
  color={COLORS.PRIMARY_DEFAULT}
  ariaLabel="Visit MetaMask.io"
/>;
```

### Disabled

Use the boolean `disabled` prop to disable button

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

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

<ButtonIcon icon={ICON_NAMES.CLOSE_OUTLINE} disabled ariaLabel="Close" />;
```