import clsx from 'clsx'; import React from 'react'; import { BlockVariant } from '../layout/Block'; // @todo: improve props to be exact export const TableHeader = ({ children, className, ...restProps }: React.HTMLAttributes) => ( {children} ); export const TableRow = ({ children, className, ...restProps }: React.HTMLAttributes) => ( {children} ); export const TableColHead = ({ children, className, ...restProps }: React.HTMLAttributes) => ( {children} ); export const TableBody = ({ children, className, ...restProps }: React.HTMLAttributes) => ( {children} ); export const TableCell = ({ children, className, ...restProps }: React.HTMLAttributes) => ( {children} ); export const TableFooter = ({ children, className, ...restProps }: React.HTMLAttributes) => ( {children} ); const TableCellWrapper = ({ as, children }: any) => React.createElement(as, null, children); // @todo: update type definitions properly type Column = { label: string }; type Row = { value: string; wrapper?: BlockVariant }; type Rows = Row[]; export interface TableProps extends React.HTMLAttributes { children?: React.ReactNode; data?: null | { columns: Column[]; rows: Rows[] }; } export const Table = ({ children, data = null, className, ...restProps }: TableProps) => ( {data ? ( <> {data.columns.map(({ label }: Column) => ( {label} ))} {data.rows.map((row: Row[], index: number) => ( {row.map(({ value, wrapper }: Row) => ( {wrapper ? ( {value} ) : ( value )} ))} ))} ) : ( <>{children} )}
); export default Table;