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 (