UNPKG

choerodon-ui

Version:

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

258 lines (217 loc) 8.27 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _extends from "@babel/runtime/helpers/extends"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; 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 { __decorate } from "tslib"; import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { observer } from 'mobx-react'; import { action, computed, get, set } from 'mobx'; import classNames from 'classnames'; import { pxToRem } from '../../../es/_util/UnitConvertor'; import measureScrollbar from '../../../es/_util/measureScrollbar'; import { columnWidth } from './Column'; import TableContext from './TableContext'; import { ColumnLock, DragColumnAlign } from './enum'; import TableFooterCell from './TableFooterCell'; import { getColumnKey, getColumnLock, getHeight as _getHeight, isStickySupport } from './utils'; import autobind from '../_util/autobind'; import ResizeObservedRow from './ResizeObservedRow'; import { CUSTOMIZED_KEY } from './TableStore'; var TableFooter = /*#__PURE__*/ function (_Component) { _inherits(TableFooter, _Component); var _super = _createSuper(TableFooter); function TableFooter() { _classCallCheck(this, TableFooter); return _super.apply(this, arguments); } _createClass(TableFooter, [{ key: "saveRef", value: function saveRef(node) { this.node = node; } }, { key: "handleResize", value: function handleResize(index, height) { this.setRowHeight(index, height); } }, { key: "setRowHeight", value: function setRowHeight(index, height) { var tableStore = this.context.tableStore; set(tableStore.lockColumnsFootRowsHeight, index, height); } }, { key: "getTds", value: function getTds() { var _this$props = this.props, lock = _this$props.lock, dataSet = _this$props.dataSet; var tableStore = this.context.tableStore; var prefixCls = tableStore.prefixCls, customizable = tableStore.customizable, rowDraggable = tableStore.rowDraggable, dragColumnAlign = tableStore.dragColumnAlign; var hasPlaceholder = tableStore.overflowY && lock !== ColumnLock.left; var leftWidth = 0; var rightWidth = isStickySupport() && tableStore.overflowX ? tableStore.rightLeafColumnsWidth + (hasPlaceholder ? measureScrollbar() : 0) : 0; var tds = this.leafColumns.map(function (column, index, cols) { var key = getColumnKey(column); if (key !== CUSTOMIZED_KEY) { var colSpan = customizable && lock !== ColumnLock.left && (!rowDraggable || dragColumnAlign !== DragColumnAlign.right) && index === cols.length - 2 ? 2 : 1; var props = {}; if (colSpan > 1) { props.colSpan = colSpan; } if (isStickySupport() && tableStore.overflowX) { var columnLock = getColumnLock(column.lock); if (columnLock === ColumnLock.left) { props.style = { left: pxToRem(leftWidth) }; var next = cols[index + 1]; if (!next || getColumnLock(next.lock) !== ColumnLock.left) { props.className = "".concat(prefixCls, "-cell-fix-left-last"); } leftWidth += columnWidth(column); } else if (columnLock === ColumnLock.right) { rightWidth -= columnWidth(column); var prev = cols[index - 1]; if (!prev || prev.lock !== ColumnLock.right) { props.className = "".concat(prefixCls, "-cell-fix-right-first"); } if (colSpan > 1) { for (var i = 1; i < colSpan; i++) { var _next = cols[index + i]; if (_next) { rightWidth -= columnWidth(_next); } } } props.style = { right: pxToRem(rightWidth) }; } } return React.createElement(TableFooterCell, _extends({ key: key, dataSet: dataSet, column: column }, props)); } return undefined; }); if (hasPlaceholder) { var placeHolderProps = { key: 'fixed-column' }; var classList = ["".concat(prefixCls, "-cell")]; if (isStickySupport() && tableStore.overflowX) { placeHolderProps.style = { right: 0 }; classList.push("".concat(prefixCls, "-cell-fix-right")); } placeHolderProps.className = classList.join(' '); tds.push(React.createElement("th", _extends({}, placeHolderProps), "\xA0")); } return tds; } }, { key: "getHeight", value: function getHeight() { var node = this.node; if (node) { return _getHeight(node); } return 0; } }, { key: "render", value: function render() { var lock = this.props.lock; var tableStore = this.context.tableStore; var prefixCls = tableStore.prefixCls, autoFootHeight = tableStore.autoFootHeight, rowHeight = tableStore.rowHeight, overflowX = tableStore.overflowX; var tds = this.getTds(); var tr = React.createElement("tr", { style: { height: !isStickySupport() && lock && (rowHeight === 'auto' || autoFootHeight) ? pxToRem(get(tableStore.lockColumnsFootRowsHeight, 0)) : undefined } }, tds); return React.createElement("tfoot", { ref: this.saveRef, className: classNames("".concat(prefixCls, "-tfoot"), _defineProperty({}, "".concat(prefixCls, "-tfoot-bordered"), overflowX)) }, !isStickySupport() && !lock && (rowHeight === 'auto' || autoFootHeight) ? React.createElement(ResizeObservedRow, { onResize: this.handleResize, rowIndex: 0 }, tr) : tr); } }, { key: "leafColumns", get: function get() { var tableStore = this.context.tableStore; var lock = this.props.lock; if (lock === ColumnLock.right) { return tableStore.rightLeafColumns.filter(function (_ref) { var hidden = _ref.hidden; return !hidden; }); } if (lock) { return tableStore.leftLeafColumns.filter(function (_ref2) { var hidden = _ref2.hidden; return !hidden; }); } return tableStore.leafColumns.filter(function (_ref3) { var hidden = _ref3.hidden; return !hidden; }); } }]); return TableFooter; }(Component); TableFooter.displayName = 'TableFooter'; TableFooter.propTypes = { lock: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf([ColumnLock.right, ColumnLock.left])]) }; TableFooter.contextType = TableContext; __decorate([autobind], TableFooter.prototype, "saveRef", null); __decorate([autobind], TableFooter.prototype, "handleResize", null); __decorate([action], TableFooter.prototype, "setRowHeight", null); __decorate([computed], TableFooter.prototype, "leafColumns", null); TableFooter = __decorate([observer], TableFooter); export default TableFooter; //# sourceMappingURL=TableFooter.js.map