4.2.0
Patterns

DataTable

A dense grid driven by column definitions instead of markup — for rows a reader scans and picks one of, not a table they read down.

Default

Columns are data, so the grid never learns what a row means: one object per column, `cell` reading whatever it needs off the row, and a `StatusPill` in one of them because colour arrives only through what a caller renders. Click a row to select it.

Services · 6

Usage

import { DataTable } from '@oceanic-hub/brand-system'

columns is data — { id, header, cell }, with cell handed the whole row — and that one choice is the whole component. The package owns the grid: one header rule, one row rule, the hover and selection tints, and a collapse below md where every cell takes its own full-width line, in column order, which is the only stacking something that does not know your columns can defend. The caller owns every cell, so the same grid is legal over services, invoices or runs without the package learning any of those words.

rowKey has no fallback to row.id: a design system that guesses at a field name on your data is the bug this component exists to undo. selectedKey names ONE row — the "which record is open in the detail pane" highlight, not a tally — and with no onSelectRow the rows stay divs instead of buttons, so the surface advertises no affordance it does not have. For a bulk selection, add a leading column whose cell renders a Checkbox and keep the set yourself; those rows must stay read-only, because a checkbox inside a row-button is a button inside a button. empty is where an Empty region goes — that component owns the medallion, the sentence and the action; this one only decides where it sits. Omit it and a wordless placeholder is drawn instead.

A column list holds functions, so it cannot cross the server/client boundary as a prop: put the grid (and its columns) in a 'use client' component.

Table's page draws the primitive/composite line from its own side; this is the other half of it. Reach for that one whenever you want the markup — real tabular semantics, a colSpan that means what it says, a cell that holds anything. Reach for this one when the rows are records to pick from and the shape is always the same. And when the rows do not share one header at all — a settings list, a set of unrelated records — neither of these is the shape; that is Item, which is how its own note puts the same test.

shadcn has no DataTable to port. What its data-table page documents is the recipe Table's page points at: column definitions and a table hook from a library, and then sorting, filtering, pagination, column visibility, bulk selection and three helper components of the reader's own, assembled by hand. columns is the one piece of that we own, because a column list is a design decision; every other piece is product behaviour, and it lands here as:

  • sorting — sortable on a column draws its header as a button with a direction indicator and aria-sort; sort/onSortChange carry and report state. The comparator is still yours, shown below — only the caller knows that a cell reading €48.00 sorts as 48, so the package draws the affordance and never reorders rows itself;
  • reordering by hand — not in upstream's recipe at all, and the opposite of sorting: the order IS the data, a stored rank no comparator would reproduce. onReorder(key, toIndex) turns it on and reports the move; you splice your own array, exactly as you own the comparator. toIndex indexes rows as passed — hand the table a filtered or paged slice and the index is into that slice, so mapping it back to the full collection is yours; the table never saw what you left out. reorderable picks the control — 'drag' (the default), 'buttons' or 'both' — because the right one is a property of the surface: two arrows suit a ten-row list, a grip suits a long one. The grip is a real button carrying a keyboard model (space to pick up, arrows to move, space to drop, escape to cancel) and a live region, which is what makes drag safe to default to; a handle that is only a pointer gesture is unreachable by keyboard and unusable on touch. reorderIcon swaps the glyph, and false removes it and makes the row itself the handle; reorderLabel names the control per row. Refused over groups by type — a target index in a grouped table means either "within this group" or "across the table", and the package does not know what your groups mean; use one flat table per section. Refused beside onSelectRow for the reason below;
  • grouping — groups is an exclusive alternative to rows (passing both is a type error): an array of { id, heading, rows }, one heading per group, in the same grid. A group with no rows is skipped rather than drawn hollow;
  • expanding a row — rowDetail is a function of the row, like cell, so it layers over either row source instead of being a third one; expandedKeys/onExpandedChange carry and report the open set, and expandLabel names each trigger for a screen reader. The package owns the disclosure column, the trigger, its aria-expanded and the detail region — which is a full-width sibling of the grid rather than a cell in it, so there is no colSpan to get wrong and no column to break, at md or in the collapse below it. A row with nothing to disclose returns null and keeps its place in the column. It is the one place where a row's own click had to give way: rowDetail and onSelectRow are exclusive by type, because the trigger would otherwise sit inside a row-button — the same button-inside-a-button this note refuses above for a checkbox and for an action menu. Keep the click and you own the disclosure instead: put your own trigger in a cell, and the aria-expanded wiring with it;
  • filtering — rows, already filtered. FilterBar is the surface that does it;
  • paging — rows, already sliced. Pagination sits beneath the grid as a sibling, never inside it, and its own page shows that join;
  • column visibility — the columns array, filtered. There is no visible flag, because hiding a column and not passing one are the same thing;
  • sizing — width is a CSS grid track, so density stays the caller's decision even though it is declared in the column object rather than in markup;
  • bulk selection — the Checkbox column above. There is no multi-select prop.

