Icon
Use the <Icon>
component to easily render <svg>
icons.
Avoid passing
onClick
handlers to theIcon
component. If you need a clickable icon, use IconButton instead.
Import
Usage
Use an icon by passing the name
props. This name must match an icon key in
theme.icons
. By default, the icon inherits the fontSize and color of it's
parent.
Editable Example
All Icons
Here's a list of the default icons included in Sajari UI. Hover the icon to see their respective name
.
medium
large
small
🚨 Resizing
While it's possible to set the size
prop and resize an icon, this is not recommended due to rendering issues, often resulting in half pixels, etc. Where possible, omit the size
prop altogether and add an icon from Nucleo in the appropriate size. If you must resize an icon, try to do so at 0.5x, 2x or 3x the original size - e.g. xl
for the default icons (16px) icons and lg
for small icons (12px). Here's the size
prop mapping:
Value | Pixels | Name Prefix |
---|---|---|
sm | 12 | small |
md | 16 | - |
lg | 24 | large |
xl | 32 | xl |
2xl | 48 | 2xl |
3xl | 64 | 3xl |
Adding icons
Icons should be sourced from our chosen icon set, Nucleo. The default icon size is 16px and in glyph style. The process is:
- Find an icon in the Nucleo app you want.
- Export it to
/src/assets/icons
in the package. - Make sure it's named correctly. Often the icons come out of Nucleo with funky names that make no sense. Name it appropriately, using kebab case and remembering to add the correct prefix in the table above for it's size.
- Run
yarn build:icons
in the root of the project. This will compress the SVG, extract theviewBox
,width
andheight
prop and add them tocomponents/Icon/icons.ts
. - Your new icon will be available for the
name
prop using the filename of the icon.
Props
Icon component composes Box
so you can pass all Box
props.
Name | Type | Default | Description |
---|---|---|---|
name (required) | string | The name of the icon. | |
size | sm , md , lg , xl , 2xl , 3xl | The size of the icon. The default is to render the icon at 100% of original size. | |
color | BoxProps['textColor'] | The color of the icon. Shorthand for textColor . By default it will inherit currentColor . | |
focusable | boolean | false | Denotes that the icon is not an interative element, and only used for presentation. |
role | presentation , img | presentation | The html role of the icon. |