mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-16 01:41:02 +08:00
60 lines
984 B
Markdown
60 lines
984 B
Markdown
---
|
|
order: 6
|
|
title:
|
|
zh-CN: 自定义图标
|
|
en-US: Customize Icon
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
可以针对不同的节点定制图标。
|
|
|
|
## en-US
|
|
|
|
You can customize icons for different nodes.
|
|
|
|
```tsx
|
|
import {
|
|
DownOutlined,
|
|
FrownFilled,
|
|
FrownOutlined,
|
|
MehOutlined,
|
|
SmileOutlined,
|
|
} from '@ant-design/icons';
|
|
import { Tree } from 'antd';
|
|
import type { DataNode } from 'antd/es/tree';
|
|
import React from 'react';
|
|
|
|
const treeData: DataNode[] = [
|
|
{
|
|
title: 'parent 1',
|
|
key: '0-0',
|
|
icon: <SmileOutlined />,
|
|
children: [
|
|
{
|
|
title: 'leaf',
|
|
key: '0-0-0',
|
|
icon: <MehOutlined />,
|
|
},
|
|
{
|
|
title: 'leaf',
|
|
key: '0-0-1',
|
|
icon: ({ selected }) => (selected ? <FrownFilled /> : <FrownOutlined />),
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
const App: React.FC = () => (
|
|
<Tree
|
|
showIcon
|
|
defaultExpandAll
|
|
defaultSelectedKeys={['0-0-0']}
|
|
switcherIcon={<DownOutlined />}
|
|
treeData={treeData}
|
|
/>
|
|
);
|
|
|
|
export default App;
|
|
```
|