-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathindex.js
113 lines (100 loc) · 3.48 KB
/
index.js
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"use strict";
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
var React = require('react');
var OrgChart = function OrgChart(_ref) {
var tree = _ref.tree,
NodeComponent = _ref.NodeComponent,
props = _objectWithoutProperties(_ref, ["tree", "NodeComponent"]);
var renderChildren = function renderChildren(node) {
var hasSiblingRight = function hasSiblingRight(childIndex) {
return (node.children || []).length > childIndex + 1;
};
var hasSiblingLeft = function hasSiblingLeft(childIndex) {
return childIndex > 0;
};
var nodeLineBelow = React.createElement(
"td",
{ colSpan: (node.children || []).length * 2, className: "nodeGroupCellLines" },
React.createElement(
"table",
{ className: "nodeLineTable" },
React.createElement(
"tbody",
null,
React.createElement(
"tr",
null,
React.createElement("td", { colSpan: 2, className: "nodeLineCell nodeGroupLineVerticalMiddle" }),
React.createElement("td", { colSpan: 2, className: "nodeLineCell" })
)
)
)
);
var childrenLinesAbove = (node.children || []).map(function (child, childIndex) {
return React.createElement(
"td",
{ colSpan: "2", className: "nodeGroupCellLines", key: childIndex },
React.createElement(
"table",
{ className: "nodeLineTable" },
React.createElement(
"tbody",
null,
React.createElement(
"tr",
null,
React.createElement("td", { colSpan: 2, className: "nodeLineCell nodeGroupLineVerticalMiddle" + (hasSiblingLeft(childIndex) ? ' nodeLineBorderTop' : '') }),
React.createElement("td", { colSpan: 2, className: "nodeLineCell" + (hasSiblingRight(childIndex) ? " nodeLineBorderTop" : "") })
)
)
)
);
});
var children = (node.children || []).map(function (child, childIndex) {
return React.createElement(
"td",
{ colSpan: "2", className: "nodeGroupCell", key: childIndex },
renderChildren(child)
);
});
return React.createElement(
"table",
{ className: "orgNodeChildGroup" },
React.createElement(
"tbody",
null,
React.createElement(
"tr",
null,
React.createElement(
"td",
{ className: "nodeCell", colSpan: (node.children || []).length * 2 },
React.createElement(NodeComponent, _extends({}, props, { node: node }))
)
),
React.createElement(
"tr",
null,
(node.children || []).length > 0 && nodeLineBelow
),
React.createElement(
"tr",
null,
childrenLinesAbove
),
React.createElement(
"tr",
null,
children
)
)
);
};
return React.createElement(
"div",
{ className: "reactOrgChart" },
renderChildren(tree)
);
};
module.exports = OrgChart;