RTL is not supported. Upstream's recipe closes with an RTL section; we ship none, because nothing in this package has ever been laid out or measured right-to-left. The refusal is package-wide, recorded in pairings.json under direction (@OCE-1779).

Sortable columns

sortable on a column draws its header as a button with a direction indicator and aria-sort — the package owns that affordance now, so consumers stop hand-rolling the same button and chevron. The comparator stays yours: sort only names which column and which direction, onSortChange only reports which header was clicked, and the caller still decides that a cell reading €48.00 sorts as 48.

Services
  • apieu-west-1€48.00
  • workereu-west-1€24.00
  • apieu-west-1€12.00
  • edgeglobal€6.40
  • workereu-west-1€6.00
  • docsglobal€1.20

Row actions

Give the last column a fixed track, align="end" and headerHidden, so it reserves its space and still announces its name to a screen reader while the header row stays free of a word that would only ever read as noise. Reach for it when a row has more verbs than fit — and leave onSelectRow off, because a menu trigger inside a row-button is a button inside a button.

Services
  • apiproduction14:02
  • workerproduction13:57
  • edgeproduction11:20
  • apistaging09:41

Empty and read-only

With no onSelectRow a row is a div, not a button — the surface advertises no affordance it does not have. The empty sentence is the caller's, because a package default has to pick a language; a whole Empty region goes in the same slot when the state has earned a medallion and an action rather than one line.

Staging services

No services in this environment yet.

Grouped rows

groups replaces rows as an exclusive alternative — the package draws one heading per group and skips a group with no rows rather than rendering it hollow, so a group left empty by a filter just disappears instead of floating a heading over nothing. Grouping itself is the caller's, same as sorting above: the package draws the heading, never decides what a group means.

Services
  • production
  • apieu-west-1€48.00
  • workereu-west-1€24.00
  • edgeglobal€6.40
  • staging
  • apieu-west-1€12.00
  • workereu-west-1€6.00
  • preview
  • docsglobal€1.20

Expandable rows

rowDetail is a function of the row, exactly like cell — so it layers over whichever row source you already use instead of replacing it, and this one table is grouped, sortable and expandable at once. The package owns the disclosure column, the trigger and its aria-expanded, and draws the detail region as a full-width sibling of the grid rather than a cell in it; you own the set of open keys, the same way you own sort. A row with nothing to disclose returns null and keeps its place in the column.

Services
  • production
  • apiDone€48.00
  • edgeDone€6.40
  • workerWorking on it€24.00
  • staging
  • apiStuck€12.00
    Reason
    The provider refused the last deploy: the region quota was already spent.
    Next step
    Raise the quota, or move the service to a region with headroom, then redeploy.
  • workerDone€6.00
  • preview
  • docsWorking on it€1.20

Row exit on a destructive action

A confirmed removal fades, then its space collapses shut — never an instant disappearance, which reads as a glitch rather than a confirmation. Set the row's key into exitingKeys once the server confirms; the package animates and reports back through onExitComplete, which is the caller's own cue to finally drop the row from rows.

Services
  • apieu-west-1€48.00
  • workereu-west-1€24.00
  • edgeglobal€6.40
  • apieu-west-1€12.00

Manual reorder

When the order IS the data — a stored rank an operator arranges by hand — onReorder reports the move and you splice your own array, exactly as you own the comparator behind sort. reorderable picks the control: a drag grip (the default), two arrow buttons, or both. The grip is a real button with a keyboard model on it — space to pick up, arrows to move, escape to cancel — so the default costs no one the ability to use it. reorderIcon swaps the glyph or removes it, and with it removed the row itself becomes the handle.

Press space to pick this row up, the arrow keys to move it, space to drop it and escape to cancel.
Deploy order
  • apieu-west-1Done€48.00
  • workereu-west-1Working on it€24.00
  • edgeglobalDone€6.40
  • apieu-west-1Stuck€12.00
  • workereu-west-1Done€6.00
  • docsglobalWorking on it€1.20

API Reference

See the DataTable API page for every prop of every part, with types, defaults and the contract that pins them.

On this page