2020-08-28 17:58:33 +08:00
# IconPark Icons
> React Icons for IconPark
## Introduction
### Features
2021-01-17 11:31:22 +08:00
* Provide more than 2000 icons
2020-08-28 17:58:33 +08:00
* Provide 4 themes:
* outline
* filled
* two-tone
* multi-color
### More
2020-09-03 21:03:21 +08:00
Please visit [IconPark Website ](http://iconpark.bytedance.com )
2020-08-28 17:58:33 +08:00
* Copy SVG
* Copy React Icon component
* Copy Vue Icon component
* Download PNG
* Download SVG
## Getting Started
### Install
2020-08-27 17:02:57 +08:00
```
npm install @icon -park/react --save
```
2020-08-28 17:58:33 +08:00
### Include Component
2020-09-29 18:29:16 +08:00
Import an icon from `@icon-park/react` at the top of a component and then use it in the render function:
2020-08-27 17:02:57 +08:00
2020-08-28 17:58:33 +08:00
```
2020-08-27 17:02:57 +08:00
import {Home} from '@icon -park/react';
// examples
< Home / >
< Home theme = "filled" / >
```
### Style Sheet
2020-08-28 17:58:33 +08:00
Import the icon style:
2020-08-27 17:02:57 +08:00
```typescript
import '@icon -park/react/styles/index.css';
```
2020-08-28 17:58:33 +08:00
Or
2020-08-27 17:02:57 +08:00
```typescript
import '@icon -park/react/styles/index.less';
```
2020-08-28 17:58:33 +08:00
### Global Config
2020-09-30 00:26:59 +08:00
You can use `IconProvider` in `@icon-park/react` to set the default config globally:
2020-08-27 17:02:57 +08:00
```typescript jsx
2020-09-30 00:26:59 +08:00
import {IconProvider, DEFAULT_ICON_CONFIGS} from '@icon -park/react'
2020-08-27 17:02:57 +08:00
import {Home} from '@icon -park/react';
const IconConfig = {...DEFAULT_ICON_CONFIGS, prefix: 'icon'}
function App() {
return (
< IconProvider value = {IconConfig} >
< Home / >
< Home theme = "filled" / >
< / IconProvider >
)
}
```
2020-08-28 17:58:33 +08:00
### Import on Demand
2020-08-27 17:02:57 +08:00
2020-08-28 17:58:33 +08:00
You can use [babel-plugin-import ](https://github.com/ant-design/babel-plugin-import ) to import icons on demand.
2020-08-27 17:02:57 +08:00
2020-08-28 17:58:33 +08:00
Set config like this:
2020-08-27 17:02:57 +08:00
```json
{
"plugins": [
[
"import",
{
"libraryName": "@icon -park/react",
"libraryDirectory": "es/icons",
2020-08-27 17:08:18 +08:00
"camel2DashComponentName": false
2020-08-27 17:02:57 +08:00
}
]
]
}
```
2020-08-28 17:58:33 +08:00
### Icon Component
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.
2020-08-27 17:02:57 +08:00
2020-08-28 17:58:33 +08:00
Usage:
2020-08-27 17:02:57 +08:00
```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" / >
2021-02-15 20:21:59 +08:00
< Icon type = "AddText" theme = "filled" / >
< Icon type = "add-text" / >
2020-08-27 17:02:57 +08:00
< / Fragment >
)
}
```
2020-08-28 17:58:33 +08:00
You can do this when you are not sure whether the `type` property is legal:
2020-08-27 17:02:57 +08:00
```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 (
2020-08-28 17:58:33 +08:00
< span > Not Exists< / span >
2020-08-27 17:02:57 +08:00
);
}
return (
< Fragment >
< Icon type = {type} theme = "filled" / >
< Icon type = "People" theme = "filled" / >
< Icon type = "Switch" / >
< / Fragment >
)
}
```
2021-01-17 11:31:22 +08:00
### Embed IconPark in your project
If you need to use additional information such as icon name, author, category, label and creation time, you can use the `icons.json` file located in the root directory of each NPM.
2020-08-27 17:02:57 +08:00
2020-08-28 17:58:33 +08:00
## Props
2020-08-27 17:02:57 +08:00
2020-08-28 17:58:33 +08:00
| prop | description | type | default | note |
2020-08-27 17:02:57 +08:00
| ---------- | --- | --- | --- | --- |
2020-08-28 17:58:33 +08:00
| theme | Theme of the icons. | 'outline' & #124 ; 'filled' & #124 ; 'two-tone' & #124 ; 'multi-color' | 'outline' |
| size | The width/height of the icon | number & #124 ; string | '1em' |
| spin | Rotate icon with animation | boolean | false |
| fill | Colors of theme | string & #124 ; string[] | 'currentColor' |
| strokeLinecap | the stroke-linecap prop of svg element | 'butt' & #124 ; 'round' & #124 ; 'square' | 'round' |
| strokeLinejoin | the stroke-linejoin prop of svg element | 'miter' & #124 ; 'round' & #124 ; '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:
2020-08-27 17:02:57 +08:00
* className
* style
* onClick
* ...