Table
Tableは、構造化データを行と列で表示するためのコンパウンドコンポーネントです。 ソート、ストライプ、スティッキーヘッダーなどの機能を備え、柔軟なデータ表示に対応します。
3
Variants
3
Sizes
8
サブコンポーネント
Pure
React
Playground
Preview
D
| Status | ||||
|---|---|---|---|---|
| PAY-7291 | Success | emily@example.com | Dec 20, 2030 | $316.00 |
| PAY-7292 | Success | james@example.com | Dec 20, 2030 | $242.00 |
| PAY-7293 | Pending | sarah@example.com | Dec 21, 2030 | $837.00 |
| PAY-7294 | Success | david@example.com | Dec 21, 2030 | $124.00 |
| PAY-7295 | Failed | olivia@example.com | Dec 22, 2030 | $495.00 |
| PAY-7296 | Success | michael@example.com | Dec 22, 2030 | $158.00 |
| PAY-7297 | Pending | sophie@example.com | Dec 23, 2030 | $721.00 |
| PAY-7298 | Success | daniel@example.com | Dec 24, 2030 | $89.00 |
| PAY-7299 | Failed | emma@example.com | Dec 24, 2030 | $362.00 |
| PAY-7300 | Success | ryan@example.com | Dec 25, 2030 | $550.00 |
Variant
Size
Options
<Table>
<TableHeader>
<TableRow>
<TableHead sortable sortDirection={sortKey === 'id' ? sortDir : null} onSort={() => handleSort('id')}>Invoice</TableHead>
<TableHead>Status</TableHead>
<TableHead sortable sortDirection={sortKey === 'email' ? sortDir : null} onSort={() => handleSort('email')}>Email</TableHead>
<TableHead sortable sortDirection={sortKey === 'date' ? sortDir : null} onSort={() => handleSort('date')}>Date</TableHead>
<TableHead align="right" sortable sortDirection={sortKey === 'amount' ? sortDir : null} onSort={() => handleSort('amount')}>Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{sortedData.map(row => (
<TableRow key={row.id} interactive>
<TableCell className="font-mono font-normal">{row.id}</TableCell>
<TableCell>
<Badge
variant="subtle"
color={statusMap[row.status].color}
size="sm"
>
{statusMap[row.status].label}
</Badge>
</TableCell>
<TableCell className="text-text-muted">{row.email}</TableCell>
<TableCell className="text-text-muted whitespace-nowrap">{row.date}</TableCell>
<TableCell align="right" className="font-mono">${row.amount.toFixed(2)}</TableCell>
</TableRow>
))}
</TableBody>
</Table>Variants
Default
| Name | Role | Status |
|---|---|---|
| Bob | Designer | Away |
| Alice | Engineer | Active |
Bordered
| Name | Role | Status |
|---|---|---|
| Bob | Designer | Away |
| Alice | Engineer | Active |
Striped
| Name | Role | Status |
|---|---|---|
| Bob | Designer | Away |
| Alice | Engineer | Active |
| Charlie | PM | Meeting |
| Diana | DevOps | Active |
Sizes
smCell PY8px
Cell PX12px
フォント14px
defaultCell PY12px
Cell PX16px
フォント14px
lgCell PY16px
Cell PX24px
フォント16px
| Size | Cell PY | Cell PX | Body Font | Head Font | プレビュー | ||
|---|---|---|---|---|---|---|---|
sm | 8px | 12px | 14px | 12px |
| ||
default | 12px | 16px | 14px | 12px |
| ||
lg | 16px | 24px | 16px | 14px |
|
API
Component Structure
Table— Pure React.Header.Body.Footer.RowProps.HeadProps.CellProps.Caption
.Header<thead> ラッパー.Body<tbody> ラッパー.Footer<tfoot> ラッパー.RowPropsテーブル行(interactive・selected).HeadPropsヘッダーセル(align・sortable).CellPropsデータセル(align).CaptionテーブルキャプションProps
Table
size"default""sm" | "default" | "lg"テーブルの行密度(sm: コンパクト / default: 標準 / lg: ゆったり)
variant"default""default" | "bordered" | "striped"テーブルのビジュアルスタイル
stickyHeaderfalsebooleanヘッダーをスクロール時に固定表示
wrapperClassNameundefinedstringスクロールラッパーに追加するclassName(例: "max-h-[400px]")。stickyHeaderと組み合わせて使用
| Name | Type | Default | Description |
|---|---|---|---|
size | "sm" | "default" | "lg" | "default" | テーブルの行密度(sm: コンパクト / default: 標準 / lg: ゆったり) |
variant | "default" | "bordered" | "striped" | "default" | テーブルのビジュアルスタイル |
stickyHeader | boolean | false | ヘッダーをスクロール時に固定表示 |
wrapperClassName | string | undefined | スクロールラッパーに追加するclassName(例: "max-h-[400px]")。stickyHeaderと組み合わせて使用 |
TableRow
interactivefalsebooleanホバー時にハイライト効果を表示
selectedfalseboolean行の選択状態を示す(data-selected属性を付与)
| Name | Type | Default | Description |
|---|---|---|---|
interactive | boolean | false | ホバー時にハイライト効果を表示 |
selected | boolean | false | 行の選択状態を示す(data-selected属性を付与) |
TableHead
align"left""left" | "center" | "right"テキストの水平配置
sortablefalsebooleanソートインジケーターを表示
sortDirectionnull"asc" | "desc" | null現在のソート方向
onSortundefined() => voidソートクリック時のコールバック
sortIcon内蔵SVG{ asc?: ReactNode, desc?: ReactNode, default?: ReactNode }ソートアイコンをカスタマイズ(部分的なオーバーライド可)
| Name | Type | Default | Description |
|---|---|---|---|
align | "left" | "center" | "right" | "left" | テキストの水平配置 |
sortable | boolean | false | ソートインジケーターを表示 |
sortDirection | "asc" | "desc" | null | null | 現在のソート方向 |
onSort | () => void | undefined | ソートクリック時のコールバック |
sortIcon | { asc?: ReactNode, desc?: ReactNode, default?: ReactNode } | 内蔵SVG | ソートアイコンをカスタマイズ(部分的なオーバーライド可) |
TableCell
align"left""left" | "center" | "right"テキストの水平配置
| Name | Type | Default | Description |
|---|---|---|---|
align | "left" | "center" | "right" | "left" | テキストの水平配置 |
Customization
sortIcon propでソートアイコンを自由にカスタマイズできます。部分的なオーバーライドも可能です。
Lucideアイコンに変更
| Role | ||
|---|---|---|
| Bob | bob@example.com | Designer |
| Alice | alice@example.com | Engineer |
| Charlie | charlie@example.com | PM |
import { ArrowUp, ArrowDown, ArrowUpDown } from 'lucide-react'
<TableHead
sortable
sortIcon={{
asc: <ArrowUp className="icon-xs" />,
desc: <ArrowDown className="icon-xs" />,
default: <ArrowUpDown className="icon-xs" />,
}}
>
Name
</TableHead>部分的オーバーライド
| Grade | |
|---|---|
| 95 | A+ |
| 87 | B+ |
| 72 | C+ |
// ascとdescだけオーバーライド(defaultは内蔵アイコンを維持)
<TableHead sortable sortIcon={{ asc: <span>↑</span>, desc: <span>↓</span> }}>
Score
</TableHead>Tip: アイコンサイズは icon-xs(14px)を推奨。テーブルヘッダーのテキストサイズに最適です。