import { cn } from '@/utils/cn'; export interface Props { columns: { name: React.ReactNode; render: (item: T, index: number) => React.ReactNode; className?: string; width: string; }[]; keyExtractor: (item: T) => string; data: T[]; className?: string; eachRow?: (item: T, index: number) => React.ReactNode; columnClassName?: string; } export const WidgetTableHead = ({ children, className, }: { children: React.ReactNode; className?: string; }) => { return ( {children} ); }; export function WidgetTable({ className, columns, data, keyExtractor, eachRow, columnClassName, }: Props) { const gridTemplateColumns = columns.length > 1 ? `1fr ${columns .slice(1) .map(() => 'auto') .join(' ')}` : '1fr'; return (
{/* Header */}
{columns.map((column) => (
1 && column !== columns[0] ? 'text-right' : 'text-left', column.className, )} style={{ width: column.width }} > {column.name}
))}
{/* Body */}
{data.map((item, index) => (
{eachRow?.(item, index)}
{columns.map((column) => (
1 && column !== columns[0] ? 'text-right' : 'text-left', column.className, column.width === 'w-full' && 'w-full min-w-0', )} style={ column.width !== 'w-full' ? { width: column.width } : {} } > {column.render(item, index)}
))}
))}
); }