1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00
metamask-extension/ui/components/component-library/avatar-icon
George Marshall d2779c9ef1
Updating Avatar components to forward refs (#18678)
Co-authored-by: Brad Decker <bhdecker84@gmail.com>
2023-04-21 08:51:34 -07:00
..
__snapshots__ update text component color to use box color (#18246) 2023-03-23 13:00:37 -07:00
avatar-icon.constants.js feature: migrate design-system.ts (#17518) 2023-02-02 20:15:26 +00:00
avatar-icon.js Updating Avatar components to forward refs (#18678) 2023-04-21 08:51:34 -07:00
avatar-icon.stories.js Updating icon imports to TS version in component-library folder (#18449) 2023-04-05 09:11:10 -07:00
avatar-icon.test.js Updating Avatar components to forward refs (#18678) 2023-04-21 08:51:34 -07:00
index.js add avatar icon component (#16755) 2022-12-08 10:25:19 -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 { AvatarBase } from '../';
import { AvatarIcon } from './avatar-icon';

# AvatarIcon

The `AvatarIcon` is an avatar component that renders only an icon inside and is built off the [AvatarBase](/docs/components-componentlibrary-avatarbase--default-story)) component

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

## Props

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

<ArgsTable of={AvatarIcon} />

`AvatarIcon` accepts all [AvatarBase](/docs/components-componentlibrary-avatarbase--default-story))
component props

<ArgsTable of={AvatarBase} />

### Size

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

Optional: `AVATAR_ICON_SIZES` from `./ui/components/component-library` object can be used instead of `Size`

Possible sizes include:

- `Size.XS` 16px
- `Size.SM` 24px
- `Size.MD` 32px
- `Size.LG` 40px
- `Size.XL` 48px

Defaults to `Size.MD`

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

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

    <AvatarIcon {...args} size={Size.XS} />
    <AvatarIcon {...args} size={Size.SM} />
    <AvatarIcon {...args} size={Size.MD} />
    <AvatarIcon {...args} size={Size.LG} />
    <AvatarIcon {...args} size={Size.XL} />
```

### 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-avataricon--icon-name-story" />
</Canvas>

```jsx
import { AvatarIcon, IconName } from '../ui/component-library';

<AvatarIcon iconName={IconName.SwapHorizontal} />
<AvatarIcon iconName={IconName.Confirmation} />
<AvatarIcon iconName={IconName.Info} />
<AvatarIcon iconName={IconName.Warning} />
<AvatarIcon iconName={IconName.Danger} />
```

### Color and Background Color

Use the `color` and `backgroundColor` props with the `IconColor` and `BackgroundColor` object from `./ui/helpers/constants/design-system.js` to change the icon color and background color of `AvatarIcon`

`color` default: `IconColor.primaryDefault`
`backgroundColor` default: `BackgroundColor.primaryMuted`

<Canvas>
  <Story id="components-componentlibrary-avataricon--color-and-background-color" />
</Canvas>

```jsx
import { BackgroundColor, IconColor } from '../../../helpers/constants/design-system';
import { AvatarIcon } from '../ui/component-library';

<AvatarIcon color={IconColor.primaryDefault} backgroundColor={BackgroundColor.primaryMuted} />
<AvatarIcon color={IconColor.primaryInverse} backgroundColor={BackgroundColor.primaryDefault} />
<AvatarIcon color={IconColor.successDefault} backgroundColor={BackgroundColor.successMuted} />
<AvatarIcon color={IconColor.infoDefault} backgroundColor={BackgroundColor.infoMuted} />
<AvatarIcon color={IconColor.warningDefault} backgroundColor={BackgroundColor.warningMuted} />
<AvatarIcon color={IconColor.errorDefault} backgroundColor={BackgroundColor.errorMuted} />
```