import clsx from 'clsx' import { ReactNode } from 'react' export type TableItem = | ReactNode | { value: ReactNode className?: string } export type TableProps = { // The table headers. headers: TableItem[] // The table rows. Each row is an array of items. rows: TableItem[][] // This makes the first column take up all the remaining space, and the rest // of the columns will be sized to fit their content. Often the first column // is a sort of descriptor for the row, and the rest of the columns are // relevant data. Default is true. expandFirstColumn?: boolean // Padding around each cell. Default is 'medium'. padding?: 'none' | 'small' | 'medium' | 'large' // If true, the headers will be bolded. Default is true. boldHeaders?: boolean // Optional class name to apply to the table container. className?: string } export const Table = ({ headers, rows, expandFirstColumn = true, padding = 'medium', boldHeaders = true, className, }: TableProps) => { const numColumns = Math.max(headers.length, ...rows.map((row) => row.length)) const paddingClass = { none: '', small: 'p-2', medium: 'p-4', large: 'p-6', }[padding] return (
'auto'), ].join(' '), }} > {headers.map((header, index) => (
{header}
))} {rows.flatMap((row, rowIndex) => row.map((item, colIndex) => (
0 && 'border-l border-border-secondary', typeof item === 'object' && item && 'className' in item && item.className )} > {item}
)) )}
) }