本文へ移動
日本語

仕組み

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.

向いている場面

  • 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.

向かない場面

  • Sorting, selection or editing: use the sort, select or edit tables.
  • Hundreds of rows: use a virtual table.

使い方

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
    />
  )
}

プロパティ

プロパティ型既定値説明
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 / rowKeyobject[] / (row, index) => keyrow.id ?? indexThe data and a stable key per row.
title / subtitle / actions / captionReactNode / string—A title row with optional actions on the right; caption names the table for screen readers.
zebrabooleanfalseAlternate 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.
emptyTextReactNode'No rows'Shown when rows is empty.

アクセシビリティ

  • 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.

プロジェクトに追加

プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。

BasicTable.jsxbasic-table.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

テーブル
「比較テーブル」は Pro に含まれます。解除するとプレビューが表示されます。
「データバー付きテーブル」は Pro に含まれます。解除するとプレビューが表示されます。
「編集可能テーブル」は Pro に含まれます。解除するとプレビューが表示されます。