// Table-Basis-Komponente — SHL-01. WCAG: semantische , scope auf Kopfzellen, sortierbare Spalten per Tastatur. import type { ReactNode } from "react"; import { useI18n } from "../i18n/i18n"; export interface TableColumn { key: string; header: string; render: (row: Row) => ReactNode; sortable?: boolean; } export interface TableProps { columns: TableColumn[]; rows: Row[]; rowKey: (row: Row) => string; sortKey?: string; sortDirection?: "asc" | "desc"; onSort?: (key: string) => void; caption?: string; } export function Table({ columns, rows, rowKey, sortKey, sortDirection, onSort, caption, }: TableProps) { const { t } = useI18n(); return (
{caption && } {columns.map((column) => { const isSorted = column.key === sortKey; const ariaSort = column.sortable ? isSorted ? sortDirection === "asc" ? "ascending" : "descending" : "none" : undefined; return ( ); })} {rows.length === 0 ? ( ) : ( rows.map((row) => ( {columns.map((column) => ( ))} )) )}
{caption}
{column.sortable ? ( ) : ( column.header )}
{t("shl.table.noRows")}
{column.render(row)}
); }