Skip to content

Table

Table is a token-styled data table with declarative columns, for the tabular list surfaces (CRM contacts, deals) that simple rows don’t fit. It renders a real <table> for semantics, with a sticky header and rows that hover-tint and can be clickable. Sorting, selection, and virtualization are out of scope; compose Pagination for paging. The preview below is the real component from @nimblebrain/synapse/ui, live.

import { Table, type Column } from "@nimblebrain/synapse/ui";
const columns: Column<Person>[] = [
{ key: "name", header: "Name", render: (p) => p.name },
{ key: "deals", header: "Deals", align: "right", render: (p) => p.deals },
];
<Table data={people} columns={columns} rowKey={(p) => p.id} />;

Each column is declared once. Pass onRowClick to make rows clickable and keyboard-operable, and empty to render a placeholder when data is empty.

<Table
data={people}
columns={columns}
rowKey={(p) => p.id}
onRowClick={(p) => open(p)}
empty={<EmptyState title="No contacts yet" />}
/>

An app renders in a pane whose width the host controls. Give columns a priority and the table fits whatever width it gets: when the columns do not fit, the column with the highest priority number hides first (1 is the most important), and its value moves under the first column’s content, named by the column’s label.

const columns: Column<Deal>[] = [
{ key: "name", header: "Deal", width: 160, render: (d) => d.name },
{ key: "stage", header: "Stage", priority: 2, render: (d) => <Badge>{d.stage}</Badge> },
{ key: "amount", header: "Amount", priority: 1, align: "right", render: (d) => d.amount },
{ key: "updated", header: "Updated", priority: 3, render: (d) => d.updated },
{ key: "open", header: "", label: "Open", render: (d) => <OpenButton deal={d} /> },
];
  • The primary column is the one that declares primary, else the first. It takes the space the others leave and truncates with an ellipsis; a width on it is the narrowest it gets. It never hides, and the hidden columns’ values sit under it. Name it with primary when the first column is something else, such as a row checkbox.
  • A column without a priority never hides, so action and selection columns stay.
  • The browser measures the fit before paint, so there is no pixel budget to declare. A hidden column comes back once the pane is wide enough to hold it.
  • A hidden column’s sort control, if its header holds one, hides with it.
  • If the table is still too wide once every column that may hide is hidden, it scrolls inside its own container when minWidth is set, and overflows otherwise.

With no priority on any column, every column always shows: declare a width on any column that truncates (that switches the table to fixed layout), and a minWidth below which it scrolls. That mode suits a table whose columns must all stay.

Prop Type Default
data T[] None
columns Column<T>[] None
rowKey (row: T, index: number) => string | number None
onRowClick (row: T, index: number) => void None
empty ReactNode None
minWidth number | string None
…rest HTMLAttributes<HTMLTableElement> None

Each entry in columns describes one column.

Field Type Default
key string None
header ReactNode None
render (row: T, index: number) => ReactNode None
align "left" | "right" | "center" "left"
width number | string None
priority number None (never hides)
label string header, when it is a string
primary boolean The first column is primary
  • Pagination: page a long table.
  • ListRow: a lighter row for non-tabular lists.
  • Badge: render inside a status column.