2022-09-20 19:15:14 +02:00
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import { Icon } from './icon';
# Icon
2023-04-04 18:48:04 +02:00
The `Icon` component in conjunction with `IconName` can be used for all icons in the extension
2022-09-20 19:15:14 +02:00
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-icon--default-story" />
2022-09-20 19:15:14 +02:00
</Canvas>
## Props
2023-01-20 20:27:46 +01:00
The `Icon` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) component props
2022-09-20 19:15:14 +02:00
<ArgsTable of={Icon} />
### Name
2023-04-04 18:48:04 +02:00
Use the `name` prop and the `IconName` enum to change the icon.
2022-09-20 19:15:14 +02: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-23 18:58:43 +01:00
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-icon--name" />
2022-11-23 18:58:43 +01:00
</Canvas>
2022-09-20 19:15:14 +02:00
```jsx
2023-04-04 18:48:04 +02:00
import { Icon, IconName } from '../../component-library';
2022-09-20 19:15:14 +02:00
2023-04-04 18:48:04 +02:00
<Icon name={IconName.AddSquare} />
<Icon name={IconName.Bank} />
<Icon name={IconName.Calculator} />
<Icon name={IconName.Coin} />
2022-11-23 18:58:43 +01:00
// etc...
2022-09-20 19:15:14 +02:00
```
### Size
2023-04-04 18:48:04 +02:00
Use the `size` prop and the `IconSize` enum to change the size of `Icon`. Defaults to `IconSize.Sm`
2022-09-20 19:15:14 +02:00
Possible sizes include:
2023-04-04 18:48:04 +02:00
- `IconSize.Xs` 12px
- `IconSize.Sm` 16px
- `IconSize.Md` 20px
- `IconSize.Lg` 24px
- `IconSize.Xl` 32px
- `IconSize.Inherit` inherits the font-size from parent element. This is useful for inline icons in text.
2022-09-20 19:15:14 +02:00
<Canvas>
2023-02-14 18:33:04 +01:00
<Story id="components-componentlibrary-icon--size-story" />
2022-09-20 19:15:14 +02:00
</Canvas>
```jsx
2023-04-04 18:48:04 +02:00
import { TextVariant } from '../../../helpers/constants/design-system';
import { Icon, IconName, IconSize, Text } from '../../component-library';
<Icon name={IconName.AddSquare} size={IconSize.Xs} />
<Icon name={IconName.AddSquare} size={IconSize.Sm} />
<Icon name={IconName.AddSquare} size={IconSize.Md} />
<Icon name={IconName.AddSquare} size={IconSize.Lg} />
<Icon name={IconName.AddSquare} size={IconSize.Xl} />
2023-02-02 21:15:26 +01:00
<Text as="p" variant={TextVariant.bodySm}>
2023-04-04 18:48:04 +02:00
<Icon size={IconSize.Inherit} /> inherits the
2022-09-29 17:33:34 +02:00
font-size of the parent element.
</Text>
2022-09-20 19:15:14 +02:00
```
### Color
2023-04-04 18:48:04 +02:00
Use the `color` prop and the `IconColor` enum from `./ui/helpers/constants/design-system.js` to change the color of `Icon`. Defaults to `IconColor.inherit` which will use the text color of the parent element. This is useful for inline icons.
2022-09-20 19:15:14 +02:00
<Canvas>
2023-02-14 18:33:04 +01:00
<Story id="components-componentlibrary-icon--color-story" />
2022-09-20 19:15:14 +02:00
</Canvas>
```jsx
2023-02-02 21:15:26 +01:00
import { IconColor } from '../../../helpers/constants/design-system';
2023-04-04 18:48:04 +02:00
import { Icon, IconName } from '../../component-library';
<Icon name={IconName.AddSquare} color={IconColor.inherit} />
<Icon name={IconName.AddSquare} color={IconColor.iconDefault} />
<Icon name={IconName.AddSquare} color={IconColor.iconAlternative} />
<Icon name={IconName.AddSquare} color={IconColor.iconMuted} />
<Icon name={IconName.AddSquare} color={IconColor.overlayInverse} />
<Icon name={IconName.AddSquare} color={IconColor.primaryDefault} />
<Icon name={IconName.AddSquare} color={IconColor.primaryInverse} />
<Icon name={IconName.AddSquare} color={IconColor.errorDefault} />
<Icon name={IconName.AddSquare} color={IconColor.errorInverse} />
<Icon name={IconName.AddSquare} color={IconColor.successDefault} />
<Icon name={IconName.AddSquare} color={IconColor.successInverse} />
<Icon name={IconName.AddSquare} color={IconColor.warningDefault} />
<Icon name={IconName.AddSquare} color={IconColor.warningInverse} />
<Icon name={IconName.AddSquare} color={IconColor.infoDefault} />
<Icon name={IconName.AddSquare} color={IconColor.infoInverse} />
2023-02-07 19:07:50 +01:00
```
### Layout & Spacing
The `Icon` component accepts all [Box](/docs/components-ui-box--default-story#props) component props including `marginTop`, `marginRight`, ` marginBottom`, `marginLeft` which you can use directly to adjust the space between icons and other components like `Text`
Some examples of `Icon` with `Text` using [Box](/docs/components-ui-box--default-story#props) component props
<Canvas>
<Story id="components-componentlibrary-icon--layout-and-spacing" />
</Canvas>
```jsx
import {
AlignItems,
2023-05-25 22:53:31 +02:00
Display,
2023-02-07 19:07:50 +01:00
IconColor,
2023-05-25 22:53:31 +02:00
FlexDirection,
2023-02-07 19:07:50 +01:00
BorderColor,
BorderRadius,
} from '../../../helpers/constants/design-system';
import Box from '../../ui/box/box';
2023-04-04 18:48:04 +02:00
import { IconName, Icon, IconSize, Text, Label } from '../../component-library';
2023-02-07 19:07:50 +01:00
2023-05-25 22:53:31 +02:00
<Box display={Display.Flex} flexDirection={FlexDirection.Column} gap={4}>
<Box display={Display.Flex} alignItems={AlignItems.center}>
2023-02-07 19:07:50 +01:00
<Icon
2023-04-04 18:48:04 +02:00
name={IconName.Check}
2023-02-07 19:07:50 +01:00
color={IconColor.successDefault}
marginRight={1}
/>
<Text>Always allow you to opt-out via Settings</Text>
</Box>
<Box
as="button"
2023-05-25 22:53:31 +02:00
display={Display.Flex}
2023-02-07 19:07:50 +01:00
alignItems={AlignItems.center}
borderRadius={BorderRadius.pill}
backgroundColor={BackgroundColor.primaryMuted}
marginRight="auto"
>
<Text color={Color.primaryDefault}>
0x79fAaFe7B6D5DB5D8c63FE88DFF0AF1Fe53358db
</Text>
<Icon
2023-04-04 18:48:04 +02:00
name={IconName.Copy}
2023-02-07 19:07:50 +01:00
color={IconColor.primaryDefault}
marginLeft={1}
/>
</Box>
<Box
as="button"
2023-05-25 22:53:31 +02:00
display={Display.Flex}
2023-02-07 19:07:50 +01:00
alignItems={AlignItems.center}
padding={4}
borderColor={BorderColor.borderMuted}
backgroundColor={BackgroundColor.backgroundDefault}
>
2023-04-04 18:48:04 +02:00
<Icon name={IconName.Add} color={IconColor.iconDefault} marginRight={2} />
2023-02-07 19:07:50 +01:00
<Text>Create account</Text>
</Box>
2023-02-22 23:42:50 +01:00
<Label>
Custom spending cap{' '}
2023-04-04 18:48:04 +02:00
<Icon name={IconName.Info} size={IconSize.Inherit} marginLeft={1} />
2023-02-22 23:42:50 +01:00
</Label>
<div>
<Text>
<Icon
2023-04-04 18:48:04 +02:00
name={IconName.Warning}
size={IconSize.Inherit}
2023-02-22 23:42:50 +01:00
marginLeft={1}
color={IconColor.warningDefault}
/>{' '}
Warning
</Text>
</div>
2023-02-07 19:07:50 +01:00
</Box>;
2022-09-20 19:15:14 +02:00
```
### Adding a new icon
2023-04-04 18:48:04 +02:00
In order to ensure that a new icon is added correctly, there are a few steps that need to be followed:
2022-09-20 19:15:14 +02:00
#### Step 1.
Optimize the svg using [Fontastic](https://fontastic.me/). This will remove any unnecessary code from the svg. Your svg should only contain a single path.
2023-04-04 18:48:04 +02:00
Example of a correctly optimized svg `add-square-filled.svg`:
2022-09-20 19:15:14 +02:00
2023-04-04 18:48:04 +02:00
```xml
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<path d="m337 51l-171 0c-75 0-119 45-119 119l0 172c0 74 44 119 119 119l171 0c75 0 119-45 119-119l0-172c1-74-44-119-119-119z m-3 220l-67 0 0 67c0 8-7 15-15 15-9 0-16-7-16-15l0-67-66 0c-9 0-16-7-16-15 0-8 7-15 16-15l66 0 0-67c0-8 7-15 16-15 8 0 15 7 15 15l0 67 67 0c8 0 15 7 15 15 0 8-7 15-15 15z" />
2022-09-20 19:15:14 +02:00
</svg>
```
If your svg **does not** contain a single path, you will need to get a designer to join all paths and outline strokes into a single path.
#### Step 2.
2023-01-24 18:39:46 +01:00
Add your optimized svg file to to `app/images/icons`
2022-09-20 19:15:14 +02:00
#### Step 3.
2023-04-04 18:48:04 +02:00
Add your icon to the `IconName` enum in `./ui/components/ui/icon/icon.types.ts`
2022-09-20 19:15:14 +02:00
If you have any questions please reach out to the design system team in the [#metamask-design-system](https://consensys.slack.com/archives/C0354T27M5M) channel on slack.