2022-11-09 22:57:21 +01: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>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-buttonicon--default-story" />
2022-11-09 22:57:21 +01:00
</Canvas>
## Props
2023-01-20 20:27:46 +01:00
The `ButtonIcon` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) component props
2022-11-09 22:57:21 +01:00
<ArgsTable of={ButtonIcon} />
2022-12-01 18:26:31 +01:00
### Icon Name<span style={{ color: 'red' }}>\*</span>
2022-11-09 22:57:21 +01:00
2023-04-05 18:11:10 +02:00
Use the required `iconName` prop with `IconName` enum from `./ui/components/component-library` to select icon.
2022-12-01 18:26:31 +01:00
2023-01-20 20:27:46 +01:00
Use the [IconSearch](/story/components-componentlibrary-icon--default-story) story to find the icon you want to use.
2022-11-09 22:57:21 +01:00
<Canvas>
2023-04-05 18:11:10 +02:00
<Story id="components-componentlibrary-buttonicon--icon-name-story" />
2022-11-09 22:57:21 +01:00
</Canvas>
```jsx
import { ButtonIcon } from '../ui/component-library';
2023-04-05 18:11:10 +02:00
import { IconName } from '../icon';
2022-11-09 22:57:21 +01:00
2023-04-05 18:11:10 +02:00
<ButtonIcon iconName={IconName.Close} ariaLabel="Close" />;
2022-11-09 22:57:21 +01:00
```
### Size
2023-04-12 17:55:24 +02:00
Use the `size` prop and the `ButtonIconSize` enum from `./ui/components/component-library/icon` to change the size of `ButtonIcon`. Defaults to `ButtonIconSize.Sm`
2022-11-09 22:57:21 +01:00
Possible sizes include:
2023-04-12 17:55:24 +02:00
- `ButtonIconSize.Sm` 24px
- `ButtonIconSize.Lg` 32px
2022-11-09 22:57:21 +01:00
<Canvas>
2023-02-14 18:33:04 +01:00
<Story id="components-componentlibrary-buttonicon--size-story" />
2022-11-09 22:57:21 +01:00
</Canvas>
```jsx
2023-04-12 17:55:24 +02:00
import { ButtonIconSize } from '../../../helpers/constants/design-system';
2022-11-09 22:57:21 +01:00
import { ButtonIcon } from '../ui/component-library';
2023-04-12 17:55:24 +02:00
<ButtonIcon size={ButtonIconSize.Sm} iconName={IconName.Close} ariaLabel="Close"/>
<ButtonIcon size={ButtonIconSize.Lg} iconName={IconName.Close} ariaLabel="Close"/>
2022-11-09 22:57:21 +01:00
```
### Aria Label
Use the `ariaLabel` prop to set the name of the ButtonIcon for proper accessibility
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-buttonicon--aria-label" />
2022-11-09 22:57:21 +01:00
</Canvas>
```jsx
2023-04-05 18:11:10 +02:00
import { ButtonIcon, IconName } from '../ui/component-library';
2023-02-14 18:33:04 +01:00
import { Color } from '../../../helpers/constants/design-system';
2022-11-09 22:57:21 +01:00
2023-04-05 18:11:10 +02:00
<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"/>
2022-11-09 22:57:21 +01:00
```
### As
Use the `as` box prop to change the element of `ButtonIcon`. Defaults to `button`.
Button `as` options:
- `button`
- `a`
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-buttonicon--as" />
2022-11-09 22:57:21 +01:00
</Canvas>
```jsx
2023-04-05 18:11:10 +02:00
import { ButtonIcon, IconName } from '../ui/component-library';
2023-02-14 18:33:04 +01:00
import { Color } from '../../../helpers/constants/design-system';
2022-11-09 22:57:21 +01:00
2023-04-05 18:11:10 +02:00
<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"/>
2022-11-09 22:57:21 +01:00
```
### Href
When an `href` prop is passed it will change the element to an anchor(`a`) tag.
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-buttonicon--href" />
2022-11-09 22:57:21 +01:00
</Canvas>
```jsx
2023-04-05 18:11:10 +02:00
import { ButtonIcon, IconName } from '../ui/component-library';
2023-02-14 18:33:04 +01:00
import { Color } from '../../../helpers/constants/design-system';
2022-11-09 22:57:21 +01:00
<ButtonIcon
href="https://metamask.io/"
target="_blank"
2023-04-05 18:11:10 +02:00
iconName={IconName.Export}
2023-02-14 18:33:04 +01:00
color={Color.primaryDefault}
2022-11-09 22:57:21 +01:00
ariaLabel="Visit MetaMask.io"
/>;
```
### Color
2023-02-14 18:33:04 +01:00
Use the `color` prop and the `Color` object to change the color of the `ButtonIcon`. Defaults to `Color.iconDefault`.
2022-11-09 22:57:21 +01:00
<Canvas>
2023-02-14 18:33:04 +01:00
<Story id="components-componentlibrary-buttonicon--color-story" />
2022-11-09 22:57:21 +01:00
</Canvas>
```jsx
2023-04-05 18:11:10 +02:00
import { ButtonIcon, IconName } from '../ui/component-library';
2023-02-14 18:33:04 +01:00
import { Color } from '../../../helpers/constants/design-system';
2022-11-09 22:57:21 +01:00
<ButtonIcon
2023-04-05 18:11:10 +02:00
iconName={IconName.Export}
2023-02-14 18:33:04 +01:00
color={Color.primaryDefault}
2022-11-09 22:57:21 +01:00
ariaLabel="Visit MetaMask.io"
/>;
```
### Disabled
Use the boolean `disabled` prop to disable button
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-buttonicon--disabled" />
2022-11-09 22:57:21 +01:00
</Canvas>
```jsx
import { ButtonIcon } from '../ui/component-library';
2023-04-05 18:11:10 +02:00
<ButtonIcon iconName={IconName.Close} disabled ariaLabel="Close" />;
2022-11-09 22:57:21 +01:00
```