import { type ComponentType, Fragment, type ReactNode } from 'react'; import { cn } from '@/lib/utils'; import { Text } from '../Text'; type ComponentMatrixCellProps = { column: ComponentMatrixColumn; row: ComponentMatrixRow; }; type ComponentMatrixColumn = { description?: string; key: string; label: string; }; type ComponentMatrixProps = { Cell: ComponentType; cellClassName?: string; cellWidth?: string; className?: string; columns: ComponentMatrixColumn[]; rows: ComponentMatrixRow[]; }; type ComponentMatrixRow = { description?: string; key: string; label: string; }; function Layout({ children, className, title, }: { children: ReactNode; className?: string; title: string; }) { return (
{title}
{children}
); } function Matrix({ Cell, cellClassName, cellWidth = 'minmax(12rem, 1fr)', className, columns, rows, }: ComponentMatrixProps) { const resolvedCellWidth = cellWidth.includes('fr') || cellWidth.includes('minmax(') ? cellWidth : `minmax(${cellWidth}, 1fr)`; return (
{columns.map((column, columnIndex) => (
{column.label}
{column.description ? (
{column.description}
) : null}
))} {rows.map((row, rowIndex) => (
{row.label}
{row.description ? (
{row.description}
) : null}
{columns.map((column, columnIndex) => (
))}
))}
); } function Section({ children, title }: { children: ReactNode; title: string }) { return (
{title} {children}
); } const Story = Object.assign(Layout, { Layout, Matrix, Section, }); export { Story }; export type { ComponentMatrixCellProps, ComponentMatrixColumn, ComponentMatrixRow, };