Lists things with the same attributes, such as tokens, users or webhooks.
import { Button, Menu, Table } from "@usememos/ui";
import { Ellipsis } from "lucide-react";
<Table.Root>
<Table.Caption>Access tokens</Table.Caption>
<Table.Header>
<Table.Row>
<Table.Head>Name</Table.Head>
<Table.Head>Created</Table.Head>
<Table.Head num>Uses</Table.Head>
<Table.Head><span className="mu-visually-hidden">Actions</span></Table.Head>
</Table.Row>
</Table.Header>
<Table.Body>
{tokens.map((token) => (
<Table.Row key={token.id}>
<Table.Cell>{token.name}</Table.Cell>
<Table.Cell muted>{token.created}</Table.Cell>
<Table.Cell num>{token.uses}</Table.Cell>
<Table.Cell num>
<Menu.Root>
<Menu.Trigger render={<Button variant="ghost" icon={<Ellipsis />} aria-label={`Actions for ${token.name}`} />} />
<Menu.Popup align="end">…</Menu.Popup>
</Menu.Root>
</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table.Root>No Base UI part: these are styled native table elements.
| Part | Renders |
|---|---|
Table.Root |
A <table> inside a <div> that scrolls sideways when the table is too wide. Takes size and bordered. The ref and props go to the <table> |
Table.Caption |
<caption>, under the table. Names it for screen readers |
Table.Header |
<thead> |
Table.Body |
<tbody> |
Table.Row |
<tr> |
Table.Head |
<th scope="col">. Takes num |
Table.Cell |
<td>. Takes num and muted |
Table.Actions |
A <div> that lays two or more row actions side by side in one Cell |
interface Table.RootProps extends React.ComponentProps<"table"> {
size?: "sm" | "md"; // sm for dense admin lists
bordered?: boolean; // a line edge and rounded corners around the table, for a table that sits among other sections
}
interface Table.HeadProps extends React.ComponentProps<"th"> {
num?: boolean; // right-aligned, for a column of numbers
}
interface Table.CellProps extends React.ComponentProps<"td"> {
num?: boolean; // right-aligned
muted?: boolean; // text-secondary, for secondary values such as dates
}Every native attribute passes through.
-
Use it for data with columns. Lists of content (notes, comments) are entries, not rows.
-
Set
numon a numeric column's Head and on its Cells. -
Put row actions in the last column as a ghost Menu trigger, named for its row. Give that column's Head text in
mu-visually-hidden. -
Two or three frequent actions, such as Edit and Delete, go in a
Table.Actionsinside that Cell, as ghost Buttons. Put a single Button straight in the Cell:<Table.Cell num> <Table.Actions> <Button variant="ghost" size="sm" icon={<Pencil />} aria-label={`Edit ${hook.name}`} /> <Button variant="ghost" size="sm" icon={<Trash2 />} aria-label={`Delete ${hook.name}`} /> </Table.Actions> </Table.Cell>
-
Name the table with a Caption, or
aria-labelon the root. -
Sort, select and paginate in the app. The table has no data props.
-
Set
borderedwhen the table is one section of a settings or admin page, next to other sections or a List, so it reads as one block. Its head row gets acanvasfill, so the head reads apart from the first row inside the box. Leave it off when the table is the page's main content. Never put a bordered table inside a Dialog or Popover.
- No stripes: a
lineunder the head row and between body rows. Ordinary data rows do not highlight on hover; action buttons inside cells keep their own shared feedback. bordered:surfacefill, a 1pxlineedge andradius-lgon the scrolling wrapper; the head row has acanvasfill, so it reads as the head inside the box; the Caption sits inside the edge, under aline. The outer columns padspace-1more, so the text lines up with a List row's.- Heads:
label-sm(13px, 500) intext-secondary, a control height tall. - Cells:
captionat sm andbodyat md, with tabular numbers. Rows are 34 or 40px; a Button in a cell, or aTable.Actionsgroup of them (space-1apart), overlaps the padding, so rows keep that height. - Cells pad
pxat the sides. Caption:captionintext-secondary,space-2above.