mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-23 23:18:36 +08:00
e7aa014c31
* docs: init * chore: all types * docs: faq * chore: fix lint
74 lines
1.4 KiB
TypeScript
74 lines
1.4 KiB
TypeScript
import React from 'react';
|
|
import { DownOutlined } from '@ant-design/icons';
|
|
import { Tree } from 'antd';
|
|
import type { TreeDataNode, TreeProps } from 'antd';
|
|
|
|
const treeData: TreeDataNode[] = [
|
|
{
|
|
title: 'parent 1',
|
|
key: '0-0',
|
|
children: [
|
|
{
|
|
title: 'parent 1-0',
|
|
key: '0-0-0',
|
|
children: [
|
|
{
|
|
title: 'leaf',
|
|
key: '0-0-0-0',
|
|
},
|
|
{
|
|
title: 'leaf',
|
|
key: '0-0-0-1',
|
|
},
|
|
{
|
|
title: 'leaf',
|
|
key: '0-0-0-2',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: 'parent 1-1',
|
|
key: '0-0-1',
|
|
children: [
|
|
{
|
|
title: 'leaf',
|
|
key: '0-0-1-0',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: 'parent 1-2',
|
|
key: '0-0-2',
|
|
children: [
|
|
{
|
|
title: 'leaf',
|
|
key: '0-0-2-0',
|
|
},
|
|
{
|
|
title: 'leaf',
|
|
key: '0-0-2-1',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
const App: React.FC = () => {
|
|
const onSelect: TreeProps['onSelect'] = (selectedKeys, info) => {
|
|
console.log('selected', selectedKeys, info);
|
|
};
|
|
|
|
return (
|
|
<Tree
|
|
showLine
|
|
switcherIcon={<DownOutlined />}
|
|
defaultExpandedKeys={['0-0-0']}
|
|
onSelect={onSelect}
|
|
treeData={treeData}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default App;
|