ant-design/components/tree/demo/customized-icon.md

40 lines
733 B
Markdown
Raw Normal View History

---
order: 6
title:
zh-CN: 自定义图标
en-US: Customize Icon
---
## zh-CN
可以针对不同的节点定制图标。
## en-US
You can customize icons for different nodes.
2019-05-07 14:57:32 +08:00
```jsx
import { Tree, Icon } from 'antd';
2018-06-27 15:55:04 +08:00
2018-11-28 15:00:03 +08:00
const { TreeNode } = Tree;
ReactDOM.render(
<Tree
showIcon
defaultExpandAll
defaultSelectedKeys={['0-0-0']}
2018-12-12 20:25:55 +08:00
switcherIcon={<Icon type="down" />}
2018-11-28 15:00:03 +08:00
>
<TreeNode icon={<Icon type="smile-o" />} title="parent 1" key="0-0">
<TreeNode icon={<Icon type="meh-o" />} title="leaf" key="0-0-0" />
<TreeNode
2019-05-07 14:57:32 +08:00
icon={({ selected }) => <Icon type={selected ? 'frown' : 'frown-o'} />}
2018-11-28 15:00:03 +08:00
title="leaf"
key="0-0-1"
/>
</TreeNode>
</Tree>,
2019-05-07 14:57:32 +08:00
mountNode,
2018-11-28 15:00:03 +08:00
);
2019-05-07 14:57:32 +08:00
```