Repository Public
1"use client";2import type { ReactNode } from "react";3import { cx } from "@/ui";45export interface RowColumn<T> {6 id: string;7 header: string;8 cell: (row: T) => ReactNode;9 align?: "right";10 shrink?: boolean;11 mono?: boolean;12 hide?: "sm" | "md";13 srOnlyHeader?: boolean;14}1516/**17 * Plain semantic table whose rows carry attributes (test ids, data-*). Same classes as the shared DataTable; used18 * where each row must be addressable (invitations, audit entries). No sorting: these lists are server-ordered.19 */20export function RowTable<T>({ caption, columns, rows, rowKey, rowProps, onRowClick, empty }: {21 caption: string;22 columns: RowColumn<T>[];23 rows: readonly T[];24 rowKey: (row: T) => string;25 rowProps?: (row: T) => Record<string, string | undefined>;26 onRowClick?: (row: T) => void;27 empty: ReactNode;28}) {29 return (30 <div className="mcc-table-wrap">31 <table className="mcc-table">32 <caption className="sr-only">{caption}</caption>33 <thead>34 <tr>35 {columns.map((c) => (36 <th key={c.id} scope="col" className={cx(c.align, c.shrink && "shrink", c.hide && `hide-${c.hide}`)}>37 {c.srOnlyHeader ? <span className="sr-only">{c.header}</span> : c.header}38 </th>39 ))}40 </tr>41 </thead>42 <tbody>43 {rows.length === 0 ? <tr><td colSpan={columns.length}>{empty}</td></tr> : null}44 {rows.map((row) => (45 <tr key={rowKey(row)} {...rowProps?.(row)} className={onRowClick ? "clickable" : undefined}46 onClick={onRowClick ? (e) => { if (!(e.target as HTMLElement).closest("a,button,input,label")) onRowClick(row); } : undefined}>47 {columns.map((c) => <td key={c.id} className={cx(c.align, c.align === "right" && "num", c.shrink && "shrink", c.mono && "mono", c.hide && `hide-${c.hide}`)}>{c.cell(row)}</td>)}48 </tr>49 ))}50 </tbody>51 </table>52 </div>53 );54}55