import * as React from 'react'; import { Box, Collapse } from '@mantine/core'; import { type MRT_Row, type MRT_TableInstance, type MRT_VirtualItem, } from '../types'; interface Props = {}> { parentRowRef: React.RefObject; row: MRT_Row; rowIndex: number; table: MRT_TableInstance; virtualRow?: MRT_VirtualItem; } export const MRT_TableDetailPanel = = {}>({ parentRowRef, row, rowIndex, table, virtualRow, }: Props) => { const { getVisibleLeafColumns, getState, options: { layoutMode, mantineTableBodyRowProps, mantineDetailPanelProps, renderDetailPanel, }, } = table; const { isLoading } = getState(); const tableRowProps = mantineTableBodyRowProps instanceof Function ? mantineTableBodyRowProps({ isDetailPanel: true, row, staticRowIndex: rowIndex, table, }) : mantineTableBodyRowProps; const tableCellProps = mantineDetailPanelProps instanceof Function ? mantineDetailPanelProps({ row, table }) : mantineDetailPanelProps; return ( ({ display: layoutMode === 'grid' ? 'flex' : 'table-row', position: virtualRow ? 'absolute' : undefined, top: virtualRow ? `${parentRowRef.current?.getBoundingClientRect()?.height}px` : undefined, transform: virtualRow ? `translateY(${virtualRow?.start}px)` : undefined, width: '100%', zIndex: virtualRow ? 2 : undefined, ...(tableRowProps?.sx instanceof Function ? tableRowProps.sx(theme) : (tableRowProps?.sx as any)), })} > ({ backgroundColor: virtualRow ? theme.fn.lighten(theme.colors.dark[7], 0.06) : undefined, borderBottom: !row.getIsExpanded() ? 'none' : undefined, display: layoutMode === 'grid' ? 'flex' : 'table-cell', paddingBottom: row.getIsExpanded() ? '16px !important' : '0 !important', paddingTop: row.getIsExpanded() ? '16px !important' : '0 !important', transition: 'all 100ms ease-in-out', width: `${table.getTotalSize()}px`, ...(tableCellProps?.sx instanceof Function ? tableCellProps.sx(theme) : (tableCellProps?.sx as any)), })} > {renderDetailPanel && ( {!isLoading && renderDetailPanel({ row, table })} )} ); };