1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/components/component-library/avatar-icon
George Marshall 3117890b30
AvatarBase font-size logic (#18203)
* Updating AvatarBase to use Text component instead of Box and adding font size logic based on avatar size

* Updating snaps
2023-03-17 10:06:59 -07:00
..
__snapshots__ AvatarBase font-size logic (#18203) 2023-03-17 10:06:59 -07:00
avatar-icon.constants.js feature: migrate design-system.ts (#17518) 2023-02-02 20:15:26 +00:00
avatar-icon.js Box types update (#18160) 2023-03-16 13:18:00 -07:00
avatar-icon.stories.js fix broken stories and readme from TS update (#17703) 2023-02-14 11:33:04 -06:00
avatar-icon.test.js AvatarBase font-size logic (#18203) 2023-03-17 10:06:59 -07:00
index.js
README.mdx fix broken stories and readme from TS update (#17703) 2023-02-14 11:33:04 -06: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, ICON_NAMES } 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 `ICON_NAMES` object 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" />
</Canvas>

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

<AvatarIcon iconName={ICON_NAMES.SWAP_HORIZONTAL} />
<AvatarIcon iconName={ICON_NAMES.CONFIRMATION} />
<AvatarIcon iconName={ICON_NAMES.INFO} />
<AvatarIcon iconName={ICON_NAMES.WARNING} />
<AvatarIcon iconName={ICON_NAMES.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} />
```