import type { ReactNode } from "react"; import type { SortState } from "@/lib/types"; /* * Reduced from OnCo src/components/filters/ResultsTable.tsx * https://github.com/judegomila/OnCo @ b594d7433bf4e408b44215e25e5304696d6f840e * Copyright (c) 2026 OnCo. MIT License. See ui/NOTICE. * * The parent owns sorting. This table does not filter, resize, translate, or page. */ export type Column = { key: string; label: string; render: (row: T) => ReactNode; sortable?: boolean; }; export function ResultsTable({ columns, rows, rowKey, sort, onSort, empty = "No records.", }: { columns: Column[]; rows: readonly T[]; rowKey: (row: T) => string; sort?: SortState; onSort?: (key: string) => void; empty?: string; }) { return (
{columns.map((column) => { const sorted = sort?.key === column.key; const direction = sort?.dir === -1 ? "descending" : "ascending"; return ( ); })} {rows.length === 0 ? ( ) : ( rows.map((row) => ( {columns.map((column) => ( ))} )) )}
{empty}
{column.render(row)}
); } function ColumnHead({ column, sort, onSort, }: { column: Column; sort?: SortState; onSort?: (key: string) => void; }) { if (!column.sortable || !onSort) return <>{column.label}; const sorted = sort?.key === column.key; const title = sorted ? sort?.dir === -1 ? `Sorted descending by ${column.label}` : `Sorted ascending by ${column.label}` : `Sort by ${column.label}`; return ( ); }