1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
3 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
4 | import _inherits from 'babel-runtime/helpers/inherits';
|
5 |
|
6 | var _class, _temp2;
|
7 |
|
8 | import React from 'react';
|
9 | import PropTypes from 'prop-types';
|
10 | import Icon from '../../icon';
|
11 | import { KEYCODE } from '../../util';
|
12 | import CellComponent from '../base/cell';
|
13 |
|
14 | var TreeCell = (_temp2 = _class = function (_React$Component) {
|
15 | _inherits(TreeCell, _React$Component);
|
16 |
|
17 | function TreeCell() {
|
18 | var _temp, _this, _ret;
|
19 |
|
20 | _classCallCheck(this, TreeCell);
|
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.onTreeNodeClick = function (record, e) {
|
27 | e.stopPropagation();
|
28 | _this.context.onTreeNodeClick(record);
|
29 | }, _this.expandedKeydown = function (record, e) {
|
30 | e.preventDefault();
|
31 | e.stopPropagation();
|
32 |
|
33 | if (e.keyCode === KEYCODE.ENTER) {
|
34 | _this.onTreeNodeClick(record, e);
|
35 | }
|
36 | }, _temp), _possibleConstructorReturn(_this, _ret);
|
37 | }
|
38 |
|
39 | TreeCell.prototype.render = function render() {
|
40 | var _this2 = this;
|
41 |
|
42 | var _props = this.props,
|
43 | colIndex = _props.colIndex,
|
44 | record = _props.record,
|
45 | prefix = _props.prefix,
|
46 | primaryKey = _props.primaryKey,
|
47 | locale = _props.locale,
|
48 | rtl = _props.rtl,
|
49 | children = _props.children;
|
50 | var _context = this.context,
|
51 | openRowKeys = _context.openTreeRowKeys,
|
52 | indent = _context.indent,
|
53 | isTree = _context.isTree,
|
54 | rowSelection = _context.rowSelection;
|
55 |
|
56 | var treeArrowNodeIndex = rowSelection ? 1 : 0;
|
57 | var firstCellStyle = void 0,
|
58 | treeArrowNode = void 0;
|
59 | if (colIndex === treeArrowNodeIndex) {
|
60 | var treeArrowType = void 0;
|
61 | if (isTree) {
|
62 | var _firstCellStyle;
|
63 |
|
64 | var paddingType = rtl ? 'paddingRight' : 'paddingLeft';
|
65 | firstCellStyle = (_firstCellStyle = {}, _firstCellStyle[paddingType] = indent * (record.__level + 1), _firstCellStyle);
|
66 | treeArrowNode = React.createElement(Icon, {
|
67 | size: 'xs',
|
68 | rtl: rtl,
|
69 | className: prefix + 'table-tree-placeholder'
|
70 | });
|
71 | if (record.children && record.children.length) {
|
72 | var hasExpanded = openRowKeys.indexOf(record[primaryKey]) > -1;
|
73 |
|
74 | treeArrowType = hasExpanded ? 'arrow-down' : 'arrow-right';
|
75 |
|
76 | treeArrowNode = React.createElement(Icon, {
|
77 | className: prefix + 'table-tree-arrow',
|
78 | type: treeArrowType,
|
79 | size: 'xs',
|
80 | rtl: rtl,
|
81 | onClick: function onClick(e) {
|
82 | return _this2.onTreeNodeClick(record, e);
|
83 | },
|
84 | onKeyDown: function onKeyDown(e) {
|
85 | return _this2.expandedKeydown(record, e);
|
86 | },
|
87 | role: 'button',
|
88 | tabIndex: '0',
|
89 | 'aria-expanded': hasExpanded,
|
90 | 'aria-label': hasExpanded ? locale.expanded : locale.folded
|
91 | });
|
92 | }
|
93 | }
|
94 | }
|
95 | return React.createElement(
|
96 | CellComponent,
|
97 | _extends({}, this.props, {
|
98 | innerStyle: firstCellStyle,
|
99 | isIconLeft: !!treeArrowNode
|
100 | }),
|
101 | children,
|
102 | treeArrowNode
|
103 | );
|
104 | };
|
105 |
|
106 | return TreeCell;
|
107 | }(React.Component), _class.propTypes = _extends({
|
108 | indent: PropTypes.number,
|
109 | locale: PropTypes.object
|
110 | }, CellComponent.propTypes), _class.defaultProps = _extends({}, CellComponent.defaultProps, {
|
111 | component: 'td',
|
112 | indent: 20
|
113 | }), _class.contextTypes = {
|
114 | openTreeRowKeys: PropTypes.array,
|
115 | indent: PropTypes.number,
|
116 | onTreeNodeClick: PropTypes.func,
|
117 | isTree: PropTypes.bool,
|
118 | rowSelection: PropTypes.object
|
119 | }, _temp2);
|
120 | TreeCell.displayName = 'TreeCell';
|
121 | export { TreeCell as default }; |
\ | No newline at end of file |