README.md 3.7 KB
Newer Older
1
2
3
4
5
6
# IconPark Icons
> React Icons for IconPark

## Introduction

### Features
7
* Provide more than 1200 icons
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
* Provide 4 themes:
    * outline
    * filled
    * two-tone
    * multi-color

### More
Please visit [IconPark Website]((http://iconpark.bytedance.com))
* Copy SVG
* Copy React Icon component
* Copy Vue Icon component
* Download PNG
* Download SVG

## Getting Started
### Install
24
25
26
27
28

```
npm install @icon-park/react --save
```

29
30
### Include Component
Import a icon from `@icon-park/react`at the top of a component and then use it in the render function:
31

32
```
33
34
35
36
37
38
39
40
import {Home} from '@icon-park/react';

// examples
<Home/>
<Home theme="filled"/>
```

### Style Sheet
41
Import the icon style:
42
43
44
```typescript
import '@icon-park/react/styles/index.css';
```
45
Or
46
47
48
49
50

```typescript
import '@icon-park/react/styles/index.less';
```

51
52
### Global Config
You can use `IconProvider` in `@icon-park/react/es/runtime` to set the default config globally:
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

```typescript jsx
import {IconProvider, DEFAULT_ICON_CONFIGS} from '@icon-park/react/es/runtime'
import {Home} from '@icon-park/react';

const IconConfig = {...DEFAULT_ICON_CONFIGS, prefix: 'icon'}

function App() {

    return (
        <IconProvider value={IconConfig}>
            <Home/>
            <Home theme="filled"/>
        </IconProvider>
    )
}
```

71
### Import on Demand
72

73
You can use [babel-plugin-import](https://github.com/ant-design/babel-plugin-import) to import icons on demand.
74

75
Set config like this:
76
77
78
79
80
81
82
83
```json
{
    "plugins": [
        [
            "import",
            {
                "libraryName": "@icon-park/react",
                "libraryDirectory": "es/icons",
84
                "camel2DashComponentName": false 
85
86
87
88
89
90
            }
        ]
    ]
}
```

91
92
93
### 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.
94

95
Usage:
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

```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>
    )
}
```
114
You can do this when you are not sure whether the `type` property is legal:
115
116
117
118
119
120
121
122
123
124
125

```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 (
126
            <span>Not Exists</span>
127
128
129
130
131
132
133
134
135
136
137
138
139
        );
    }

    return (
        <Fragment>
            <Icon type={type} theme="filled" />
            <Icon type="People" theme="filled" />
            <Icon type="Switch" />
        </Fragment>
    )
}
```

140
## Props
141

142
|    prop	 | description  | type  | default | note |
143
| ---------- | --- | --- | --- | --- |
144
145
146
147
148
149
150
151
152
153
154
| 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:
155
156
157
158
* className
* style
* onClick
* ...