Skip to Content

Table

A brandless data table wrapping native <table>, <thead>, and <tbody> elements. Accepts typed column definitions and data rows. All visual styling is driven by CSS custom properties.

Usage

import { Table } from '@froglet/ui' import type { TableColumn } from '@froglet/ui' type Row = { name: string; role: string; status: string } const columns: TableColumn<Row>[] = [ { key: 'name', label: 'Name' }, { key: 'role', label: 'Role' }, { key: 'status', label: 'Status' }, ] const data: Row[] = [ { name: 'Alice Martin', role: 'Engineer', status: 'Active' }, { name: 'Bob Chen', role: 'Designer', status: 'Active' }, ] <Table columns={columns} data={data} caption="Team members" /> // Themed <Table className="table--froglet" columns={columns} data={data} caption="Team members" /> // Custom cell render const columns: TableColumn<Row>[] = [ { key: 'name', label: 'Name' }, { key: 'status', label: 'Status', render: (value) => <strong>{String(value)}</strong>, }, ]

Props

TableProps<T>

PropTypeDefaultDescription
columnsTableColumn<T>[]Column definitions. Order determines column order.
dataT[]Data rows.
captionstringTable caption. Recommended for screen readers.
classNamestringAdditional CSS classes. Use to apply a token block.
refReact.Ref<HTMLTableElement>Forwarded to the underlying <table>.

TableColumn<T>

PropTypeDefaultDescription
keykeyof T & stringColumn key. Must match a property key of T.
labelstringkeyColumn header text. Falls back to key if omitted.
render(value: T[keyof T], row: T) => ReactNodeOptional cell renderer. Defaults to String(value ?? "").

CSS Custom Properties

TokenDefaultDescription
--table-width100%Table width.
--table-border-collapsecollapseBorder collapse mode.
--table-font-size1remBase font size.
--table-border-colorOuter border color. No border when unset.
--table-th-padding0.75rem 1remHeader cell padding.
--table-th-font-weight600Header cell font weight.
--table-th-background-colorHeader cell background.
--table-th-text-colorHeader cell text color.
--table-th-border-bottom-width2pxHeader cell bottom border width.
--table-th-border-bottom-colorcurrentColorHeader cell bottom border color.
--table-tr-background-color-evenEven row background (striping).
--table-tr-background-color-oddOdd row background (striping).
--table-td-padding0.75rem 1remBody cell padding.
--table-td-text-colorBody cell text color.
--table-td-border-bottom-width1pxBody cell bottom border width.
--table-td-border-bottom-colorcurrentColorBody cell bottom border color.
--table-caption-font-size0.875remCaption font size.
--table-caption-text-colorCaption text color.

Accessibility

  • <caption> provides a table title for screen readers. Recommended when multiple tables are on the same page.
  • Each <th> has scope="col" so screen readers associate headers with their columns.
Last updated on