import _ from 'lodash'; import { FC } from 'react'; import { useTable, useSortBy, Column } from 'react-table'; import TableEmpty from './components/empty/TableEmpty'; import Table from './Table'; const { Container, Head, Row, HeaderCell, Body, Cell } = Table; export interface DataTableProps { title?: string; sortable?: boolean; data: readonly Record[]; columns: readonly Column>[]; className?: string; } const DataTable: FC = ({ title, sortable = false, data, columns, className = '' }) => { const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable({ columns, data }, useSortBy); return ( {headerGroups.map((headerGroup, index) => ( {headerGroup.headers.map((column) => ( {column.render('Header')} ))} ))} {_.isEmpty(rows) ? ( ) : ( rows.map((row) => { prepareRow(row); return ( {row.cells.map((cell) => { const key = `${cell.column.id}-${cell.row.id}`; return ( {cell.render('Cell')} ); })} ); }) )}
); }; export default DataTable;