1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
4 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
5 | import _inherits from 'babel-runtime/helpers/inherits';
|
6 |
|
7 | var _class, _temp2;
|
8 |
|
9 | import React from 'react';
|
10 | import PropTypes from 'prop-types';
|
11 | import { log } from '../../util';
|
12 | import Row from '../lock/row';
|
13 |
|
14 | var ExpandedRow = (_temp2 = _class = function (_React$Component) {
|
15 | _inherits(ExpandedRow, _React$Component);
|
16 |
|
17 | function ExpandedRow() {
|
18 | var _temp, _this, _ret;
|
19 |
|
20 | _classCallCheck(this, ExpandedRow);
|
21 |
|
22 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
23 | args[_key] = arguments[_key];
|
24 | }
|
25 |
|
26 | return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.getExpandedRow = function (parentKey, ref) {
|
27 | var getExpandedRowRef = _this.context.getExpandedRowRef;
|
28 |
|
29 | getExpandedRowRef && getExpandedRowRef(parentKey, ref);
|
30 | }, _temp), _possibleConstructorReturn(_this, _ret);
|
31 | }
|
32 |
|
33 | ExpandedRow.prototype.renderExpandedRow = function renderExpandedRow(record, rowIndex) {
|
34 | var _context = this.context,
|
35 | expandedRowRender = _context.expandedRowRender,
|
36 | expandedRowIndent = _context.expandedRowIndent,
|
37 | openRowKeys = _context.openRowKeys,
|
38 | lockType = _context.lockType,
|
39 | expandedIndexSimulate = _context.expandedIndexSimulate,
|
40 | expandedRowWidthEquals2Table = _context.expandedRowWidthEquals2Table;
|
41 |
|
42 | var expandedIndex = expandedIndexSimulate ? (rowIndex - 1) / 2 : rowIndex;
|
43 |
|
44 | var _props = this.props,
|
45 | columns = _props.columns,
|
46 | cellRef = _props.cellRef;
|
47 |
|
48 | var colSpan = columns.length;
|
49 | var expandedCols = columns[0] && columns[0].__colIndex || 0;
|
50 |
|
51 | if (expandedRowRender) {
|
52 | var _props2 = this.props,
|
53 | primaryKey = _props2.primaryKey,
|
54 | prefix = _props2.prefix,
|
55 | leftIndent = expandedRowIndent[0],
|
56 | rightIndent = expandedRowIndent[1],
|
57 | totalIndent = leftIndent + rightIndent,
|
58 | renderCols = function renderCols(number) {
|
59 | var start = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
60 |
|
61 | var ret = [];
|
62 |
|
63 | var _loop = function _loop(i) {
|
64 | ret.push(React.createElement(
|
65 | 'td',
|
66 | { key: i, ref: function ref(cell) {
|
67 | return cellRef(rowIndex, i + start, cell);
|
68 | } },
|
69 | '\xA0'
|
70 | ));
|
71 | };
|
72 |
|
73 | for (var i = 0; i < number; i++) {
|
74 | _loop(i);
|
75 | }
|
76 | return ret;
|
77 | };
|
78 |
|
79 | var content = void 0;
|
80 |
|
81 | if (totalIndent > colSpan && !lockType) {
|
82 | log.warning("It's not allowed expandedRowIndent is more than the number of columns.");
|
83 | }
|
84 | if (leftIndent < columns.length && lockType === 'left') {
|
85 | log.warning('expandedRowIndent left is less than the number of left lock columns.');
|
86 | }
|
87 | if (rightIndent < columns.length && lockType === 'right') {
|
88 | log.warning('expandedRowIndent right is less than the number of right lock columns.');
|
89 | }
|
90 | if (lockType) {
|
91 | return openRowKeys.indexOf(record[primaryKey]) > -1 ? React.createElement(
|
92 | 'tr',
|
93 | { className: prefix + 'table-expanded-row', key: 'expanded-' + expandedIndex },
|
94 | React.createElement(
|
95 | 'td',
|
96 | { colSpan: colSpan, ref: function ref(cell) {
|
97 | return cellRef(rowIndex, expandedCols, cell);
|
98 | } },
|
99 | '\xA0'
|
100 | )
|
101 | ) : null;
|
102 | }
|
103 |
|
104 | var expandedRowStyle = {
|
105 | position: 'sticky',
|
106 | left: 0
|
107 | };
|
108 |
|
109 | content = expandedRowRender(record, expandedIndex);
|
110 | if (!React.isValidElement(content)) {
|
111 | content = React.createElement(
|
112 | 'div',
|
113 | {
|
114 | className: prefix + 'table-cell-wrapper',
|
115 | ref: this.getExpandedRow.bind(this, record[primaryKey]),
|
116 | style: expandedRowWidthEquals2Table && expandedRowStyle
|
117 | },
|
118 | content
|
119 | );
|
120 | } else {
|
121 | content = expandedRowWidthEquals2Table ? React.createElement(
|
122 | 'div',
|
123 | {
|
124 | className: prefix + 'table-expanded-area',
|
125 | ref: this.getExpandedRow.bind(this, record[primaryKey]),
|
126 | style: expandedRowStyle
|
127 | },
|
128 | content
|
129 | ) : content;
|
130 | }
|
131 |
|
132 | var rightStart = columns.length;
|
133 | columns.forEach(function (col) {
|
134 | col.lock === 'right' && rightStart--;
|
135 | });
|
136 | return openRowKeys.indexOf(record[primaryKey]) > -1 ? React.createElement(
|
137 | 'tr',
|
138 | { className: prefix + 'table-expanded-row', key: 'expanded-' + (record[primaryKey] || expandedIndex) },
|
139 | renderCols(leftIndent),
|
140 | React.createElement(
|
141 | 'td',
|
142 | { colSpan: colSpan - totalIndent },
|
143 | content
|
144 | ),
|
145 | renderCols(rightIndent, rightStart)
|
146 | ) : null;
|
147 | } else {
|
148 | return null;
|
149 | }
|
150 | };
|
151 |
|
152 | ExpandedRow.prototype.render = function render() {
|
153 |
|
154 | var _props3 = this.props,
|
155 | record = _props3.record,
|
156 | rowIndex = _props3.rowIndex,
|
157 | columns = _props3.columns,
|
158 | others = _objectWithoutProperties(_props3, ['record', 'rowIndex', 'columns']);
|
159 |
|
160 | var expandedIndexSimulate = this.context.expandedIndexSimulate;
|
161 |
|
162 |
|
163 | if (record.__expanded) {
|
164 | return this.renderExpandedRow(record, rowIndex, columns);
|
165 | }
|
166 |
|
167 | var newRowIndex = expandedIndexSimulate ? rowIndex / 2 : rowIndex;
|
168 | return React.createElement(Row, _extends({}, others, { record: record, columns: columns, __rowIndex: rowIndex, rowIndex: newRowIndex }));
|
169 | };
|
170 |
|
171 | return ExpandedRow;
|
172 | }(React.Component), _class.propTypes = _extends({}, Row.propTypes), _class.defaultProps = _extends({}, Row.defaultProps), _class.contextTypes = {
|
173 | openRowKeys: PropTypes.array,
|
174 | expandedRowRender: PropTypes.func,
|
175 | expandedRowIndent: PropTypes.array,
|
176 | expandedIndexSimulate: PropTypes.bool,
|
177 | expandedRowWidthEquals2Table: PropTypes.bool,
|
178 | lockType: PropTypes.oneOf(['left', 'right']),
|
179 | getExpandedRowRef: PropTypes.func
|
180 | }, _temp2);
|
181 | ExpandedRow.displayName = 'ExpandedRow';
|
182 | export { ExpandedRow as default }; |
\ | No newline at end of file |