import { useId } from 'react'; import type { ReactNode } from 'react'; export interface ComparisonColumn { /** Matches a key in every row's `cells`. */ key: string; header: string; /** The one column floated out as a card. The pack allows exactly one. */ us?: boolean; } export interface ComparisonRow { id: string; /** Keyed by column `key`. The first column is the row's label. */ cells: Record; } export interface ComparisonTableProps { /** `columns[0]` is the label column; the rest are the things compared. */ columns: ComparisonColumn[]; rows: ComparisonRow[]; /** Says what is being compared. Rendered above the panel and names it. */ caption?: string; className?: string; } /** * A wide cream panel of 1px-ruled rows with the "us" column lifted out of it as * a rounded card in the accent gradient — a physical card laid on a printed * table. * * The panel is a grid rather than a `` because the card is one element * spanning every row, which is what makes it read as a single object instead of * a column of separately tinted cells. Rows are `display: contents` and every * cell is placed explicitly, so the card can sit underneath them all. */ export function ComparisonTable({ columns, rows, caption, className }: ComparisonTableProps) { const captionId = useId(); const usIndex = columns.findIndex((column) => column.us === true); return (
{caption !== undefined && (

{caption}

)}
{usIndex >= 0 && (
); }