Table
Chrome for a data table. You write the thead, tbody, tr, th and td
yourself; Table styles them and puts the whole thing in a box that scrolls
sideways when it has to.
import { Table } from "antlitz";
API
| Prop | Type | Default |
|---|
| radius | "none" | "sm" | "md" | "lg" | "full" | none |
| size | "sm" | "md" | "lg" | md |
| variant | "outline" | "plain" | outline |
There is no TableRow or TableCell here. Table styles native markup through
descendant selectors, the same way the Typeset stylesheet styles a table that
arrives from a CMS — one component instead of seven, and colSpan, scope,
tfoot and the rest keep working because they were never taken away.
className styles the box; every other prop reaches the table. Cell rules
live on the box too, so an override merges with them rather than fighting
them.
<Table className="my-6 [&_td]:px-6">
Usage
| Quarter | Revenue | Change |
|---|
| Q1 | 120,400 | +4% |
| Q2 | 138,900 | +15% |
| Q3 | 131,200 | −6% |
export function Basic() {
return (
<Table>
<thead>
<tr>
<th>Quarter</th>
<th>Revenue</th>
<th>Change</th>
</tr>
</thead>
<tbody>
{ROWS.map((row) => (
<tr key={row.quarter}>
<td>{row.quarter}</td>
<td>{row.revenue}</td>
<td>{row.change}</td>
</tr>
))}
</tbody>
</Table>
);
}
Variants
export function Variants() {
return VARIANTS.map((variant) => (
<Table key={variant} variant={variant}>
<tbody>
<tr>
<td>{variant}</td>
</tr>
</tbody>
</Table>
));
}
plain drops the outer border for a table that sits inside a Card or
another container that already has one.
Sizes
export function Sizes() {
return SIZES.map((size) => (
<Table key={size} size={size}>
<tbody>
<tr>
<td>{size}</td>
</tr>
</tbody>
</Table>
));
}
Size sets cell padding. It leaves the text size alone, so a table matches the
density of the page rather than shifting its type.
Radius
export function Radius() {
return RADII.map((radius) => (
<Table key={radius} radius={radius}>
<tbody>
<tr>
<td>{radius}</td>
</tr>
</tbody>
</Table>
));
}
Rounding lives on the box rather than the table. A border-collapse table
cannot clip its own corners — the cells in them spill past the curve — which
is why the box exists at all.
Caption and alignment
Revenue by quarter, in euros| Quarter | Revenue |
|---|
| Q1 | 120,400 |
| Q2 | 138,900 |
| Q3 | 131,200 |
export function Caption() {
return (
<Table>
<caption>Revenue by quarter, in euros</caption>
<thead>
<tr>
<th>Quarter</th>
<th className="text-end">Revenue</th>
</tr>
</thead>
<tbody>
{ROWS.map((row) => (
<tr key={row.quarter}>
<td>{row.quarter}</td>
<td className="text-end tabular-nums">{row.revenue}</td>
</tr>
))}
</tbody>
</Table>
);
}
A caption is the table's accessible name and is announced before its
contents, which beats a heading above it that nothing connects.
Alignment is per cell: numbers read better against the end edge, and
tabular-nums keeps the digits in columns.
Rendered tables
Table is for markup you author. For a table inside long-form content — a
markdown file, a CMS field — the Typeset stylesheet already styles the same
elements, and no component is involved.