UNPKG

choerodon-ui

Version:

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

174 lines (142 loc) 5.08 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 _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _createSuper(Derived) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } return function () { var Super = _getPrototypeOf(Derived), result; if (isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } import React, { Component, isValidElement } from 'react'; import PropTypes from 'prop-types'; import get from 'lodash/get'; 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: "isInvalidRenderCellText", value: function isInvalidRenderCellText(text) { return text && !isValidElement(text) && Object.prototype.toString.call(text) === '[object Object]'; } }, { 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 (this.isInvalidRenderCellText(text)) { tdProps = text.props || tdProps; colSpan = tdProps.colSpan; rowSpan = tdProps.rowSpan; text = text.children; } } if (column.onCell) { tdProps = _objectSpread({}, tdProps, {}, column.onCell(record)); } if (this.isInvalidRenderCellText(text)) { text = null; } var indentText = expandIcon ? 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 = { textAlign: column.align }; } return React.createElement(BodyCell, _extends({ className: className, onClick: this.handleClick }, tdProps), indentText, expandIcon, text); } }]); return TableCell; }(Component); _defineProperty(TableCell, "propTypes", { record: PropTypes.object, prefixCls: PropTypes.string, index: PropTypes.number, indent: PropTypes.number, indentSize: PropTypes.number, column: PropTypes.object, expandIcon: PropTypes.node, component: PropTypes.any }); export { TableCell as default }; //# sourceMappingURL=TableCell.js.map