2017-03-21 09:41:02 +08:00
|
|
|
---
|
|
|
|
order: 6
|
|
|
|
title:
|
|
|
|
zh-CN: 自定义图标
|
|
|
|
en-US: Customize Icon
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
2018-04-04 16:39:50 +08:00
|
|
|
可以针对不同的节点定制图标。
|
2017-03-21 09:41:02 +08:00
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2018-04-04 16:39:50 +08:00
|
|
|
You can customize icons for different nodes.
|
2017-03-21 09:41:02 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
|
|
|
import React from 'react';
|
2019-08-13 14:07:17 +08:00
|
|
|
import { Tree } from 'antd';
|
2019-11-28 12:34:33 +08:00
|
|
|
import {
|
|
|
|
DownOutlined,
|
|
|
|
FrownOutlined,
|
|
|
|
SmileOutlined,
|
|
|
|
MehOutlined,
|
|
|
|
FrownFilled,
|
|
|
|
} from '@ant-design/icons';
|
2022-05-19 09:46:26 +08:00
|
|
|
import type { DataNode } from 'antd/lib/tree';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const treeData: DataNode[] = [
|
2019-08-12 13:22:36 +08:00
|
|
|
{
|
|
|
|
title: 'parent 1',
|
|
|
|
key: '0-0',
|
2019-11-28 12:34:33 +08:00
|
|
|
icon: <SmileOutlined />,
|
2019-08-12 13:22:36 +08:00
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: 'leaf',
|
|
|
|
key: '0-0-0',
|
2019-11-28 12:34:33 +08:00
|
|
|
icon: <MehOutlined />,
|
2019-08-12 13:22:36 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'leaf',
|
|
|
|
key: '0-0-1',
|
2019-11-28 12:34:33 +08:00
|
|
|
icon: ({ selected }) => (selected ? <FrownFilled /> : <FrownOutlined />),
|
2019-08-12 13:22:36 +08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
2018-11-28 15:00:03 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => (
|
2018-11-28 15:00:03 +08:00
|
|
|
<Tree
|
|
|
|
showIcon
|
|
|
|
defaultExpandAll
|
|
|
|
defaultSelectedKeys={['0-0-0']}
|
2019-11-28 12:34:33 +08:00
|
|
|
switcherIcon={<DownOutlined />}
|
2019-08-12 13:22:36 +08:00
|
|
|
treeData={treeData}
|
2022-04-03 23:27:45 +08:00
|
|
|
/>
|
2018-11-28 15:00:03 +08:00
|
|
|
);
|
2022-05-19 09:46:26 +08:00
|
|
|
|
|
|
|
export default App;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|