React Icons for IconPark
Please visit IconPark Website
npm install @icon-park/react --save
Import an icon from @icon-park/react
at the top of a component and then use it in the render function:
import {Home} from '@icon-park/react';
// examples
<Home/>
<Home theme="filled"/>
Import the icon style:
import '@icon-park/react/styles/index.css';
Or
import '@icon-park/react/styles/index.less';
You can use IconProvider
in @icon-park/react
to set the default config globally:
```typescript jsx import {IconProvider, DEFAULT_ICON_CONFIGS} from â@icon-park/reactâ import {Home} from â@icon-park/reactâ;
const IconConfig = {âŚDEFAULT_ICON_CONFIGS, prefix: âiconâ}
function App() {
return (
<IconProvider value={IconConfig}>
<Home/>
<Home theme="filled"/>
</IconProvider>
) } ```
You can use babel-plugin-import to import icons on demand.
Set config like this:
{
"plugins": [
[
"import",
{
"libraryName": "@icon-park/react",
"libraryDirectory": "es/icons",
"camel2DashComponentName": false
}
]
]
}
We recommend loading icons on demand, because this can greatly reduce the volume of compiled codeă However, in some scenarios similar to remote loading menus, direct reference to all icons can reduce the development cost.
Usage:
```typescript jsx import Icon, {IconType} from â@icon-park/react/es/allâ; import React, {Fragment} from âreactâ;
export function Demo(props: {type: IconType}): JSX.Element {
const {type} = props;
return (
<Fragment>
<Icon type={type} theme="filled" />
<Icon type="People" theme="filled" />
<Icon type="Switch" />
</Fragment>
) } ``` You can do this when you are not sure whether the `type` property is legal:
```typescript jsx import Icon, {ALL_ICON_KEYS, IconType} from â@icon-park/react/es/allâ; import React, {Fragment} from âreactâ;
export function Demo(props: {type: IconType}): JSX.Element {
const {type} = props;
if(ALL_ICON_KEYS.indexOf(type) < 0) {
return (
<span>Not Exists</span>
);
}
return (
<Fragment>
<Icon type={type} theme="filled" />
<Icon type="People" theme="filled" />
<Icon type="Switch" />
</Fragment>
) } ```
prop | description | type | default | note |
---|---|---|---|---|
theme | Theme of the icons. | âoutlineâ | âfilledâ | âtwo-toneâ | âmulti-colorâ | âoutlineâ | Â |
size | The width/height of the icon | number | string | â1emâ | Â |
spin | Rotate icon with animation | boolean | false | Â |
fill | Colors of theme | string | string[] | âcurrentColorâ | Â |
strokeLinecap | the stroke-linecap prop of svg element | âbuttâ | âroundâ | âsquareâ | âroundâ | Â |
strokeLinejoin | the stroke-linejoin prop of svg element | âmiterâ | âroundâ | âbevelâ | âroundâ | Â |
strokeWidth | the stroke-width prop of svg element | number | 4 | Â |
Other props
You can use all props which are defined in HTMLAttributes<HTMLSpanElement>>
, such as: