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, _temp;
|
8 |
|
9 | import React from 'react';
|
10 | import PropTypes from 'prop-types';
|
11 | import classnames from 'classnames';
|
12 | import { obj, pickAttrs } from '../../util';
|
13 |
|
14 | var Cell = (_temp = _class = function (_React$Component) {
|
15 | _inherits(Cell, _React$Component);
|
16 |
|
17 | function Cell() {
|
18 | _classCallCheck(this, Cell);
|
19 |
|
20 | return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
|
21 | }
|
22 |
|
23 | Cell.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
|
24 | if (nextProps.pure) {
|
25 | var isEqual = obj.shallowEqual(this.props, nextProps);
|
26 | return !isEqual;
|
27 | }
|
28 | return true;
|
29 | };
|
30 |
|
31 | Cell.prototype.render = function render() {
|
32 | var _classnames;
|
33 |
|
34 |
|
35 | var _props = this.props,
|
36 | prefix = _props.prefix,
|
37 | className = _props.className,
|
38 | cell = _props.cell,
|
39 | value = _props.value,
|
40 | resizable = _props.resizable,
|
41 | asyncResizable = _props.asyncResizable,
|
42 | colIndex = _props.colIndex,
|
43 | rowIndex = _props.rowIndex,
|
44 | __colIndex = _props.__colIndex,
|
45 | record = _props.record,
|
46 | context = _props.context,
|
47 | align = _props.align,
|
48 | _props$style = _props.style,
|
49 | style = _props$style === undefined ? {} : _props$style,
|
50 | Tag = _props.component,
|
51 | children = _props.children,
|
52 | title = _props.title,
|
53 | width = _props.width,
|
54 | innerStyle = _props.innerStyle,
|
55 | primaryKey = _props.primaryKey,
|
56 | __normalized = _props.__normalized,
|
57 | filterMode = _props.filterMode,
|
58 | filterMenuProps = _props.filterMenuProps,
|
59 | filterProps = _props.filterProps,
|
60 | filters = _props.filters,
|
61 | sortable = _props.sortable,
|
62 | sortDirections = _props.sortDirections,
|
63 | lock = _props.lock,
|
64 | pure = _props.pure,
|
65 | locale = _props.locale,
|
66 | expandedIndexSimulate = _props.expandedIndexSimulate,
|
67 | rtl = _props.rtl,
|
68 | isIconLeft = _props.isIconLeft,
|
69 | type = _props.type,
|
70 | htmlTitle = _props.htmlTitle,
|
71 | wordBreak = _props.wordBreak,
|
72 | others = _objectWithoutProperties(_props, ['prefix', 'className', 'cell', 'value', 'resizable', 'asyncResizable', 'colIndex', 'rowIndex', '__colIndex', 'record', 'context', 'align', 'style', 'component', 'children', 'title', 'width', 'innerStyle', 'primaryKey', '__normalized', 'filterMode', 'filterMenuProps', 'filterProps', 'filters', 'sortable', 'sortDirections', 'lock', 'pure', 'locale', 'expandedIndexSimulate', 'rtl', 'isIconLeft', 'type', 'htmlTitle', 'wordBreak']);
|
73 |
|
74 | var tagStyle = _extends({}, style);
|
75 | var cellProps = { value: value, index: rowIndex, record: record, context: context };
|
76 | var content = cell;
|
77 | if (React.isValidElement(content)) {
|
78 | content = React.cloneElement(content, cellProps);
|
79 | } else if (typeof content === 'function') {
|
80 | content = content(value, rowIndex, record, context);
|
81 | }
|
82 | if (align) {
|
83 | tagStyle.textAlign = align;
|
84 | if (rtl) {
|
85 | tagStyle.textAlign = align === 'left' ? 'right' : align === 'right' ? 'left' : align;
|
86 | }
|
87 | }
|
88 | var cls = classnames((_classnames = {}, _classnames[prefix + 'table-cell'] = true, _classnames[prefix + 'table-word-break-' + wordBreak] = !!wordBreak, _classnames[className] = className, _classnames));
|
89 |
|
90 | return React.createElement(
|
91 | Tag,
|
92 | _extends({}, pickAttrs(others), { className: cls, style: tagStyle, role: 'gridcell' }),
|
93 | React.createElement(
|
94 | 'div',
|
95 | {
|
96 | className: prefix + 'table-cell-wrapper',
|
97 | ref: this.props.getCellDomRef,
|
98 | style: innerStyle,
|
99 | title: htmlTitle,
|
100 | 'data-next-table-col': __colIndex,
|
101 | 'data-next-table-row': rowIndex
|
102 | },
|
103 | isIconLeft ? children : content,
|
104 | isIconLeft ? content : children
|
105 | )
|
106 | );
|
107 | };
|
108 |
|
109 | return Cell;
|
110 | }(React.Component), _class.propTypes = {
|
111 | prefix: PropTypes.string,
|
112 | pure: PropTypes.bool,
|
113 | primaryKey: PropTypes.oneOfType([PropTypes.symbol, PropTypes.string]),
|
114 | className: PropTypes.string,
|
115 | record: PropTypes.any,
|
116 | value: PropTypes.any,
|
117 | isIconLeft: PropTypes.bool,
|
118 | colIndex: PropTypes.number,
|
119 | rowIndex: PropTypes.number,
|
120 |
|
121 | __colIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
122 | title: PropTypes.any,
|
123 | width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
124 | context: PropTypes.any,
|
125 | cell: PropTypes.oneOfType([PropTypes.element, PropTypes.node, PropTypes.func]),
|
126 | align: PropTypes.oneOf(['left', 'center', 'right']),
|
127 | component: PropTypes.oneOf(['td', 'th', 'div']),
|
128 | children: PropTypes.any,
|
129 | style: PropTypes.object,
|
130 | innerStyle: PropTypes.object,
|
131 | filterMode: PropTypes.oneOf(['single', 'multiple']),
|
132 | filterMenuProps: PropTypes.object,
|
133 | filterProps: PropTypes.object,
|
134 | filters: PropTypes.array,
|
135 | sortable: PropTypes.bool,
|
136 | sortDirections: PropTypes.arrayOf(PropTypes.oneOf(['desc', 'asc', 'default'])),
|
137 | lock: PropTypes.any,
|
138 | type: PropTypes.oneOf(['header', 'body']),
|
139 | resizable: PropTypes.bool,
|
140 | asyncResizable: PropTypes.bool,
|
141 | __normalized: PropTypes.bool
|
142 | }, _class.defaultProps = {
|
143 | component: 'td',
|
144 | type: 'body',
|
145 | isIconLeft: false,
|
146 | cell: function cell(value) {
|
147 | return value;
|
148 | },
|
149 | prefix: 'next-'
|
150 | }, _temp);
|
151 | Cell.displayName = 'Cell';
|
152 | export { Cell as default }; |
\ | No newline at end of file |