2017-03-21 09:41:02 +08:00
|
|
|
---
|
|
|
|
order: 5
|
|
|
|
title:
|
|
|
|
zh-CN: 连接线
|
2019-12-05 17:48:47 +08:00
|
|
|
en-US: Tree with line
|
2017-03-21 09:41:02 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
2019-12-11 18:22:06 +08:00
|
|
|
节点之间带连接线的树,常用于文件目录结构展示。使用 `showLine` 开启,可以用 `switcherIcon` 修改默认图标。
|
2017-03-21 09:41:02 +08:00
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2019-12-11 18:22:06 +08:00
|
|
|
Tree with connected line between nodes, turn on by `showLine`, customize the preseted icon by `switcherIcon`.
|
2017-03-21 09:41:02 +08:00
|
|
|
|
2019-08-12 13:22:36 +08:00
|
|
|
```tsx
|
2020-01-22 12:11:49 +08:00
|
|
|
import React, { useState } from 'react';
|
2019-12-25 19:09:17 +08:00
|
|
|
import { Tree, Switch } from 'antd';
|
|
|
|
import { CarryOutOutlined, FormOutlined } from '@ant-design/icons';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-08-12 13:22:36 +08:00
|
|
|
const treeData = [
|
|
|
|
{
|
|
|
|
title: 'parent 1',
|
|
|
|
key: '0-0',
|
2019-12-25 19:09:17 +08:00
|
|
|
icon: <CarryOutOutlined />,
|
2019-08-12 13:22:36 +08:00
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: 'parent 1-0',
|
|
|
|
key: '0-0-0',
|
2019-12-25 19:09:17 +08:00
|
|
|
icon: <CarryOutOutlined />,
|
2019-08-12 13:22:36 +08:00
|
|
|
children: [
|
2019-12-25 19:09:17 +08:00
|
|
|
{ title: 'leaf', key: '0-0-0-0', icon: <CarryOutOutlined /> },
|
2020-10-26 23:13:52 +08:00
|
|
|
{
|
|
|
|
title: (
|
|
|
|
<>
|
|
|
|
<div>multiple line title</div>
|
|
|
|
<div>multiple line title</div>
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
key: '0-0-0-1',
|
|
|
|
icon: <CarryOutOutlined />,
|
|
|
|
},
|
2019-12-25 19:09:17 +08:00
|
|
|
{ title: 'leaf', key: '0-0-0-2', icon: <CarryOutOutlined /> },
|
2019-08-12 13:22:36 +08:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'parent 1-1',
|
|
|
|
key: '0-0-1',
|
2019-12-25 19:09:17 +08:00
|
|
|
icon: <CarryOutOutlined />,
|
|
|
|
children: [{ title: 'leaf', key: '0-0-1-0', icon: <CarryOutOutlined /> }],
|
2019-08-12 13:22:36 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'parent 1-2',
|
|
|
|
key: '0-0-2',
|
2019-12-25 19:09:17 +08:00
|
|
|
icon: <CarryOutOutlined />,
|
|
|
|
children: [
|
|
|
|
{ title: 'leaf', key: '0-0-2-0', icon: <CarryOutOutlined /> },
|
|
|
|
{
|
|
|
|
title: 'leaf',
|
|
|
|
key: '0-0-2-1',
|
|
|
|
icon: <CarryOutOutlined />,
|
|
|
|
switcherIcon: <FormOutlined />,
|
|
|
|
},
|
|
|
|
],
|
2019-08-12 13:22:36 +08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-08-10 10:48:11 +08:00
|
|
|
{
|
|
|
|
title: 'parent 2',
|
|
|
|
key: '0-1',
|
|
|
|
icon: <CarryOutOutlined />,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: 'parent 2-0',
|
|
|
|
key: '0-1-0',
|
|
|
|
icon: <CarryOutOutlined />,
|
|
|
|
children: [
|
|
|
|
{ title: 'leaf', key: '0-1-0-0', icon: <CarryOutOutlined /> },
|
|
|
|
{ title: 'leaf', key: '0-1-0-1', icon: <CarryOutOutlined /> },
|
|
|
|
],
|
|
|
|
},
|
2020-10-21 11:06:07 +08:00
|
|
|
],
|
2020-08-10 10:48:11 +08:00
|
|
|
},
|
2019-08-12 13:22:36 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
const Demo: React.FC<{}> = () => {
|
2020-12-17 15:09:18 +08:00
|
|
|
const [showLine, setShowLine] = useState<boolean | { showLeafIcon: boolean }>(true);
|
|
|
|
const [showIcon, setShowIcon] = useState<boolean>(false);
|
|
|
|
const [showLeafIcon, setShowLeafIcon] = useState<boolean>(true);
|
2019-12-11 18:22:06 +08:00
|
|
|
|
2020-12-17 15:09:18 +08:00
|
|
|
const onSelect = (selectedKeys: React.Key[], info: any) => {
|
2017-03-21 09:41:02 +08:00
|
|
|
console.log('selected', selectedKeys, info);
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2020-12-17 15:09:18 +08:00
|
|
|
const onSetLeafIcon = (checked: boolean) => {
|
2020-06-29 11:04:58 +08:00
|
|
|
setShowLeafIcon(checked);
|
|
|
|
setShowLine({ showLeafIcon: checked });
|
|
|
|
};
|
|
|
|
|
2020-12-17 15:09:18 +08:00
|
|
|
const onSetShowLine = (checked: boolean) => {
|
2021-02-23 10:45:11 +08:00
|
|
|
setShowLine(checked ? { showLeafIcon } : false);
|
2020-06-29 11:04:58 +08:00
|
|
|
};
|
|
|
|
|
2019-12-25 19:09:17 +08:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div style={{ marginBottom: 16 }}>
|
2020-12-17 15:09:18 +08:00
|
|
|
showLine: <Switch checked={!!showLine} onChange={onSetShowLine} />
|
2019-12-25 19:09:17 +08:00
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
showIcon: <Switch checked={showIcon} onChange={setShowIcon} />
|
2020-06-29 11:04:58 +08:00
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
showLeafIcon: <Switch checked={showLeafIcon} onChange={onSetLeafIcon} />
|
2019-12-11 18:22:06 +08:00
|
|
|
</div>
|
2019-12-25 19:09:17 +08:00
|
|
|
<Tree
|
|
|
|
showLine={showLine}
|
|
|
|
showIcon={showIcon}
|
|
|
|
defaultExpandedKeys={['0-0-0']}
|
|
|
|
onSelect={onSelect}
|
|
|
|
treeData={treeData}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
2019-08-12 13:22:36 +08:00
|
|
|
};
|
2017-03-21 09:41:02 +08:00
|
|
|
|
2022-04-15 16:20:56 +08:00
|
|
|
export default Demo;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|