UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

127 lines (102 loc) 3.93 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/inherits"; import _createSuper from "@babel/runtime/helpers/createSuper"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import React, { Component, isValidElement } from 'react'; import get from 'lodash/get'; function isInvalidRenderCellText(text) { return text && ! /*#__PURE__*/isValidElement(text) && Object.prototype.toString.call(text) === '[object Object]'; } var TableCell = /*#__PURE__*/function (_Component) { _inherits(TableCell, _Component); var _super = _createSuper(TableCell); function TableCell() { var _this; _classCallCheck(this, TableCell); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _defineProperty(_assertThisInitialized(_this), "handleClick", function (e) { var _this$props = _this.props, record = _this$props.record, onCellClick = _this$props.column.onCellClick; if (onCellClick) { onCellClick(record, e); } }); return _this; } _createClass(TableCell, [{ key: "render", value: function render() { var _this$props2 = this.props, record = _this$props2.record, indentSize = _this$props2.indentSize, prefixCls = _this$props2.prefixCls, indent = _this$props2.indent, index = _this$props2.index, expandIcon = _this$props2.expandIcon, column = _this$props2.column, BodyCell = _this$props2.component; var dataIndex = column.dataIndex, render = column.render, _column$className = column.className, className = _column$className === void 0 ? '' : _column$className; // We should return undefined if no dataIndex is specified, but in order to // be compatible with object-path's behavior, we return the record object instead. var text; if (typeof dataIndex === 'number') { text = get(record, dataIndex); } else if (!dataIndex || dataIndex.length === 0) { text = record; } else { text = get(record, dataIndex); } var tdProps = { tabIndex: -1 }; var colSpan; var rowSpan; if (render) { text = render(text, record, index); if (isInvalidRenderCellText(text)) { tdProps = text.props || tdProps; colSpan = tdProps.colSpan; rowSpan = tdProps.rowSpan; text = text.children; } } if (column.onCell) { tdProps = _objectSpread(_objectSpread({}, tdProps), column.onCell(record, column)); } if (isInvalidRenderCellText(text)) { text = null; } var indentText = expandIcon ? /*#__PURE__*/React.createElement("span", { style: { paddingLeft: "".concat(indentSize * indent, "px") }, className: "".concat(prefixCls, "-indent indent-level-").concat(indent) }) : null; if (rowSpan === 0 || colSpan === 0) { return null; } if (column.align) { tdProps.style = _objectSpread(_objectSpread({}, tdProps.style), {}, { textAlign: column.align }); } return /*#__PURE__*/React.createElement(BodyCell, _extends({ className: className, onClick: this.handleClick }, tdProps), indentText, expandIcon, text); } }]); return TableCell; }(Component); export { TableCell as default }; //# sourceMappingURL=TableCell.js.map