import { ReactNode } from "react"; export type TableColumn> = { key: keyof T | "actions" | string; header: string; render?: (row: T) => ReactNode; }; type TableProps> = { columns: TableColumn[]; data: T[]; loading?: boolean; noDataText?: string; }; export default function DataTable>({ columns, data, loading, noDataText = "No data" }: TableProps) { return (
{loading && (
Loading ...
)} {!loading && data.length === 0 &&
{noDataText}
} {!loading && data.length > 0 && ( {columns.map((col) => ( ))} {data.map((row, idx) => ( {columns.map((col) => ( ))} ))}
{col.header}
{col.render ? col.render(row) : String((row as Record)[col.key as keyof T] ?? "-")}
)}
); }