import { PropsWithChildren } from 'react'; import { Row, TableRowProps } from 'react-table'; interface Props = Record> { isLoading?: boolean; rows: Row[]; emptyContent?: string; prepareRow(row: Row): void; renderRow(row: Row, rowProps: TableRowProps): React.ReactNode; } export function TableContent< T extends Record = Record >({ isLoading = false, rows, emptyContent = 'No items available', prepareRow, renderRow, }: Props) { if (isLoading) { return Loading...; } if (!rows.length) { return {emptyContent}; } return ( <> {rows.map((row) => { prepareRow(row); const { key, className, role, style } = row.getRowProps(); return renderRow(row, { key, className, role, style }); })} ); } function TableContentOneColumn({ children }: PropsWithChildren) { // using MAX_SAFE_INTEGER to make sure the single column will be the size of the table return ( {children} ); }