Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / Feedback and display

Table

Rows of data with headers. Columns can sort, rows can be selected, and the header can stay in view while the body scrolls.

Asemantic table

When to useLink to "When to use"

  • Records with the same fields, read across and compared down: members, invoices, logs.

Use something else when:

UsageLink to "Usage"

tsx
Copy
import { Table } from "@arshad-shah/cynosure";

<Table caption="Team members" rows={members} getRowId={(m) => m.id} columns={columns} />

A column shows row[key] unless it has a cell function. align: "end" lines numbers up.

SortingLink to "Sorting"

Mark columns sortable and their headers become buttons (a SortButton): ascending, then descending, then the original order. Sorting compares row[key] (or sortValue(row)): text in the locale's order, numbers as numbers, empty values last. Sort on a server with manualSort: the table then shows and reports the sort through onSortChange without reordering.

Sorting cycles and compares

SelectionLink to "Selection"

selectable adds a checkbox to each row (named after the row header, "Select Grace") and a select-all that is mixed when some rows are selected. Selected ids are reported in the rows' own order. Ids that are not in rows (another page, or filtered out) stay selected, listed first; the select-all acts on the rows shown.

Selecting rows

With stickyHeader the body scrolls inside the table up to --cy-table-max-height and the header stays in view. The scroller is a focusable region named by the caption, so keyboard users can scroll it.

Sticky header scrolls

PropsLink to "Props"

Every prop of Table
PropWhat it doesTypeDefault
captionRequired
The table's caption: its accessible name, shown above it unless captionHidden.ReactNode
columnsRequired
The columns, in display order.TableColumn<Row>[]
rowsRequired
The data, one entry per row.Row[]
getRowIdRequired
A stable id per row (for selection and React keys).(row: Row) => string
captionHidden
Hides the caption visually; it still names the table.boolean
sort
The current sort (controlled); null is unsorted.TableSort | null
defaultSort
Starting sort when uncontrolled; unsorted when left out.TableSort | null
onSortChange
Called when a sortable header is pressed, with the new sort, or null when it goes back to unsorted.((sort: TableSort | null) => void)
manualSort
You sort the rows (e.g. on a server); the table only shows and reports the sort.boolean
selectable
Adds a checkbox per row and a select-all in the header.boolean
selected
Ids of the selected rows (controlled).string[]
defaultSelected
Ids of the rows selected at the start when uncontrolled.string[]
onSelectionChange
Called when a row's checkbox or select-all changes, with the selected ids: those not in rows (another page, filtered out) first, then the shown ones in row order. Select-all acts on the shown rows only.((ids: string[]) => void)
stickyHeader
The header stays visible while the body scrolls inside the table.boolean
size
Cell padding and text size. Default "md".Size"md"
labels
Replace the built-in English text: the checkbox names and the empty message.Partial<TableLabels>
className
Added to the root element, for layout.string
style
Layout only. Restyle through --cy-table-* tokens.CSSProperties

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

  • Semantics: a native table with a caption; column headers, and a row header per row (the first column, or the one marked rowHeader), so screen readers announce context with every cell.
  • Sorting: sortable headers carry aria-sort and contain a button; Enter or Space sorts.
  • Selection: native checkboxes in the first column; Space toggles; the select-all reports "mixed".
  • Empty: one cell across all columns says so (labels.empty).
  • Touch: sort buttons have a 44px hit area on touch screens.
  • Contrast: headers, cells and selected rows keep 4.5:1 in light and dark modes.
  • Direction: columns follow the text direction; end-aligned cells sit at the inline end.

ThemingLink to "Theming"

Tokens: --cy-table-header-background, --cy-table-selected-background and --cy-table-max-height.

DescriptionList · Checkbox · Badge

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog