import { ColumnDef, flexRender, } from "@tanstack/react-table"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Skeleton } from "@marzneshin/components"; import { useTranslation } from "react-i18next"; import { useEntityTableContext } from "@marzneshin/features/entity-table/contexts"; import { type FC } from "react"; interface DataTableProps { columns: ColumnDef[] onRowClick?: (object: TData) => void } const Headers = () => { const { table } = useEntityTableContext(); return ( table.getHeaderGroups().map(headerGroup => ( {headerGroup.headers.map(header => ( {!header.isPlaceholder && flexRender(header.column.columnDef.header, header.getContext())} ))} )) ) }; const Rows: FC>> = ({ columns, onRowClick }) => { const { table } = useEntityTableContext(); const { t } = useTranslation(); return (table.getRowModel().rows?.length ? ( table.getRowModel().rows.map(row => ( onRowClick?.(row.original)} > {row.getVisibleCells().map(cell => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : ( {t('table.no-result')} )) }; const Loading = () => ( <> {Array.from({ length: 5 }).map((_, rowIndex) => ( ))} ); export function EntityDataTable({ columns, onRowClick, }: Readonly>) { const { isLoading } = useEntityTableContext(); return ( {isLoading ? : }
); }