本文へ移動
日本語

仕組み

A card with no outer border, a muted 12px header over the only hairline and no lines between rows. The footer shows the range on the left ("5–8 of 22"), an optional page-size menu, and the pager on the right: page numbers on a filled track, the current one marked by an ink pill that slides to it with translateX (its width is set at once, never animated). The first and last page always show with siblingCount pages beside the current one, and the cell count stays constant so the pager never changes width. The body height is fixed to pageSize rows. On a page change the new rows fade in and slide 12px from the paging direction (Web Animations, transform and opacity only), played when the rows actually change, so server-side paging animates when data arrives.

向いている場面

  • Data too long for one page, where people need the total and a way to jump to a page: orders, transactions, audit logs.
  • Server-side paging (page, size, total): pass total and the current page of rows, fetch in onPageChange, and the old rows stay faded while loading.
  • A list inside a fixed-height card or dialog: the body height is fixed per page, so a short last page does not pull what is below upward.

向かない場面

  • Feeds that people only scroll down (messages, activity): use "load more" or infinite loading.
  • Twenty rows or fewer in total: show them all, or use a fixed-height scrolling body.
  • Cursor-based APIs with no total: page numbers and total cannot be shown; offer previous and next only.

使い方

import { useEffect, useState } from 'react'
import { PageTable } from './PageTable.jsx'

const columns = [
  { key: 'client', title: 'Client' },
  { key: 'amount', title: 'Amount', width: 96, align: 'right', render: (r) => `$${r.amount.toFixed(2)}` },
  { key: 'status', title: 'Status', width: 96 },
]

// Client-side paging: pass all the data and the component slices it
export function LocalInvoices({ invoices }) {
  return <PageTable title="Invoices" columns={columns} rows={invoices} rowKey={(r) => r.id} defaultPageSize={10} pageSizeOptions={[10, 20, 50]} />
}

// Server-side paging: pass total; rows is the current page and you fetch on change
export function RemoteInvoices() {
  const [page, setPage] = useState(1)
  const [data, setData] = useState({ rows: [], total: 0 })
  const [loading, setLoading] = useState(false)

  useEffect(() => {
    let stale = false
    setLoading(true)
    fetch(`/api/invoices?page=${page}&size=10`)
      .then((res) => res.json())
      .then((json) => !stale && setData(json))
      .finally(() => !stale && setLoading(false))
    return () => {
      stale = true
    }
  }, [page])

  return (
    <PageTable title="Invoices" columns={columns} rows={data.rows} rowKey={(r) => r.id} total={data.total} page={page} pageSize={10} onPageChange={setPage} loading={loading} />
  )
}

プロパティ

プロパティ型既定値説明
columnsColumn[]—Column definitions: key (also the default field to read), title, width, align, render(row, index) where index is the row's position on the current page.
rowsobject[]—Data rows. Without total this is all the data and the component slices the page; with total it is the current page.
rowKey(row) => string | number—Unique key of each row.
pagenumber—Controlled current page, starting at 1. Out-of-range values are clamped.
defaultPagenumber1Initial page when uncontrolled.
onPageChange(page, pageSize) => void—Called when the page changes, including when a new page size moves the page.
pageSizenumber—Controlled page size. The body height is fixed to it.
defaultPageSizenumber10Initial page size when uncontrolled.
onPageSizeChange(pageSize) => void—Called when the page size changes.
pageSizeOptionsnumber[]—Page sizes to offer, such as [10, 20, 50]. The menu shows in the footer only when this is set; it needs a card of about 480px or more beside the range and pager.
totalnumber—Total number of items. Setting it means server-side paging: rows is the current page and you fetch in onPageChange.
loadingbooleanfalseFetching: current rows fade and cannot be clicked, a progress line appears under the header, and the root gets aria-busy.
siblingCountnumber1Page numbers on each side of the current page (1 … 4 5 6 … 12). Use 0 in narrow spaces.
totalText(total) => ReactNode—Text at the left of the footer, given the total. Default is labels.range(from, to, total), such as “5–8 of 22”.
emptyTextReactNode'No data'Text in the middle of the body when there are no rows.
titleReactNode—Card title shown in the title row. A string title also names the table for screen readers when label is not given.
subtitleReactNode—Muted qualifier after the title, such as a period ("This week").
iconReactNode—Icon before the title, drawn in a tinted 32px rounded square. Decorative (aria-hidden).
actionsReactNode—Controls at the right end of the title row (buttons, a switch, a menu).
labelstring—Table name for screen readers (the <caption>). Defaults to title when title is a string.
labelsobject—Replaces built-in text (pagination, previous, next, page, pageOf, range, pageSize, perPage). Shallow-merged over the English defaults.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the root <div>.

アクセシビリティ

  • The pager is a <nav> with a label; each page is a button named "Page 3" with aria-current="page" on the current one; previous and next have labels and become disabled at the ends.
  • Left and Right in the pager move one page, Home and End go to the first and last, and focus stays on the current page number.
  • When a step button becomes disabled, focus moves to the current page instead of getting stuck.
  • Each page change is announced through aria-live ("Page 2 of 5"); the root has aria-busy while loading.
  • The current page is not only a colour: an ink pill with reversed digits and aria-current; it is a real <table> with <th scope="col"> and the label as <caption>.
  • With reduced motion the new page appears at once and the progress line is still; on touch the header is 44px and the pager compacts to "Previous · 3 / 12 · Next".

モーション

The ink pill slides to the new page in 360ms ease-out; the page number turns to the pill's text colour 90ms later, as it arrives. New rows: opacity and translateX 12px over 240ms ease-out, 20ms apart. Buttons shrink to 0.92 while pressed. Loading: an accent segment travels along a 3px track under the header, 900ms each way.

プロジェクトに追加

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

PageTable.jsxpage-table.csstokens.cssREADME.md

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

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