Skip to content

Commit 7ec0223

Browse files
committed
feat: 增加子节点展开相关参数expandAll、expandable、onExpand
1 parent 0cf161a commit 7ec0223

File tree

14 files changed

+200
-37
lines changed

14 files changed

+200
-37
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# 1.0.0 (2021-09-08)
2+
3+
### Features
4+
5+
- 上传版本 1.0.0 ([63060e9](https://github.com/twp0217/react-org-chart/commit/63060e98760e60fd185933b0728beb07544a74e9))

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ export default () => {
5252

5353
### OrgChartProps
5454

55-
| 名称 | 类型 | 默认值 | 说明 |
56-
| ---------- | --------------------------------------------------------------------- | ------ | -------------- |
57-
| data | NodeDataType | - | 数据 |
58-
| className | string | - | 类名 |
59-
| style | React.CSSProperties | - | 样式 |
60-
| renderNode | (node: NodeDataType, originNode: React.ReactNode) => React.ReactNode; | - | 自定义渲染节点 |
61-
| onClick | (node: NodeDataType) => void | - | 点击事件 |
55+
| 名称 | 类型 | 默认值 | 说明 |
56+
| ---------- | --------------------------------------------------------------------- | ------ | --------------------- |
57+
| data | NodeDataType | - | 数据 |
58+
| className | string | - | 类名 |
59+
| style | React.CSSProperties | - | 样式 |
60+
| expandAll | boolean | true | 是否展开所有子节点 |
61+
| expandable | boolean | false | 是否允许子节点展开 |
62+
| renderNode | (node: NodeDataType, originNode: React.ReactNode) => React.ReactNode; | - | 自定义渲染节点 |
63+
| onExpand | (expanded: boolean, node: NodeDataType) => void | - | 展开/收起节点时的回调 |
64+
| onClick | (node: NodeDataType) => void | - | 点击节点时的回调 |

docs/demo/basic.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
order: 1
3+
---
4+
15
## basic
26

37
<code src="../examples/basic.tsx" />

docs/demo/event.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
order: 9
3+
---
4+
15
## event
26

37
<code src="../examples/event.tsx" />

docs/demo/expandAll.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
order: 3
3+
---
4+
5+
## expandAll
6+
7+
<code src="../examples/expandAll.tsx" />

docs/demo/expandable.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
order: 2
3+
---
4+
5+
## expandable
6+
7+
<code src="../examples/expandable.tsx" />

docs/examples/event.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ export default () => {
88
console.log('onClick', node);
99
};
1010

11+
const onExpand = (expanded: boolean, node: NodeDataType) => {
12+
console.log('onExpand', expanded, node);
13+
};
14+
1115
return (
1216
<div
1317
style={{
1418
overflow: 'auto',
1519
textAlign: 'center',
1620
}}
1721
>
18-
<OrgChart data={data} onClick={onClick} />
22+
<OrgChart data={data} expandable onClick={onClick} onExpand={onExpand} />
1923
</div>
2024
);
2125
};

docs/examples/expandAll.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React from 'react';
2+
import OrgChart, { NodeDataType } from '@twp0217/react-org-chart';
3+
4+
export default () => {
5+
const data: NodeDataType = {
6+
key: 0,
7+
label: '科技有限公司',
8+
children: [
9+
{
10+
key: 1,
11+
label: '研发部',
12+
children: [
13+
{ key: 11, label: '开发-前端' },
14+
{ key: 12, label: '开发-后端' },
15+
{ key: 13, label: 'UI设计' },
16+
{ key: 14, label: '产品经理' },
17+
],
18+
},
19+
{
20+
key: 2,
21+
label: '销售部',
22+
children: [
23+
{ key: 21, label: '销售一部' },
24+
{ key: 22, label: '销售二部' },
25+
],
26+
},
27+
{ key: 3, label: '财务部' },
28+
{ key: 4, label: '人事部' },
29+
],
30+
};
31+
32+
const [expandAll, setExpandAll] = React.useState<boolean>(false);
33+
34+
return (
35+
<div>
36+
<div>
37+
<button onClick={() => setExpandAll(!expandAll)}>
38+
{expandAll ? '收起' : '展开'}
39+
</button>
40+
</div>
41+
<br />
42+
<OrgChart expandable data={data} expandAll={expandAll} />
43+
</div>
44+
);
45+
};

docs/examples/expandable.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
import OrgChart from '@twp0217/react-org-chart';
3+
4+
export default () => {
5+
const data = require('./data.json');
6+
7+
return <OrgChart data={data} expandable />;
8+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@twp0217/react-org-chart",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"scripts": {
55
"start": "dumi dev",
66
"docs:build": "dumi build",

0 commit comments

Comments
 (0)