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-icon
2023-04-05 09:11:10 -07:00
..
__snapshots__ Updating Icon html element to span (#17790) 2023-02-22 14:42:50 -08:00
button-icon.constants.js feature: migrate design-system.ts (#17518) 2023-02-02 20:15:26 +00:00
button-icon.js Updating icon imports to TS version in component-library folder (#18449) 2023-04-05 09:11:10 -07:00
button-icon.scss Feat/15088/add button icon (#16277) 2022-11-09 13:57:21 -08:00
button-icon.stories.js Updating icon imports to TS version in component-library folder (#18449) 2023-04-05 09:11:10 -07:00
button-icon.test.js Updating icon imports to TS version in component-library folder (#18449) 2023-04-05 09:11:10 -07:00
index.js Feat/15088/add button icon (#16277) 2022-11-09 13:57:21 -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 { ButtonIcon } from './button-icon';

# ButtonIcon

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

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

## Props

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

<ArgsTable of={ButtonIcon} />

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

Use the required `iconName` prop with `IconName` enum from `./ui/components/component-library` 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-buttonicon--icon-name-story" />
</Canvas>

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

<ButtonIcon iconName={IconName.Close} ariaLabel="Close" />;
```

### Size

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

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

Possible sizes include:

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

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

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

<ButtonIcon size={Size.SM} iconName={IconName.Close} ariaLabel="Close"/>
<ButtonIcon size={Size.LG} iconName={IconName.Close} ariaLabel="Close"/>
```

### Aria Label

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

<Canvas>
  <Story id="components-componentlibrary-buttonicon--aria-label" />
</Canvas>

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


<ButtonIcon as="button" iconName={IconName.Close} ariaLabel="Close"/>
<ButtonIcon as="a" href="https://metamask.io/" target="_blank" iconName={IconName.Export} color={Color.primaryDefault} 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="components-componentlibrary-buttonicon--as" />
</Canvas>

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


<ButtonIcon as="button" iconName={IconName.Close} ariaLabel="Close"/>
<ButtonIcon as="a" href="https://metamask.io/" target="_blank" iconName={IconName.Export} color={Color.primaryDefault} ariaLabel="Visit MetaMask.io"/>
```

### Href

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

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

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

<ButtonIcon
  href="https://metamask.io/"
  target="_blank"
  iconName={IconName.Export}
  color={Color.primaryDefault}
  ariaLabel="Visit MetaMask.io"
/>;
```

### Color

Use the `color` prop and the `Color` object to change the color of the `ButtonIcon`. Defaults to `Color.iconDefault`.

<Canvas>
  <Story id="components-componentlibrary-buttonicon--color-story" />
</Canvas>

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

<ButtonIcon
  iconName={IconName.Export}
  color={Color.primaryDefault}
  ariaLabel="Visit MetaMask.io"
/>;
```

### Disabled

Use the boolean `disabled` prop to disable button

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

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

<ButtonIcon iconName={IconName.Close} disabled ariaLabel="Close" />;
```