import type { ReactNode } from 'react'; export interface ComparisonColumn { /** Matches a key in every row's `cells`. */ key: string; header: string; /** * Marks the column the deck is arguing for. Exactly one column carries it; * if more than one does, only the first is honoured (see ComparisonTable.md). */ us?: boolean; } export interface ComparisonRow { id: string; cells: Record; } export interface ComparisonTableProps { /** The first column is normally the criterion being compared. */ columns: ComparisonColumn[]; rows: ComparisonRow[]; /** Mono uppercase line above the table saying what is being compared. */ caption?: string; className?: string; } /** The pack's comparison: a table with exactly one column marked as *us*. */ export function ComparisonTable({ columns, rows, caption, className }: ComparisonTableProps) { // First flagged column wins, so a second `us` cannot produce a second accent // column — the invariant lives here rather than in every caller. const usKey = columns.find((column) => column.us === true)?.key; return ( {caption !== undefined && } {columns.map((column) => ( ))} {rows.map((row) => ( {columns.map((column) => ( ))} ))}
{caption}
{column.header}
{row.cells[column.key]}
); }