import { ColumnDef, flexRender, getCoreRowModel, getSortedRowModel, SortingState, Row as TanstackRow, Table as TanstackTable, useReactTable, } from '@tanstack/react-table' import classNames from 'classnames' import React from 'react' import Card from 'components/Card' import { SortAsc, SortDesc, SortNone } from 'components/Icons' import Row from 'components/Table/Row' import Text from 'components/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 isBalancesTable?: boolean hideCard?: boolean } export default function Table(props: Props) { const [sorting, setSorting] = React.useState(props.initialSorting) const table = useReactTable({ data: props.data, columns: props.columns, state: { sorting, }, onSortingChange: setSorting, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), }) return ( ( {children} )} > {table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => { return ( ) })} ))} {table.getRowModel().rows.map((row) => ( ))}
{header.column.getCanSort() ? { asc: , desc: , false: , }[header.column.getIsSorted() as string] ?? null : null} {flexRender(header.column.columnDef.header, header.getContext())}
) }