UNPKG

choerodon-ui

Version:

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

196 lines (167 loc) 6.57 kB
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 } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'mini-store'; import ExpandIcon from './ExpandIcon'; var ExpandableRow = /*#__PURE__*/ function (_Component) { _inherits(ExpandableRow, _Component); var _super = _createSuper(ExpandableRow); function ExpandableRow() { var _this; _classCallCheck(this, ExpandableRow); 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), "hasExpandIcon", function (columnIndex) { var expandRowByClick = _this.props.expandRowByClick; return !_this.expandIconAsCell && !expandRowByClick && columnIndex === _this.expandIconColumnIndex; }); _defineProperty(_assertThisInitialized(_this), "handleExpandChange", function (record, event) { var _this$props = _this.props, onExpandedChange = _this$props.onExpandedChange, expanded = _this$props.expanded, rowKey = _this$props.rowKey; if (_this.expandable) { onExpandedChange(!expanded, record, event, rowKey); } }); _defineProperty(_assertThisInitialized(_this), "handleRowClick", function (record, index, event) { var _this$props2 = _this.props, expandRowByClick = _this$props2.expandRowByClick, onRowClick = _this$props2.onRowClick; if (expandRowByClick) { _this.handleExpandChange(record, event); } if (onRowClick) { onRowClick(record, index, event); } }); _defineProperty(_assertThisInitialized(_this), "renderExpandIcon", function () { var _this$props3 = _this.props, prefixCls = _this$props3.prefixCls, expanded = _this$props3.expanded, record = _this$props3.record, needIndentSpaced = _this$props3.needIndentSpaced; return React.createElement(ExpandIcon, { expandable: _this.expandable, prefixCls: prefixCls, onExpand: _this.handleExpandChange, needIndentSpaced: needIndentSpaced, expanded: expanded, record: record }); }); _defineProperty(_assertThisInitialized(_this), "renderExpandIconCell", function (cells) { if (!_this.expandIconAsCell) { return; } var prefixCls = _this.props.prefixCls; cells.push(React.createElement("td", { className: "".concat(prefixCls, "-expand-icon-cell"), key: "rc-table-expand-icon-cell" }, _this.renderExpandIcon())); }); return _this; } _createClass(ExpandableRow, [{ key: "componentWillUnmount", value: function componentWillUnmount() { this.handleDestroy(); } }, { key: "handleDestroy", value: function handleDestroy() { var _this$props4 = this.props, onExpandedChange = _this$props4.onExpandedChange, rowKey = _this$props4.rowKey, record = _this$props4.record; if (this.expandable) { onExpandedChange(false, record, null, rowKey, true); } } }, { key: "render", value: function render() { var _this$props5 = this.props, childrenColumnName = _this$props5.childrenColumnName, expandedRowRender = _this$props5.expandedRowRender, indentSize = _this$props5.indentSize, record = _this$props5.record, fixed = _this$props5.fixed, expanded = _this$props5.expanded; this.expandIconAsCell = fixed !== 'right' ? this.props.expandIconAsCell : false; this.expandIconColumnIndex = fixed !== 'right' ? this.props.expandIconColumnIndex : -1; var childrenData = record[childrenColumnName]; this.expandable = !!(childrenData || expandedRowRender); var expandableRowProps = { indentSize: indentSize, // not used in TableRow, but it's required to re-render TableRow when `expanded` changes expanded: expanded, onRowClick: this.handleRowClick, hasExpandIcon: this.hasExpandIcon, renderExpandIcon: this.renderExpandIcon, renderExpandIconCell: this.renderExpandIconCell }; return this.props.children(expandableRowProps); } }]); return ExpandableRow; }(Component); _defineProperty(ExpandableRow, "propTypes", { prefixCls: PropTypes.string.isRequired, rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, fixed: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]), record: PropTypes.object.isRequired, indentSize: PropTypes.number, needIndentSpaced: PropTypes.bool.isRequired, expandRowByClick: PropTypes.bool, expanded: PropTypes.bool.isRequired, expandIconAsCell: PropTypes.bool, expandIconColumnIndex: PropTypes.number, childrenColumnName: PropTypes.string, expandedRowRender: PropTypes.func, onExpandedChange: PropTypes.func.isRequired, onRowClick: PropTypes.func, children: PropTypes.func.isRequired }); export default connect(function (_ref, _ref2) { var expandedRowKeys = _ref.expandedRowKeys; var rowKey = _ref2.rowKey; return { expanded: expandedRowKeys.includes(rowKey) }; })(ExpandableRow); //# sourceMappingURL=ExpandableRow.js.map