Cómo funciona
The card holds a real table: the header is 12px muted text over one hairline, rows are separated by faint hairlines (or alternating fills with zebra), and the hovered row becomes a soft rounded band. Right-aligned columns use tabular figures. The card is an inline-size container, so it responds to its own width rather than the window: below 520px each row becomes a card in which the primary cell is the title over a hairline and the other cells form a two-column grid of label and value, taken from the column titles. Cards rise in with a short stagger.
Úsalo para
- Short lists of records people scan and compare: invoices, members, orders, files.
- Tables that must also work in a narrow side panel or on a phone.
Busca otra opción cuando
- Sorting, selection or editing: use the sort, select or edit tables.
- Hundreds of rows: use a virtual table.
Uso
import { BasicTable } from './BasicTable.jsx'
export function Invoices({ invoices }) {
return (
<BasicTable
title="Invoices"
caption="Invoices this month"
columns={[
{ key: 'client', title: 'Client', primary: true },
{ key: 'id', title: 'Invoice' },
{ key: 'amount', title: 'Amount', align: 'right', render: (r) => `$${r.amount.toFixed(2)}` },
]}
rows={invoices}
zebra
/>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
columns | { key: string, title: ReactNode, align?: 'left' | 'right' | 'center', width?: number | string, render?: (row) => ReactNode, primary?: boolean, hideInCard?: boolean }[] | — | The primary column (the first by default) is the row header and the title of each stacked card; hideInCard drops a column from the cards. |
rows / rowKey | object[] / (row, index) => key | row.id ?? index | The data and a stable key per row. |
title / subtitle / actions / caption | ReactNode / string | — | A title row with optional actions on the right; caption names the table for screen readers. |
zebra | boolean | false | Alternate row fills instead of hairlines. |
density | 'compact' | 'regular' | 'relaxed' | 'regular' | Rows of 38, 48 or 58px. |
stack | 'auto' | 'never' | 'always' | 'auto' | Stacked cards below 520px of the table's own width (a container query), never, or always. |
emptyText | ReactNode | 'No rows' | Shown when rows is empty. |
Accesibilidad
- It is a native table with a caption, column headers (scope col) and a row header (scope row) for the primary cell.
- In stacked cards the header row is visually hidden, not removed, and every value is preceded by its visible label.
- Status cells should carry text, not colour alone, as in the demo.
- Reduced motion removes the card entrance.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
BasicTable.jsxbasic-table.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.





