1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | 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; };
|
8 |
|
9 | var _react = require('react');
|
10 |
|
11 | var _react2 = _interopRequireDefault(_react);
|
12 |
|
13 | var _getLevel = require('./get-level');
|
14 |
|
15 | var _getLevel2 = _interopRequireDefault(_getLevel);
|
16 |
|
17 | var _hasChildren = require('./has-children');
|
18 |
|
19 | var _hasChildren2 = _interopRequireDefault(_hasChildren);
|
20 |
|
21 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
22 |
|
23 | 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; }
|
24 |
|
25 | var toggleChildren = function toggleChildren() {
|
26 | var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
27 | getRows = _ref.getRows,
|
28 | getShowingChildren = _ref.getShowingChildren,
|
29 | toggleShowingChildren = _ref.toggleShowingChildren,
|
30 | props = _ref.props,
|
31 | idField = _ref.idField,
|
32 | parentField = _ref.parentField;
|
33 |
|
34 | if (!getRows) {
|
35 | throw new Error('tree.toggleChildren - Missing getRows!');
|
36 | }
|
37 |
|
38 | if (!getShowingChildren) {
|
39 | throw new Error('tree.toggleChildren - Missing getShowingChildren!');
|
40 | }
|
41 |
|
42 | if (!toggleShowingChildren) {
|
43 | throw new Error('tree.toggleChildren - Missing toggleShowingChildren!');
|
44 | }
|
45 |
|
46 | var toggle = function toggle(e, index) {
|
47 | e.stopPropagation();
|
48 | e.preventDefault();
|
49 |
|
50 | toggleShowingChildren(index);
|
51 | };
|
52 |
|
53 | return function (value, extra) {
|
54 | var _ref2 = props || {},
|
55 | className = _ref2.className,
|
56 | restProps = _objectWithoutProperties(_ref2, ['className']);
|
57 |
|
58 |
|
59 | var rowData = extra.rowData;
|
60 |
|
61 | var rows = getRows();
|
62 | var showingChildren = getShowingChildren(extra);
|
63 | var index = rowData._index;
|
64 | var containsChildren = (0, _hasChildren2.default)({ index: index, idField: idField })(rows) ? 'has-children' : '';
|
65 | var level = (0, _getLevel2.default)({ index: index, parentField: parentField })(rows);
|
66 | var hasParent = level > 0 ? 'has-parent' : '';
|
67 |
|
68 | return _react2.default.createElement(
|
69 | 'div',
|
70 | _extends({
|
71 | style: { paddingLeft: level + 'em' },
|
72 | onClick: function onClick(e) {
|
73 | return toggle(e, index);
|
74 | },
|
75 | className: containsChildren + ' ' + hasParent + ' ' + (className || '')
|
76 | }, restProps),
|
77 | containsChildren && _react2.default.createElement('span', {
|
78 | className: showingChildren ? 'show-less' : 'show-more',
|
79 | onClick: function onClick(e) {
|
80 | return toggle(e, index);
|
81 | }
|
82 | }),
|
83 | value
|
84 | );
|
85 | };
|
86 | };
|
87 |
|
88 | exports.default = toggleChildren; |
\ | No newline at end of file |