Table
A ruled data table. Compound: Table with Head, Body, Row, HeaderCell, Cell, and Caption, rendered on semantic table elements.
Cells share collapsed 1px rules and headers are uppercase micro-labels, so a table reads as a technical drawing rather than a spreadsheet.
Copy source
Requires: Nothing. Any bundler that understands .module.css.
This is the component, complete. Copy the files below into a ui/ folder at your project root and keep the folder structure — the imports between them are relative, so the paths have to come along. Each component imports its own .module.css, so its class names are scoped to it and cannot collide with your application's.
ui/components/Table/Table.tsximport { createContext, useContext } from "react";
import { cx } from "../../internal/cx";
import styles from "./table.module.css";
export interface TableProps
extends React.TableHTMLAttributes<HTMLTableElement> {
/** Pins the header row while the body scrolls. */
stickyHeader?: boolean;
/** Makes numeric columns use tabular figures. Applied to cells manually. */
numeric?: boolean;
/** Wraps the table in a horizontally scrollable square frame. */
scrollable?: boolean;
children: React.ReactNode;
}
/* A module cannot style a child from its parent, so the header treatment
travels by context to keep `<Table stickyHeader>` a single prop. */
const TableContext = createContext<{ stickyHeader: boolean }>({
stickyHeader: false,
});
function TableRoot({
stickyHeader = false,
scrollable = false,
className,
children,
...rest
}: TableProps): React.JSX.Element {
const table = (
<table className={cx(styles.table, className)} {...rest}>
{children}
</table>
);
return (
<TableContext.Provider value={{ stickyHeader }}>
{scrollable ? (
<div className={styles.scroll}>{table}</div>
) : (
table
)}
</TableContext.Provider>
);
}
function Head({
className,
children,
...rest
}: React.HTMLAttributes<HTMLTableSectionElement>): React.JSX.Element {
return (
<thead className={cx(styles.head, className)} {...rest}>
{children}
</thead>
);
}
function Body({
className,
children,
...rest
}: React.HTMLAttributes<HTMLTableSectionElement>): React.JSX.Element {
return (
<tbody className={cx(styles.body, className)} {...rest}>
{children}
</tbody>
);
}
function Row({
className,
selected = false,
children,
...rest
}: React.HTMLAttributes<HTMLTableRowElement> & { selected?: boolean }): React.JSX.Element {
return (
<tr
className={cx(styles.row, selected && styles.rowSelected, className)}
aria-selected={selected || undefined}
{...rest}
>
{children}
</tr>
);
}
interface CellProps extends React.TdHTMLAttributes<HTMLTableCellElement> {
/** Right-aligns and uses tabular figures. Use for money and counts. */
numeric?: boolean;
}
function HeaderCell({
className,
numeric = false,
children,
...rest
}: CellProps & React.ThHTMLAttributes<HTMLTableCellElement>): React.JSX.Element {
const { stickyHeader } = useContext(TableContext);
return (
<th
scope="col"
className={cx(
styles.cell,
styles.cellHead,
stickyHeader && styles.cellHeadSticky,
numeric && styles.numeric,
className,
)}
{...rest}
>
{children}
</th>
);
}
function Cell({
className,
numeric = false,
children,
...rest
}: CellProps): React.JSX.Element {
return (
<td
className={cx(styles.cell, numeric && styles.numeric, className)}
{...rest}
>
{children}
</td>
);
}
function Caption({
className,
children,
...rest
}: React.HTMLAttributes<HTMLTableCaptionElement>): React.JSX.Element {
return (
<caption className={cx(styles.caption, className)} {...rest}>
{children}
</caption>
);
}
export const Table = Object.assign(TableRoot, {
Head,
Body,
Row,
HeaderCell,
Cell,
Caption,
/** Put this on a cell that holds an identifier — mono, small, tracked. */
mono: styles.mono,
});ui/components/Table/table.module.css/* Table — a collapsed 1px grid. Headers are uppercase micro-labels. */
.scroll {
width: 100%;
overflow-x: auto;
border: var(--fr-rule-width) solid var(--fr-rule);
border-radius: var(--fr-radius);
background: var(--fr-surface);
}
.table {
width: 100%;
border-collapse: collapse;
font-size: var(--fr-text-small);
text-align: left;
}
.caption {
caption-side: bottom;
padding: var(--fr-space-2) var(--fr-space-3);
font-size: var(--fr-text-micro);
color: var(--fr-ink-subtle);
text-align: left;
border-top: var(--fr-rule-width) solid var(--fr-rule-soft);
}
.cell {
padding: var(--fr-space-3);
border-bottom: var(--fr-rule-width) solid var(--fr-rule-soft);
vertical-align: middle;
color: var(--fr-ink);
line-height: 1.4;
}
.body .row:last-child > .cell {
border-bottom: 0;
}
/* Header cells: uppercase, tracked, ruled against the body with ink. */
.cellHead {
position: relative;
top: 0;
z-index: 10;
background: var(--fr-surface-sunken);
border-bottom: var(--fr-rule-width) solid var(--fr-rule);
font-size: var(--fr-text-micro);
font-weight: var(--fr-weight-semibold);
letter-spacing: var(--fr-tracking-micro);
text-transform: uppercase;
color: var(--fr-ink-muted);
white-space: nowrap;
}
/* Only when the table asks for it: a header that always sticks is a header that
covers content in a short table. */
.cellHeadSticky {
position: sticky;
top: 0;
}
.row {
transition: background-color var(--fr-duration-fast) var(--fr-ease);
}
.body .row:hover {
background: var(--fr-surface-sunken);
}
.rowSelected,
.rowSelected:hover {
background: var(--fr-accent-soft);
}
.numeric {
text-align: right;
font-variant-numeric: tabular-nums;
font-feature-settings: "tnum" 1;
}
.mono {
font-family: var(--fr-font-mono);
font-size: var(--fr-text-micro);
letter-spacing: 0.01em;
}ui/internal/cx.tsexport type ClassValue = string | false | null | undefined;
// The only part of `clsx` this library needs, without the dependency.
export function cx(...values: ClassValue[]): string {
const out: string[] = [];
for (const value of values) {
if (value) out.push(value);
}
return out.join(" ");
}Every component reads from these two files. Copy them once, on your first component, and reuse them thereafter.
ui/styles/tokens.css
/* Every ground is white and every value below cleared AA on it; dark mode
re-derives rather than inverting. Check contrast again before changing a value. */
:root {
/* The only radius token. Do not override per component. */
--fr-radius: 0px;
/* Core surfaces — flat by default; separation comes from rules, not fills. */
--fr-paper: #ffffff;
--fr-surface: #ffffff;
--fr-surface-sunken: #f5f5f5;
--fr-ink: #262626;
--fr-ink-muted: #525252;
--fr-ink-subtle: #737373;
/* Rules — soft divides, rule bounds, strong marks a control edge. A boundary
is a hairline tone; only controls and active markers earn the ink one. */
--fr-rule: #e5e5e5;
--fr-rule-strong: #262626;
--fr-rule-soft: #ededed;
/* Accent: Emerald. Reserved for interaction, never decoration. `bright` is
ornament only — marks and arrows, never a label or a fill that carries one. */
--fr-accent: #047857;
--fr-accent-ink: #ffffff;
--fr-accent-soft: #ecfdf5;
--fr-accent-hover: #065f46;
--fr-accent-bright: #10b981;
/* Status. Success stays a true green rather than a second emerald, so a badge
tone never reads as the accent. */
--fr-danger: #a81f24;
--fr-danger-soft: #fbeaeb;
--fr-danger-ink: #ffffff;
--fr-success: #15803d;
--fr-success-soft: #f0fdf4;
--fr-success-ink: #ffffff;
--fr-warning: #7a5312;
--fr-warning-soft: #f8efdf;
--fr-warning-ink: #ffffff;
/* Inverse surfaces */
--fr-inverse-surface: #262626;
--fr-inverse-ink: #ffffff;
/* Disabled */
--fr-disabled-surface: #f0f0f0;
--fr-disabled-ink: #737373;
/* Hard shadow: no blur, ever. */
--fr-shadow-hard: 3px 3px 0 var(--fr-rule-strong);
--fr-shadow-hard-sm: 2px 2px 0 var(--fr-rule-strong);
/* No font ships with the library, so this is the platform's own UI face. */
--fr-font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
Arial, sans-serif;
--fr-font-mono: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
--fr-text-display: 3.5rem;
--fr-text-h1: 2.5rem;
--fr-text-h2: 1.75rem;
--fr-text-h3: 1.25rem;
--fr-text-body: 0.9375rem;
--fr-text-small: 0.8125rem;
--fr-text-micro: 0.6875rem;
--fr-leading-display: 1.02;
--fr-leading-heading: 1.15;
--fr-leading-body: 1.6;
--fr-tracking-micro: 0.08em;
--fr-tracking-display: -0.02em;
--fr-weight-regular: 400;
--fr-weight-medium: 500;
--fr-weight-semibold: 600;
--fr-weight-bold: 700;
/* Spacing scale — 4px base */
--fr-space-0: 0;
--fr-space-1: 0.25rem;
--fr-space-2: 0.5rem;
--fr-space-3: 0.75rem;
--fr-space-4: 1rem;
--fr-space-5: 1.5rem;
--fr-space-6: 2rem;
--fr-space-7: 3rem;
--fr-space-8: 4rem;
--fr-space-9: 6rem;
/* Sizing */
--fr-control-sm: 1.75rem;
--fr-control-md: 2.25rem;
--fr-control-lg: 2.75rem;
--fr-rule-width: 1px;
--fr-rule-width-strong: 2px;
--fr-focus-width: 2px;
--fr-focus-offset: 2px;
/* Motion — short and linear; this library does not bounce. */
--fr-duration-fast: 90ms;
--fr-duration-base: 140ms;
--fr-ease: cubic-bezier(0.2, 0, 0, 1);
/* Layers */
--fr-z-sticky: 10;
--fr-z-overlay: 100;
--fr-z-dialog: 101;
/* Layout */
--fr-container: 78rem;
--fr-measure: 68ch;
}
/* Dark re-derives rather than inverting: the ground stays near-black and the
accent lifts so it still clears AA (#34D399 on #0A0A0A is 10.33:1). */
[data-theme="dark"] {
--fr-paper: #0a0a0a;
--fr-surface: #141414;
--fr-surface-sunken: #1c1c1c;
--fr-ink: #f5f5f5;
--fr-ink-muted: #a3a3a3;
--fr-ink-subtle: #7a7a7a;
--fr-rule: #3a3a3a;
--fr-rule-strong: #f5f5f5;
--fr-rule-soft: #2a2a2a;
--fr-accent: #34d399;
--fr-accent-ink: #022c22;
--fr-accent-soft: #052e22;
--fr-accent-hover: #6ee7b7;
--fr-accent-bright: #34d399;
--fr-danger: #fca5a5;
--fr-danger-soft: #2e1214;
--fr-danger-ink: #240708;
--fr-success: #86efac;
--fr-success-soft: #0d2415;
--fr-success-ink: #04150c;
--fr-warning: #e2b262;
--fr-warning-soft: #2a2011;
--fr-warning-ink: #1c1305;
--fr-inverse-surface: #f5f5f5;
--fr-inverse-ink: #0a0a0a;
--fr-disabled-surface: #1f1f1f;
--fr-disabled-ink: #6a6a6a;
--fr-shadow-hard: 3px 3px 0 #f5f5f5;
--fr-shadow-hard-sm: 2px 2px 0 #f5f5f5;
}
/* Opt-in inverse region: use for a closing band or a deliberate contrast strip. */
[data-theme="inverse"] {
--fr-paper: #171717;
--fr-surface: #171717;
--fr-surface-sunken: #242424;
--fr-ink: #ffffff;
--fr-ink-muted: #b5b5b5;
--fr-ink-subtle: #8a8a8a;
--fr-rule: #3d3d3d;
--fr-rule-strong: #ffffff;
--fr-rule-soft: #2e2e2e;
--fr-accent: #34d399;
--fr-accent-ink: #022c22;
--fr-accent-soft: #052e22;
--fr-accent-hover: #6ee7b7;
--fr-accent-bright: #34d399;
--fr-inverse-surface: #ffffff;
--fr-inverse-ink: #171717;
--fr-shadow-hard: 3px 3px 0 #ffffff;
--fr-shadow-hard-sm: 2px 2px 0 #ffffff;
}
@media (prefers-reduced-motion: reduce) {
:root {
--fr-duration-fast: 0ms;
--fr-duration-base: 0ms;
}
}ui/styles/base.css
/* Only what a module cannot scope: the page reset. Everything a component owns
lives in its .module.css, so no global class here can collide with yours. */
*,
*::before,
*::after {
box-sizing: border-box;
}
html {
-webkit-text-size-adjust: 100%;
text-size-adjust: 100%;
}
body {
margin: 0;
font-family: var(--fr-font-sans);
font-size: var(--fr-text-body);
line-height: var(--fr-leading-body);
color: var(--fr-ink);
background: var(--fr-paper);
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
h1,
h2,
h3,
h4,
h5,
h6,
p,
figure,
blockquote,
dl,
dd {
margin: 0;
}
ul,
ol {
margin: 0;
padding: 0;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-weight: var(--fr-weight-semibold);
line-height: var(--fr-leading-heading);
letter-spacing: -0.02em;
text-wrap: balance;
}
a {
color: var(--fr-accent);
text-decoration-thickness: 1px;
text-underline-offset: 2px;
}
a:hover {
color: var(--fr-accent-hover);
}
img,
svg,
video,
canvas {
display: block;
max-width: 100%;
}
button,
input,
select,
textarea {
font: inherit;
color: inherit;
letter-spacing: inherit;
}Then import the component from its file. A page that holds state needs "use client".
/* app/layout.tsx — once, before your own CSS */
import "../ui/styles/tokens.css";
import "../ui/styles/base.css";// app/page.tsx
"use client";
import { Table } from "../ui/components/Table/Table";Basic
| ID | Recipe | Status | Uses |
|---|---|---|---|
| FR-104 | Button | Stable | 412 |
| FR-118 | Input | Stable | 388 |
| FR-131 | Tabs | Stable | 96 |
| FR-140 | Combobox | Experimental | 12 |
| FR-152 | Date picker | Planned | 0 |
numeric right-aligns a cell and switches it to tabular figures, so digits line up down the column. Use it for every number that will be compared.
Sticky header
| ID | Recipe | Uses |
|---|---|---|
| FR-200 | Recipe 1 | 37 |
| FR-201 | Recipe 2 | 74 |
| FR-202 | Recipe 3 | 111 |
| FR-203 | Recipe 4 | 148 |
| FR-204 | Recipe 5 | 185 |
| FR-205 | Recipe 6 | 222 |
| FR-206 | Recipe 7 | 259 |
| FR-207 | Recipe 8 | 296 |
| FR-208 | Recipe 9 | 333 |
| FR-209 | Recipe 10 | 370 |
| FR-210 | Recipe 11 | 407 |
| FR-211 | Recipe 12 | 444 |
| FR-212 | Recipe 13 | 481 |
| FR-213 | Recipe 14 | 518 |
scrollable wraps the table in a square, horizontally scrollable frame. stickyHeader pins the header row to the top of its scroll container — note that this requires the container to scroll, so give the wrapper a maxHeight.
Selected rows
| Recipe | Uses |
|---|---|
| Button | 412 |
| Input — selected | 388 |
| Tabs | 96 |
selected applies the accent-soft background and sets aria-selected. Use it when rows correspond to rows in a second view — a master/detail layout.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| stickyHeader | boolean | false | Pins the header row within a scrolling container. |
| scrollable | boolean | false | Wraps the table in a horizontally scrollable frame. |
| numeric | boolean | false | Present on the type but applied per cell via HeaderCell/Cell numeric. |
Table.Row
| Prop | Type | Default | Description |
|---|---|---|---|
| selected | boolean | false | Highlights the row and sets aria-selected. |
Table.Cell / Table.HeaderCell
| Prop | Type | Default | Description |
|---|---|---|---|
| numeric | boolean | false | Right-aligns and uses tabular figures. |
| scope | 'col' | 'row' | col | HeaderCell only. Use row for a row header. |
Accessibility
- Semantic elements throughout:
<table>,<thead>,<tbody>,<tr>,<th>,<td>,<caption>. No ARIA roles are required or applied for structure — the browser supplies the table semantics. Table.HeaderCellsetsscope="col"by default, which is what lets a screen reader associate a cell with its column header.Table.Captionis the accessible name for the table. Pass a caption even if you hide it visually — an unnamed table is announced as "table" with no context.- Hover highlighting is decorative only; no information is conveyed by hover.
- The sticky header maintains a solid background so rows do not show through it as they scroll.
Do and don't
numeric on every comparable number column.