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

60 lines
985 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.
```tsx
import {
DownOutlined,
2022-05-21 22:14:15 +08:00
FrownFilled,
FrownOutlined,
MehOutlined,
2022-05-21 22:14:15 +08:00
SmileOutlined,
} from '@ant-design/icons';
2022-05-21 22:14:15 +08:00
import { Tree } from 'antd';
import type { DataNode } from 'antd/lib/tree';
2022-05-21 22:14:15 +08:00
import React from 'react';
2018-06-27 15:55:04 +08:00
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 />),
},
],
},
];
2018-11-28 15:00:03 +08:00
const App: React.FC = () => (
2018-11-28 15:00:03 +08:00
<Tree
showIcon
defaultExpandAll
defaultSelectedKeys={['0-0-0']}
switcherIcon={<DownOutlined />}
treeData={treeData}
/>
2018-11-28 15:00:03 +08:00
);
export default App;
2019-05-07 14:57:32 +08:00
```