phx-react
Version:
PHX REACT
68 lines • 3.72 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const types_1 = require("../../types");
const ExpandedRows_1 = tslib_1.__importDefault(require("./ExpandedRows"));
const Row_1 = tslib_1.__importDefault(require("./Row"));
const RowMerge_1 = tslib_1.__importDefault(require("./RowMerge"));
/**
* Renders one body cell using either merge-row or normal-row behavior.
*
* @param props - Cell data, table configuration, and expansion state.
* @returns A table body cell component.
*/
function TableBodyCell({ bodyKey, border, brSetSelectedPeople, data, dataIdx, isExpanded, isHighlight, keyIdx, mergeConfig, readonly, rowChildren, rowClassName, rowHighlightReadonly, rowKey, selectedAllPeople, selectedPeople, tableKey, thBodyComponent, toggleRowExpanded, }) {
const commonProps = {
border,
bodyKey,
brSetSelectedPeople,
className: rowClassName(keyIdx, dataIdx),
data,
dataIdx,
highlightReadonly: rowHighlightReadonly,
selectedAllPeople,
isHighlight,
selectedPeople,
keyIdx,
thBodyComponent,
readonly,
tableKey,
};
if (mergeConfig.isMergeRowData) {
return react_1.default.createElement(RowMerge_1.default, { ...commonProps, mergeConfig: mergeConfig });
}
return (react_1.default.createElement(Row_1.default, { ...commonProps, expandable: rowChildren && keyIdx === rowChildren.columnIndex
? {
enable: true,
isExpanded,
onToggle: () => toggleRowExpanded(rowKey),
}
: undefined }));
}
/**
* Renders one parent table row and its expanded children.
*
* @param props - Row data, table configuration, and expansion handlers.
* @returns One parent row with optional expanded rows.
*/
function TableBodyRow({ data, dataIdx, expandedRowKeys, getRowChildren, getRowKey, handleClick, isHighLight, mergeConfig, thBody, ...restProps }) {
const rowChildren = getRowChildren(data);
const rowKey = getRowKey(data, dataIdx);
const isExpanded = expandedRowKeys.includes(rowKey);
const isHighlight = isHighLight(data);
return (react_1.default.createElement(react_1.default.Fragment, { key: rowKey },
react_1.default.createElement("tr", { className: (0, types_1.classNames)('group', isHighlight && 'bg-gray-100 font-semibold'), onClick: () => handleClick(data, isHighlight) }, thBody.map((bodyKey, keyIdx) => (react_1.default.createElement(TableBodyCell, { key: keyIdx, ...restProps, bodyKey: bodyKey, data: data, dataIdx: dataIdx, isExpanded: isExpanded, isHighlight: isHighlight, keyIdx: keyIdx, mergeConfig: mergeConfig, rowChildren: rowChildren, rowKey: rowKey })))),
!mergeConfig.isMergeRowData && rowChildren && isExpanded && (react_1.default.createElement(ExpandedRows_1.default, { border: restProps.border, dataIdx: dataIdx, rowChildren: rowChildren, selectedAllPeople: restProps.selectedAllPeople, spacing: restProps.spacing, textCenter: restProps.textCenter, thBody: thBody }))));
}
/**
* Renders table report body rows and their optional expanded child rows.
*
* @param props - Body row data, table configuration, and row interaction handlers.
* @returns Table body row elements.
*/
function TableBodyRows({ rows, ...config }) {
return (react_1.default.createElement(react_1.default.Fragment, null, rows.map((data, dataIdx) => (react_1.default.createElement(TableBodyRow, { key: config.getRowKey(data, dataIdx), ...config, data: data, dataIdx: dataIdx })))));
}
exports.default = TableBodyRows;
//# sourceMappingURL=TableBodyRows.js.map