UNPKG

choerodon-ui

Version:

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

99 lines (86 loc) 3.48 kB
import _extends from "@babel/runtime/helpers/extends"; import _typeof from "@babel/runtime/helpers/typeof"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import React, { useContext } from 'react'; 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 { getColumnLock, isStickySupport } from './utils'; import { ColumnAlign, ColumnLock } from './enum'; var TableFooterCell = function TableFooterCell(props) { var columnGroup = props.columnGroup, style = props.style, className = props.className, colSpan = props.colSpan, right = props.right; var _useContext = useContext(TableContext), rowHeight = _useContext.rowHeight, dataSet = _useContext.dataSet, prefixCls = _useContext.prefixCls, tableStore = _useContext.tableStore; var column = columnGroup.column; var autoFootHeight = tableStore.autoFootHeight, footerRowHeight = tableStore.props.footerRowHeight; 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 innerClassNames = ["".concat(prefixCls, "-cell-inner")]; var innerProps = {}; if (footerRowHeight !== 'auto' && rowHeight !== 'auto' && !autoFootHeight) { innerProps.style = { height: pxToRem(footerRowHeight === undefined ? rowHeight : footerRowHeight) }; innerClassNames.push("".concat(prefixCls, "-cell-inner-row-height-fixed")); } var cellStyle = _objectSpread({ textAlign: align || (command ? ColumnAlign.center : tableStore.getConfig('tableColumnAlign')(column, dataSet.getField(name))) }, footerStyle, {}, style); if (columnLock) { if (columnLock === ColumnLock.left) { cellStyle.left = pxToRem(columnGroup.left); } else if (columnLock === ColumnLock.right) { cellStyle.right = pxToRem(colSpan && colSpan > 1 ? right : columnGroup.right + right); } } var getFooter = function getFooter() { switch (_typeof(footer)) { case 'function': { var footerHookOptions = { dataSet: dataSet, name: name }; try { return footer(footerHookOptions); } catch (e) { return footer(dataSet, name); } } case 'string': return React.createElement("span", null, footer); default: return footer; } }; return React.createElement("th", { className: classString, style: omit(cellStyle, ['width', 'height']), colSpan: colSpan, scope: "col" }, React.createElement("div", _extends({}, innerProps, { className: innerClassNames.join(' ') }), getFooter())); }; TableFooterCell.displayName = 'TableFooterCell'; export default observer(TableFooterCell); //# sourceMappingURL=TableFooterCell.js.map