choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
138 lines (118 loc) • 4.61 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _typeof from "@babel/runtime/helpers/typeof";
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 omit from 'lodash/omit';
import classNames from 'classnames';
import { pxToRem } from '../../../es/_util/UnitConvertor';
import TableContext from './TableContext';
import { getAlignByField, getColumnLock, isStickySupport } from './utils';
import { ColumnAlign } from './enum';
var TableFooterCell =
/*#__PURE__*/
function (_Component) {
_inherits(TableFooterCell, _Component);
var _super = _createSuper(TableFooterCell);
function TableFooterCell() {
_classCallCheck(this, TableFooterCell);
return _super.apply(this, arguments);
}
_createClass(TableFooterCell, [{
key: "getFooter",
value: function getFooter(footer, dataSet) {
switch (_typeof(footer)) {
case 'function':
{
var column = this.props.column;
return footer(dataSet, column.name);
}
case 'string':
return React.createElement("span", null, footer);
default:
return footer;
}
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
column = _this$props.column,
dataSet = _this$props.dataSet,
style = _this$props.style,
className = _this$props.className,
colSpan = _this$props.colSpan;
var tableStore = this.context.tableStore;
var prefixCls = tableStore.prefixCls,
rowHeight = tableStore.rowHeight,
autoFootHeight = tableStore.autoFootHeight;
var footer = column.footer,
footerClassName = column.footerClassName,
_column$footerStyle = column.footerStyle,
footerStyle = _column$footerStyle === void 0 ? {} : _column$footerStyle,
align = column.align,
name = column.name,
command = column.command,
lock = column.lock;
var columnLock = isStickySupport() && tableStore.overflowX && getColumnLock(lock);
var classString = classNames("".concat(prefixCls, "-cell"), _defineProperty({}, "".concat(prefixCls, "-cell-fix-").concat(columnLock), columnLock), className, footerClassName);
var innerProps = {
className: "".concat(prefixCls, "-cell-inner")
};
if (rowHeight !== 'auto' && !autoFootHeight) {
innerProps.style = {
height: pxToRem(rowHeight)
};
}
var cellStyle = _objectSpread({
textAlign: align || (command ? ColumnAlign.center : getAlignByField(dataSet.getField(name)))
}, footerStyle, {}, style);
return React.createElement("th", {
className: classString,
style: omit(cellStyle, ['width', 'height']),
colSpan: colSpan
}, React.createElement("div", _extends({}, innerProps), this.getFooter(footer, dataSet)));
}
}]);
return TableFooterCell;
}(Component);
TableFooterCell.displayName = 'TableFooterCell';
TableFooterCell.propTypes = {
column: PropTypes.object.isRequired
};
TableFooterCell.contextType = TableContext;
TableFooterCell = __decorate([observer], TableFooterCell);
export default TableFooterCell;
//# sourceMappingURL=TableFooterCell.js.map