2018-07-19 19:24:19 +08:00
|
|
|
---
|
|
|
|
order: 1
|
|
|
|
title:
|
|
|
|
zh-CN: 自定义图标
|
|
|
|
en-US: Custom Icon
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
2018-08-16 11:41:37 +08:00
|
|
|
利用 `Icon` 组件封装一个可复用的自定义图标。可以将 `svg` 图标的路径信息作为 `children` 传入至组件,也可以进一步通过 `component` 属性传入一个组件来渲染最终的图标,以满足特定的需求。这个例子中使用了 `@svgr/webpack` 来将 `svg` 图标转化为 `React` 组件。
|
2018-07-19 19:24:19 +08:00
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Todo, Please replace me.
|
|
|
|
|
|
|
|
````jsx
|
|
|
|
import { Icon } from 'antd';
|
2018-08-15 17:21:02 +08:00
|
|
|
import HeartSvg from './assets/heart.svg';
|
|
|
|
import AntDesignSvg from './assets/ant-design.svg';
|
|
|
|
// use webpack loader `@svgr/webpack`,
|
|
|
|
// which convert `*.svg` file into react component.
|
2018-07-19 19:24:19 +08:00
|
|
|
|
2018-08-15 17:21:02 +08:00
|
|
|
const HeartIcon = props => (
|
2018-08-16 11:41:37 +08:00
|
|
|
<Icon component={HeartSvg} {...props} />
|
2018-08-15 17:21:02 +08:00
|
|
|
);
|
2018-07-19 21:07:33 +08:00
|
|
|
|
2018-08-15 17:21:02 +08:00
|
|
|
const AntDesignIcon = props => (
|
2018-08-16 11:41:37 +08:00
|
|
|
<Icon component={AntDesignSvg} {...props} />
|
2018-08-15 17:21:02 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
ReactDOM.render(
|
|
|
|
<div className="custom-icons-list">
|
|
|
|
<HeartIcon style={{ color: 'hotpink' }} />
|
|
|
|
<AntDesignIcon style={{ fontSize: '32px' }} />
|
2018-07-19 19:24:19 +08:00
|
|
|
</div>,
|
|
|
|
mountNode
|
|
|
|
);
|
|
|
|
````
|
2018-08-14 17:17:51 +08:00
|
|
|
|
|
|
|
```css
|
2018-08-15 17:21:02 +08:00
|
|
|
.custom-icons-list > .anticon {
|
2018-08-14 17:17:51 +08:00
|
|
|
margin-right: 6px;
|
|
|
|
}
|
|
|
|
```
|