import { type ReactNode } from 'react'; import Stack from '@mui/material/Stack'; import Tooltip from '@mui/material/Tooltip'; import { MRT_ExpandAllButton } from '../../components/buttons/MRT_ExpandAllButton'; import { MRT_ExpandButton } from '../../components/buttons/MRT_ExpandButton'; import { type MRT_ColumnDef, type MRT_RowData, type MRT_StatefulTableOptions, } from '../../types'; import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils'; import { getCommonTooltipProps } from '../../utils/style.utils'; export const getMRT_RowExpandColumnDef = ( tableOptions: MRT_StatefulTableOptions, ): MRT_ColumnDef => { const { defaultColumn, enableExpandAll, groupedColumnMode, positionExpandColumn, renderDetailPanel, state: { grouping }, } = tableOptions; const alignProps = positionExpandColumn === 'last' ? ({ align: 'right', } as const) : undefined; return { Cell: ({ cell, column, row, staticRowIndex, table }) => { const expandButtonProps = { row, staticRowIndex, table }; const subRowsLength = row.subRows?.length; if (groupedColumnMode === 'remove' && row.groupingColumnId) { return ( {row.groupingValue as ReactNode} {!!subRowsLength && ({subRowsLength})} ); } else { return ( <> {column.columnDef.GroupedCell?.({ cell, column, row, table })} ); } }, Header: enableExpandAll ? ({ table }) => { return ( <> {groupedColumnMode === 'remove' && grouping ?.map( (groupedColumnId) => table.getColumn(groupedColumnId).columnDef.header, ) ?.join(', ')} ); } : undefined, muiTableBodyCellProps: alignProps, muiTableHeadCellProps: alignProps, ...defaultDisplayColumnProps({ header: 'expand', id: 'mrt-row-expand', size: groupedColumnMode === 'remove' ? (defaultColumn?.size ?? 180) : renderDetailPanel ? enableExpandAll ? 60 : 70 : 100, tableOptions, }), }; };