import { ColumnDef, flexRender, getCoreRowModel, useReactTable, createColumnHelper, getExpandedRowModel, ExpandedState, } from '@tanstack/react-table'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table'; import { Empty } from 'antd'; import React from 'react'; import { Button } from './ui/button'; import { LuArrowRight } from 'react-icons/lu'; import { cn } from '@/utils/style'; export type { ColumnDef }; export { createColumnHelper }; interface DataTableProps { columns: ColumnDef[]; data: TData[]; ExpandComponent?: React.ComponentType<{ row: TData }>; } export function DataTable({ columns, data, ExpandComponent, }: DataTableProps) { const [expanded, setExpanded] = React.useState({}); const canExpand = Boolean(ExpandComponent); const table = useReactTable({ data, columns, state: { expanded, }, onExpandedChange: setExpanded, getCoreRowModel: getCoreRowModel(), getRowCanExpand: () => canExpand, }); return (
{table.getHeaderGroups().map((headerGroup) => ( {canExpand && (
); }