import { ReactElement, ReactNode } from 'react'; interface DataTableProps { data: T[]; headers: { label: string; key?: keyof T; render?: (item: T, index: number) => ReactNode; className?: string; }[]; showCheckbox?: boolean; onRowClick?: (item: T) => void; } export const DataTable = >({ data, headers, showCheckbox = true, onRowClick, }: DataTableProps): ReactElement => { return (
{showCheckbox && ( )} {headers.map((header, index) => { const isFirst = index === 0 && !showCheckbox; const isLast = index === headers.length - 1; return ( ); })} {data.map((item, rowIndex) => ( onRowClick && onRowClick(item)} > {showCheckbox && ( )} {headers.map((header, colIndex) => { const isFirst = colIndex === 0 && !showCheckbox; const isLast = colIndex === headers.length - 1; return ( ); })} ))}
{header.label}
{header.render ? header.render(item, rowIndex) : header.key ? item[header.key] : null}
); }; export default DataTable;