({
table,
loading,
className,
onRowClick,
empty = {
title: 'No data',
description: 'We could not find any data here yet',
},
...props
}: DataTableProps<TData>)
| 33 | } |
| 34 | |
| 35 | export function DataTable<TData>({ |
| 36 | table, |
| 37 | loading, |
| 38 | className, |
| 39 | onRowClick, |
| 40 | empty = { |
| 41 | title: 'No data', |
| 42 | description: 'We could not find any data here yet', |
| 43 | }, |
| 44 | ...props |
| 45 | }: DataTableProps<TData>) { |
| 46 | return ( |
| 47 | <div |
| 48 | className={cn('flex w-full flex-col gap-2.5 overflow-auto', className)} |
| 49 | {...props} |
| 50 | > |
| 51 | <div className="overflow-hidden rounded-md border"> |
| 52 | <Table> |
| 53 | <TableHeader> |
| 54 | {table.getHeaderGroups().map((headerGroup) => ( |
| 55 | <TableRow key={headerGroup.id}> |
| 56 | {headerGroup.headers.map((header) => ( |
| 57 | <TableHead |
| 58 | key={header.id} |
| 59 | colSpan={header.colSpan} |
| 60 | style={{ |
| 61 | ...getCommonPinningStyles({ |
| 62 | column: header.column, |
| 63 | }), |
| 64 | }} |
| 65 | > |
| 66 | {header.isPlaceholder |
| 67 | ? null |
| 68 | : flexRender( |
| 69 | header.column.columnDef.header, |
| 70 | header.getContext(), |
| 71 | )} |
| 72 | </TableHead> |
| 73 | ))} |
| 74 | </TableRow> |
| 75 | ))} |
| 76 | </TableHeader> |
| 77 | <TableBody> |
| 78 | {table.getRowModel().rows?.length ? ( |
| 79 | table.getRowModel().rows.map((row) => ( |
| 80 | <TableRow |
| 81 | key={row.id} |
| 82 | data-state={row.getIsSelected() && 'selected'} |
| 83 | onClick={onRowClick ? () => onRowClick(row) : undefined} |
| 84 | className={onRowClick ? 'cursor-pointer' : undefined} |
| 85 | > |
| 86 | {row.getVisibleCells().map((cell) => ( |
| 87 | <TableCell |
| 88 | key={cell.id} |
| 89 | style={{ |
| 90 | ...getCommonPinningStyles({ |
| 91 | column: cell.column, |
| 92 | }), |
nothing calls this directly
no test coverage detected