1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 02:10:12 +01:00
metamask-extension/ui/components/component-library/avatar-icon
Binij Shrestha 6e5ab2a945
Migrate AvatarIcon (#19107)
Migrate AvatarIcon to TS


---------

Co-authored-by: georgewrmarshall <george.marshall@consensys.net>
2023-07-26 14:18:36 -07:00
..
__snapshots__ Migrate AvatarIcon (#19107) 2023-07-26 14:18:36 -07:00
avatar-icon.stories.tsx Migrate AvatarIcon (#19107) 2023-07-26 14:18:36 -07:00
avatar-icon.test.tsx Migrate AvatarIcon (#19107) 2023-07-26 14:18:36 -07:00
avatar-icon.tsx Migrate AvatarIcon (#19107) 2023-07-26 14:18:36 -07:00
avatar-icon.types.ts Migrate AvatarIcon (#19107) 2023-07-26 14:18:36 -07:00
index.ts Migrate AvatarIcon (#19107) 2023-07-26 14:18:36 -07:00
README.mdx Migrate AvatarIcon (#19107) 2023-07-26 14:18:36 -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-componentlibrary-box--docs#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 `AvatarIconSize` enum to change the size of `AvatarIcon`

Possible sizes include:

- `AvatarIconSize.Xs` 16px
- `AvatarIconSize.Sm` 24px
- `AvatarIconSize.Md` 32px
- `AvatarIconSize.Lg` 40px
- `AvatarIconSize.Xl` 48px

Defaults to `AvatarIconSize.Md`

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

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

    <AvatarIcon {...args} size={AvatarIconSize.Xs} />
    <AvatarIcon {...args} size={AvatarIconSize.Sm} />
    <AvatarIcon {...args} size={AvatarIconSize.Md} />
    <AvatarIcon {...args} size={AvatarIconSize.Lg} />
    <AvatarIcon {...args} size={AvatarIconSize.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} />
```