import { ColumnDef, flexRender, getCoreRowModel, getSortedRowModel, OnChangeFn, RowSelectionState, SortingState, Row as TanstackRow, Table as TanstackTable, useReactTable, } from '@tanstack/react-table' import classNames from 'classnames' import React from 'react' import Card from 'components/common/Card' import { SortAsc, SortDesc, SortNone } from 'components/common/Icons' import Row from 'components/common/Table/Row' import Text from 'components/common/Text' import ConditionalWrapper from 'hocs/ConditionalWrapper' interface Props { title: string columns: ColumnDef[] data: T[] initialSorting: SortingState renderExpanded?: (row: TanstackRow, table: TanstackTable) => JSX.Element tableBodyClassName?: string spacingClassName?: string type?: TableType hideCard?: boolean setRowSelection?: OnChangeFn selectedRows?: RowSelectionState onClickRow?: (id: string) => void } export default function Table(props: Props) { const [sorting, setSorting] = React.useState(props.initialSorting) const table = useReactTable({ data: props.data, columns: props.columns, state: { sorting, rowSelection: props.selectedRows, }, enableRowSelection: true, onRowSelectionChange: props.setRowSelection, onSortingChange: setSorting, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), }) return ( ( {children} )} > {table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => { return ( ) })} ))} {table.getRowModel().rows.map((row) => ( ))}
{flexRender(header.column.columnDef.header, header.getContext())} {header.column.getCanSort() && ( {header.column.getCanSort() ? { asc: , desc: , false: , }[header.column.getIsSorted() as string] ?? null : null} )}
) }