forked from nater1067/react-orgchart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.jsx
76 lines (66 loc) · 2.07 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const React = require('react')
const OrgChart = ({tree, NodeComponent}) => {
const renderChildren = (node) => {
const hasSiblingRight = (childIndex) => {
return (node.children || []).length > (childIndex + 1)
};
const hasSiblingLeft = (childIndex) => {
return childIndex > 0
};
const nodeLineBelow = (
<td colSpan={(node.children || []).length * 2} className="nodeGroupCellLines">
<table className="nodeLineTable">
<tbody>
<tr>
<td colSpan={2} className="nodeLineCell nodeGroupLineVerticalMiddle" />
<td colSpan={2} className="nodeLineCell" />
</tr>
</tbody>
</table>
</td>
);
const childrenLinesAbove = (node.children || []).map((child, childIndex) => (
<td colSpan="2" className="nodeGroupCellLines" key={childIndex}>
<table className="nodeLineTable">
<tbody>
<tr>
<td colSpan={2} className={ "nodeLineCell nodeGroupLineVerticalMiddle" + (hasSiblingLeft(childIndex) ? ' nodeLineBorderTop' : '') } />
<td colSpan={2} className={ "nodeLineCell" + (hasSiblingRight(childIndex) ? " nodeLineBorderTop" : "") } />
</tr>
</tbody>
</table>
</td>
));
const children = (node.children || []).map((child, childIndex) => (
<td colSpan="2" className="nodeGroupCell" key={childIndex}>
{ renderChildren(child) }
</td>
));
return (
<table className="orgNodeChildGroup">
<tbody>
<tr>
<td className="nodeCell" colSpan={(node.children || []).length * 2}>
<NodeComponent node={node}/>
</td>
</tr>
<tr>
{(node.children || []).length > 0 && nodeLineBelow}
</tr>
<tr>
{childrenLinesAbove}
</tr>
<tr>
{children}
</tr>
</tbody>
</table>
)
};
return (
<div className="reactOrgChart">
{renderChildren(tree)}
</div>
)
};
module.exports = OrgChart;