|
| 1 | +# react-org-chart - 组织结构图 |
| 2 | + |
| 3 | +## 使用 |
| 4 | + |
| 5 | +```typescript |
| 6 | +import React from 'react'; |
| 7 | +import OrgChart, { NodeDataType } from '@twp0217/react-org-chart'; |
| 8 | + |
| 9 | +export default () => { |
| 10 | + const data: NodeDataType = { |
| 11 | + key: 0, |
| 12 | + label: '科技有限公司', |
| 13 | + children: [ |
| 14 | + { |
| 15 | + key: 1, |
| 16 | + label: '研发部', |
| 17 | + children: [ |
| 18 | + { key: 11, label: '开发-前端' }, |
| 19 | + { key: 12, label: '开发-后端' }, |
| 20 | + { key: 13, label: 'UI设计' }, |
| 21 | + { key: 14, label: '产品经理' }, |
| 22 | + ], |
| 23 | + }, |
| 24 | + { |
| 25 | + key: 2, |
| 26 | + label: '销售部', |
| 27 | + children: [ |
| 28 | + { key: 21, label: '销售一部' }, |
| 29 | + { key: 22, label: '销售二部' }, |
| 30 | + ], |
| 31 | + }, |
| 32 | + { key: 3, label: '财务部' }, |
| 33 | + { key: 4, label: '人事部' }, |
| 34 | + ], |
| 35 | + }; |
| 36 | + |
| 37 | + return <OrgChart data={data} />; |
| 38 | +}; |
| 39 | +``` |
| 40 | + |
| 41 | +## API |
| 42 | + |
| 43 | +### NodeDataType |
| 44 | + |
| 45 | +| 名称 | 类型 | 默认值 | 说明 | |
| 46 | +| --------- | ------------------- | ------ | ---------- | |
| 47 | +| key | string \| number | - | key | |
| 48 | +| label | number | - | label | |
| 49 | +| children | NodeDataType[] | - | 子节点集合 | |
| 50 | +| className | string | - | 类名 | |
| 51 | +| style | React.CSSProperties | - | 样式 | |
| 52 | + |
| 53 | +### OrgChartProps |
| 54 | + |
| 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 | - | 点击事件 | |
0 commit comments