tdesign-react
Version:
TDesign Component for React
122 lines (118 loc) • 5.41 kB
JavaScript
/**
* tdesign v1.15.1
* (c) 2025 tdesign
* @license MIT
*/
import { _ as _defineProperty } from '../_chunks/dep-cb0a3966.js';
import React, { useRef } from 'react';
import { isFunction, get } from 'lodash-es';
import classNames from 'classnames';
import { formatRowAttributes, formatRowClassNames } from './utils.js';
import { getColumnFixedStyles } from './hooks/useFixed.js';
import useRowspanAndColspan, { getCellKey } from './hooks/useRowspanAndColspan.js';
import useClassName from './hooks/useClassName.js';
import '../_chunks/dep-eca3a3de.js';
import '../_chunks/dep-1630b9b4.js';
import '../_chunks/dep-87d110df.js';
import '../_chunks/dep-026a4c6b.js';
import '../_chunks/dep-6b660ef0.js';
import '../_chunks/dep-48805ab8.js';
import '../_chunks/dep-f53c91cd.js';
import '../_chunks/dep-b908e1fe.js';
import '../_chunks/dep-a3bde62f.js';
import '../hooks/useDebounce.js';
import '../hooks/usePersistFn.js';
import '../hooks/usePrevious.js';
import '../_util/listener.js';
import '../_chunks/dep-3a09424a.js';
import '../hooks/useConfig.js';
import '../config-provider/ConfigContext.js';
import '../locale/zh_CN.js';
import '../_chunks/dep-e29214cb.js';
import 'dayjs';
import '../_chunks/dep-3c9ab31a.js';
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function TFoot(props) {
var footData = props.footData,
columns = props.columns,
rowKey = props.rowKey,
footerSummary = props.footerSummary,
virtualScroll = props.virtualScroll;
var tfooterRef = useRef(null);
var classnames = useClassName();
var _useRowspanAndColspan = useRowspanAndColspan(footData, columns, rowKey, props.rowspanAndColspanInFooter),
skipSpansMap = _useRowspanAndColspan.skipSpansMap;
var renderTFootCell = function renderTFootCell(p) {
var col = p.col,
row = p.row;
if (isFunction(col.foot)) {
return col.foot(p);
}
return col.foot || get(row, col.colKey);
};
var theadClasses = [classnames.tableFooterClasses.footer, _defineProperty({}, classnames.tableFooterClasses.fixed, props.isFixedHeader)];
if (!columns) return null;
var footerDomList = footData === null || footData === void 0 ? void 0 : footData.map(function (row, rowIndex) {
var trAttributes = formatRowAttributes(props.rowAttributes, {
row: row,
rowIndex: rowIndex,
type: "foot"
});
var customClasses = formatRowClassNames(props.rowClassName, {
row: row,
rowIndex: rowIndex,
type: "foot"
}, props.rowKey || "id");
return /* @__PURE__ */React.createElement("tr", _objectSpread(_objectSpread({
key: rowIndex
}, trAttributes), {}, {
className: classNames(customClasses)
}), columns.map(function (col, colIndex) {
var _props$thWidthList;
var cellSpans = {};
var spanState = null;
if (skipSpansMap.size) {
var _spanState, _spanState2;
var cellKey = getCellKey(row, rowKey, col.colKey, colIndex);
spanState = skipSpansMap.get(cellKey) || {};
((_spanState = spanState) === null || _spanState === void 0 ? void 0 : _spanState.rowspan) > 1 && (cellSpans.rowspan = spanState.rowspan);
((_spanState2 = spanState) === null || _spanState2 === void 0 ? void 0 : _spanState2.colspan) > 1 && (cellSpans.colspan = spanState.colspan);
if (spanState.skipped) return null;
}
var tdStyles = getColumnFixedStyles(col, colIndex, props.rowAndColFixedPosition, classnames.tableColFixedClasses);
var style = _objectSpread({}, tdStyles.style);
if ((_props$thWidthList = props.thWidthList) !== null && _props$thWidthList !== void 0 && _props$thWidthList[col.colKey]) {
style.width = "".concat(props.thWidthList[col.colKey] || 0, "px");
}
return /* @__PURE__ */React.createElement("td", {
key: col.colKey,
rowSpan: cellSpans.rowspan,
colSpan: cellSpans.colspan,
className: classNames(tdStyles.classes),
style: style
}, renderTFootCell({
row: row,
rowIndex: rowIndex,
col: col,
colIndex: colIndex
}));
}));
});
if (!footerSummary && (!props.footData || !props.footData.length)) return null;
return /* @__PURE__ */React.createElement("tfoot", {
ref: tfooterRef,
className: classNames(theadClasses),
style: {
visibility: virtualScroll ? "hidden" : "visible"
}
}, footerSummary && /* @__PURE__ */React.createElement("tr", {
className: classnames.tableFullRowClasses.base
}, /* @__PURE__ */React.createElement("td", {
colSpan: columns.length
}, /* @__PURE__ */React.createElement("div", {
className: classnames.tableFullRowClasses.innerFullElement
}, footerSummary))), footerDomList);
}
export { TFoot as default };
//# sourceMappingURL=TFoot.js.map