UNPKG

choerodon-ui

Version:

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

122 lines (103 loc) 3.81 kB
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 { action, get, set } from 'mobx'; import { observer } from 'mobx-react'; import { pxToRem } from '../../../es/_util/UnitConvertor'; import ResizeObservedRow from './ResizeObservedRow'; import TableContext from './TableContext'; import autobind from '../_util/autobind'; import { isStickySupport } from './utils'; var TableHeaderRow = /*#__PURE__*/ function (_Component) { _inherits(TableHeaderRow, _Component); var _super = _createSuper(TableHeaderRow); function TableHeaderRow() { _classCallCheck(this, TableHeaderRow); return _super.apply(this, arguments); } _createClass(TableHeaderRow, [{ key: "handleResize", value: function handleResize(rowIndex, height) { this.setRowHeight(rowIndex, height); } }, { key: "setRowHeight", value: function setRowHeight(index, height) { var tableStore = this.context.tableStore; set(tableStore.lockColumnsHeadRowsHeight, index, height); } }, { key: "getRowHeight", value: function getRowHeight(index) { var tableStore = this.context.tableStore; return get(tableStore.lockColumnsHeadRowsHeight, index) || 0; } }, { key: "getHeaderRowStyle", value: function getHeaderRowStyle(rows, rowIndex) { var _this = this; var height = this.getRowHeight(rowIndex++); return pxToRem(rows.slice(rowIndex).reduce(function (total, r, index) { return r.length ? total : total + _this.getRowHeight(index + rowIndex); }, height)); } }, { key: "render", value: function render() { var _this$props = this.props, rowIndex = _this$props.rowIndex, lock = _this$props.lock, tds = _this$props.tds, rows = _this$props.rows; var rowHeight = this.context.tableStore.rowHeight; var needStoreRowHeight = !isStickySupport() && (rowHeight === 'auto' || rows.length > 1); var tr = React.createElement("tr", { style: { height: lock && needStoreRowHeight ? this.getHeaderRowStyle(rows, rowIndex) : undefined } }, tds); return !lock && needStoreRowHeight ? React.createElement(ResizeObservedRow, { onResize: this.handleResize, rowIndex: rowIndex }, tr) : tr; } }]); return TableHeaderRow; }(Component); TableHeaderRow.contextType = TableContext; __decorate([autobind], TableHeaderRow.prototype, "handleResize", null); __decorate([action], TableHeaderRow.prototype, "setRowHeight", null); TableHeaderRow = __decorate([observer], TableHeaderRow); export default TableHeaderRow; ; //# sourceMappingURL=TableHeaderRow.js.map