--- localeCode: en-US order: 12 category: Basic title: Icon subTitle: Icon icon: doc-icons brief: Semantic vector graphics. --- ## Icon List ```icon ``` ## Demos ### How to import ```jsx import import Icon, { IconHome } from '@douyinfe/semi-icons'; ``` ### Basic usage Import icons from the `@douyinfe/semi-icons` package ```jsx live=true import React from 'react'; import { IconHome } from '@douyinfe/semi-icons'; () => ; ``` ### Rotate & Spin Introduce icons from the `@douyinfe/semi-icons` package, with its own size, rotation, and spin functions ```jsx live=true import React from 'react'; import { IconHome, IconEmoji, IconSpin } from '@douyinfe/semi-icons'; () => (
); ``` ### Size > You can change the `font-size` to change the icon size > The Icon component encapsulates the size attribute, which makes it easier to define the icon size. It supports `extra-small` (8x8), `small` (12x12), `default` (16x16), `large` (20x20), `extra-large `(24x24), When size is specified as `inherit`, the icon size inherits the current context font size. ```jsx live=true import React from 'react'; import { IconSearch, IconHelpCircle, IconAlertCircle, IconMinusCircle, IconPlusCircle, IconPlus, IconRefresh } from '@douyinfe/semi-icons'; () => { // eslint-disable-next-line react/jsx-key const types = [, , , , , , ]; const sizes = ['extra-small', 'small', 'default', 'large', 'extra-large']; let icons = types.map((type, i) => { return
{sizes.map(size => React.cloneElement(type, {size, key:size}))}
; }); return icons; }; ``` ### Color The icon will automatically inherit the `color` property of the external container CSS You can also modify the color of the icon by setting style props to the Icon. ```jsx live=true import React from 'react'; import { IconLikeHeart, IconFlag, IconLock, IconUnlock } from '@douyinfe/semi-icons'; () => (

); ``` ### Custom icon You can use custom icons to pass in Icon components Icon component supports size, rotate, spinning and other attributes ```jsx live=true import React from 'react'; import { Icon } from '@douyinfe/semi-ui'; () => { function CustomIcon(){ return ; } return (
} /> } rotate={180} />
); }; ``` ### Use svgr to convert svg files into ReactComponent If the icons provided by Semi are not enough to meet business needs, you can also introduce custom icons through @svgr/webpack and use them as React components ``` // webpack.config.js { test: /\.svg$/, use: ['@svgr/webpack'], } import { Icon } from '@douyinfe/semi-ui'; import StarIcon from './star.svg'; } /> ``` ## API reference ### Icon | Properties | Illustrate | Type | Default | |-------|-------------|-----------------|--------| | className | class name | string | none | | onClick | Callback event of clicking the icon | (e: Event) => void | None | | onMouseDown | The callback event of mouse button press >=v1.21 | (e: Event) => void | None | | onMouseEnter | Callback event of entering icon | (e: Event) => void | None | | onMouseLeave | Callback event of leaving icon | (e: Event) => void | None | | onMouseMove | Callback event of moving the mouse >=v1.21 | (e: Event) => void | None | | onMouseUp | Callback event when the mouse button is raised >=v1.21 | (e: Event) => void | None | | rotate | degree of rotation | number | | | size | Size, supports `inherit`, `extra-small`, `small`, `default`, `large`, `extra-large` | string | `default` | | spin | spin animation | boolean | | | style | Icon style | CSSProperties | None | | svg | Icon content | ReactNode | None | ## Accessibility ### ARIA - The Icon component role is img, and its aria-label defaults to the component's file name ```jsx live=true import React from 'react'; import { IconHome } from '@douyinfe/semi-icons'; () => ; ``` - The svg element inside Icon is a decorative element, and aria-hidden is set by default to prevent it from being read by screen readers