import clsx from 'clsx'; import classes from './MRT_TableDetailPanel.module.css'; import { type RefObject } from 'react'; import { Collapse, TableTd, type TableTdProps, TableTr } from '@mantine/core'; import { type MRT_Row, type MRT_RowData, type MRT_RowVirtualizer, type MRT_TableInstance, type MRT_VirtualItem, } from '../../types'; import { parseFromValuesOrFunc } from '../../utils/utils'; import { MRT_EditCellTextInput } from '../inputs/MRT_EditCellTextInput'; interface Props extends TableTdProps { parentRowRef: RefObject; renderedRowIndex?: number; row: MRT_Row; rowVirtualizer?: MRT_RowVirtualizer; striped?: false | string; table: MRT_TableInstance; virtualRow?: MRT_VirtualItem; } export const MRT_TableDetailPanel = ({ parentRowRef, renderedRowIndex = 0, row, rowVirtualizer, striped, table, virtualRow, ...rest }: Props) => { 'use no memo'; const { getState, getVisibleLeafColumns, options: { layoutMode, mantineDetailPanelProps, mantineTableBodyRowProps, renderDetailPanel, }, } = table; const { isLoading } = getState(); const tableRowProps = parseFromValuesOrFunc(mantineTableBodyRowProps, { isDetailPanel: true, row, table, }); const tableCellProps = { ...parseFromValuesOrFunc(mantineDetailPanelProps, { row, table, }), ...rest, }; const internalEditComponents = row .getAllCells() .filter((cell) => cell.column.columnDef.columnDefType === 'data') .map((cell) => ( )); const DetailPanel = !isLoading && row.getIsExpanded() && renderDetailPanel?.({ internalEditComponents, row, table }); return ( { if (node) { rowVirtualizer?.measureElement?.(node); } }} {...tableRowProps} __vars={{ '--mrt-parent-row-height': virtualRow ? `${parentRowRef.current?.getBoundingClientRect()?.height}px` : undefined, '--mrt-virtual-row-start': virtualRow ? `${virtualRow.start}px` : undefined, ...tableRowProps?.__vars, }} className={clsx( 'mantine-Table-tr-detail-panel', classes.root, layoutMode?.startsWith('grid') && classes['root-grid'], virtualRow && classes['root-virtual-row'], tableRowProps?.className, )} > {rowVirtualizer ? ( row.getIsExpanded() && DetailPanel ) : ( {DetailPanel} )} ); };