2023-05-02 06:42:16 +00:00
|
|
|
import { Row } from '@tanstack/react-table';
|
2022-11-22 12:16:34 +00:00
|
|
|
import { ReactNode } from 'react';
|
|
|
|
|
|
|
|
import { ExpandableDatatableTableRow } from './ExpandableDatatableRow';
|
|
|
|
import { Datatable, Props as DatatableProps } from './Datatable';
|
|
|
|
|
|
|
|
interface Props<D extends Record<string, unknown>>
|
|
|
|
extends Omit<DatatableProps<D>, 'renderRow' | 'expandable'> {
|
|
|
|
renderSubRow(row: Row<D>): ReactNode;
|
2023-05-02 06:42:16 +00:00
|
|
|
expandOnRowClick?: boolean;
|
2022-11-22 12:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function ExpandableDatatable<D extends Record<string, unknown>>({
|
|
|
|
renderSubRow,
|
2023-05-02 06:42:16 +00:00
|
|
|
getRowCanExpand = () => true,
|
|
|
|
expandOnRowClick,
|
2022-11-22 12:16:34 +00:00
|
|
|
...props
|
|
|
|
}: Props<D>) {
|
|
|
|
return (
|
|
|
|
<Datatable<D>
|
|
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
|
|
{...props}
|
2023-05-02 06:42:16 +00:00
|
|
|
getRowCanExpand={getRowCanExpand}
|
|
|
|
renderRow={(row) => (
|
2022-11-22 12:16:34 +00:00
|
|
|
<ExpandableDatatableTableRow<D>
|
|
|
|
row={row}
|
|
|
|
renderSubRow={renderSubRow}
|
2023-05-02 06:42:16 +00:00
|
|
|
expandOnClick={expandOnRowClick}
|
2022-11-22 12:16:34 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|