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>
| Prop | Type | Default | Description |
|---|---|---|---|
columns | TableColumn<T>[] | — | Column definitions. Order determines column order. |
data | T[] | — | Data rows. |
caption | string | — | Table caption. Recommended for screen readers. |
className | string | — | Additional CSS classes. Use to apply a token block. |
ref | React.Ref<HTMLTableElement> | — | Forwarded to the underlying <table>. |
TableColumn<T>
| Prop | Type | Default | Description |
|---|---|---|---|
key | keyof T & string | — | Column key. Must match a property key of T. |
label | string | key | Column header text. Falls back to key if omitted. |
render | (value: T[keyof T], row: T) => ReactNode | — | Optional cell renderer. Defaults to String(value ?? ""). |
CSS Custom Properties
| Token | Default | Description |
|---|---|---|
--table-width | 100% | Table width. |
--table-border-collapse | collapse | Border collapse mode. |
--table-font-size | 1rem | Base font size. |
--table-border-color | — | Outer border color. No border when unset. |
--table-th-padding | 0.75rem 1rem | Header cell padding. |
--table-th-font-weight | 600 | Header cell font weight. |
--table-th-background-color | — | Header cell background. |
--table-th-text-color | — | Header cell text color. |
--table-th-border-bottom-width | 2px | Header cell bottom border width. |
--table-th-border-bottom-color | currentColor | Header cell bottom border color. |
--table-tr-background-color-even | — | Even row background (striping). |
--table-tr-background-color-odd | — | Odd row background (striping). |
--table-td-padding | 0.75rem 1rem | Body cell padding. |
--table-td-text-color | — | Body cell text color. |
--table-td-border-bottom-width | 1px | Body cell bottom border width. |
--table-td-border-bottom-color | currentColor | Body cell bottom border color. |
--table-caption-font-size | 0.875rem | Caption font size. |
--table-caption-text-color | — | Caption text color. |
Accessibility
<caption>provides a table title for screen readers. Recommended when multiple tables are on the same page.- Each
<th>hasscope="col"so screen readers associate headers with their columns.
Last updated on