choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
157 lines (132 loc) • 5.15 kB
JavaScript
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 { observer } from 'mobx-react';
import raf from 'raf';
import { pxToRem } from '../../../es/_util/UnitConvertor';
import measureScrollbar from '../../../es/_util/measureScrollbar';
import autobind from '../_util/autobind';
import TableContext from './TableContext';
import { ColumnLock, TableAutoHeightType } from './enum';
var TableBody =
/*#__PURE__*/
function (_Component) {
_inherits(TableBody, _Component);
var _super = _createSuper(TableBody);
function TableBody() {
_classCallCheck(this, TableBody);
return _super.apply(this, arguments);
}
_createClass(TableBody, [{
key: "saveRef",
value: function saveRef(node) {
var getRef = this.props.getRef;
if (getRef) {
getRef(node);
}
this.element = node;
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
var element = this.element;
if (element) {
var scrollHeight = element.scrollHeight,
clientHeight = element.clientHeight; // Fixed vertical scrollbar not displayed in Chrome when scrollHeight - clientHeight < scrollbarHeight
if (scrollHeight > clientHeight && scrollHeight - clientHeight < measureScrollbar()) {
var overflow = element.style.overflow;
element.style.overflow = 'scroll';
raf(function () {
element.style.overflow = overflow;
});
}
}
}
}, {
key: "getHeightStyle",
value: function getHeightStyle() {
var _this$context$tableSt = this.context.tableStore,
height = _this$context$tableSt.height,
autoHeight = _this$context$tableSt.autoHeight,
heightType = _this$context$tableSt.customized.heightType;
if (!heightType && autoHeight && autoHeight.type === TableAutoHeightType.maxHeight) {
return undefined;
}
return height;
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
children = _this$props.children,
lock = _this$props.lock,
onScroll = _this$props.onScroll;
var _this$context$tableSt2 = this.context.tableStore,
prefixCls = _this$context$tableSt2.prefixCls,
leftLeafColumnsWidth = _this$context$tableSt2.leftLeafColumnsWidth,
rightLeafColumnsWidth = _this$context$tableSt2.rightLeafColumnsWidth,
hasFooter = _this$context$tableSt2.hasFooter,
overflowY = _this$context$tableSt2.overflowY,
overflowX = _this$context$tableSt2.overflowX;
var fixedLeft = lock === true || lock === ColumnLock.left;
var scrollbar = measureScrollbar();
var hasFooterAndNotLock = !lock && hasFooter && overflowX && scrollbar;
var height = this.getHeightStyle();
var tableBody = React.createElement("div", {
ref: this.saveRef,
className: "".concat(prefixCls, "-body"),
style: {
height: pxToRem(hasFooterAndNotLock && height !== undefined ? height + scrollbar : height),
marginBottom: hasFooterAndNotLock ? pxToRem(-scrollbar) : undefined,
width: fixedLeft ? pxToRem(leftLeafColumnsWidth + (scrollbar || 20)) : lock === ColumnLock.right ? pxToRem(rightLeafColumnsWidth - 1 + (overflowY ? scrollbar : 0)) : undefined,
marginLeft: lock === ColumnLock.right ? pxToRem(1) : undefined
},
onScroll: onScroll
}, children);
if (fixedLeft) {
return React.createElement("div", {
style: {
width: pxToRem(leftLeafColumnsWidth),
overflow: 'hidden'
}
}, tableBody);
}
return tableBody;
}
}]);
return TableBody;
}(Component);
TableBody.displayName = 'TableBody';
TableBody.contextType = TableContext;
__decorate([autobind], TableBody.prototype, "saveRef", null);
TableBody = __decorate([observer], TableBody);
export default TableBody;
//# sourceMappingURL=TableBody.js.map