2023-05-02 06:42:16 +00:00
|
|
|
import { ReactNode } from 'react';
|
|
|
|
import { Row } from '@tanstack/react-table';
|
2022-11-22 12:16:34 +00:00
|
|
|
|
|
|
|
import { TableRow } from './TableRow';
|
2023-09-04 09:33:07 +00:00
|
|
|
import { DefaultType } from './types';
|
2022-11-22 12:16:34 +00:00
|
|
|
|
2023-09-04 09:33:07 +00:00
|
|
|
interface Props<D extends DefaultType> {
|
2022-11-22 12:16:34 +00:00
|
|
|
row: Row<D>;
|
|
|
|
renderSubRow(row: Row<D>): ReactNode;
|
2023-05-02 06:42:16 +00:00
|
|
|
expandOnClick?: boolean;
|
2022-11-22 12:16:34 +00:00
|
|
|
}
|
|
|
|
|
2023-09-04 09:33:07 +00:00
|
|
|
export function ExpandableDatatableTableRow<D extends DefaultType>({
|
2022-11-22 12:16:34 +00:00
|
|
|
row,
|
|
|
|
renderSubRow,
|
2023-05-02 06:42:16 +00:00
|
|
|
expandOnClick,
|
2022-11-22 12:16:34 +00:00
|
|
|
}: Props<D>) {
|
2023-05-02 06:42:16 +00:00
|
|
|
const cells = row.getVisibleCells();
|
|
|
|
|
2022-11-22 12:16:34 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<TableRow<D>
|
2023-05-02 06:42:16 +00:00
|
|
|
cells={cells}
|
|
|
|
onClick={expandOnClick ? () => row.toggleExpanded() : undefined}
|
2022-11-22 12:16:34 +00:00
|
|
|
/>
|
2023-09-20 06:04:26 +00:00
|
|
|
{row.getIsExpanded() && renderSubRow(row)}
|
2022-11-22 12:16:34 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|