コンテンツにスキップ

spst-table

実サービスへ通信しない見本です。モデルの描画は静止した代替表示です。

元 commit: d204666f04a0ee7b6f18543f8aec414b4128874e · shadcn build 4.23.1

Noto Sans JP · @fontsource/noto-sans-jp 5.3.1 · OFL-1.1

操作を試す

全画面で開く

取り込む(公開予定)

以下の URL は公開予定です。公開前は取り込めません。既存ファイルとの差分を確認してから実行し、--overwrite を既定にしないでください。

npx shadcn@latest add https://spritestack.dev/r/spst-table.json

components.json の registries に追加

{"registries":{"@spritestack":"https://spritestack.dev/r/{name}.json"}}
npx shadcn@latest add @spritestack/spst-table

React 19・Tailwind v4・shadcn の src/ を持つ構成が対象です。src/ の無い構成は未検証です。取り込みはソースのコピーで、自動更新されません。

import "./styles/spritestack/theme.css";

<div className="spst-theme" data-theme="light">
  {/* Render components here. */}
</div>

Portal の container / portalContainer は .spst-theme 内の要素を渡してください。Noto Sans JP の 400・600・700 は利用先が自己ホストしてください。未導入時は system-ui です。

依存

Props / API

以下は実際のソースを構文解析して生成しています。… の行は継承する React / Radix の公開型です。既定欄の — は、この関数の引数で既定を指定していないことを表します。union の必須条件は型宣言も確認してください。

src/components/ui/table.tsx

Table

Table({ className, ...props }: React.ComponentProps<"table">)
Prop型必須既定イベント
…React.ComponentProps<"table">———

TableHeader

TableHeader({ className, ...props }: React.ComponentProps<"thead">)
Prop型必須既定イベント
…React.ComponentProps<"thead">———

TableBody

TableBody({ className, ...props }: React.ComponentProps<"tbody">)
Prop型必須既定イベント
…React.ComponentProps<"tbody">———

TableFooter

TableFooter({ className, ...props }: React.ComponentProps<"tfoot">)
Prop型必須既定イベント
…React.ComponentProps<"tfoot">———

TableRow

TableRow({ className, ...props }: React.ComponentProps<"tr">)
Prop型必須既定イベント
…React.ComponentProps<"tr">———

TableHead

TableHead({ className, ...props }: React.ComponentProps<"th">)
Prop型必須既定イベント
…React.ComponentProps<"th">———

TableCell

TableCell({
  className,
  numeric = false,
  ...props
}: React.ComponentProps<"td"> & { numeric?: boolean })
Prop型必須既定イベント
…React.ComponentProps<"td">———
numericbooleanいいえfalse—
分割代入の既定値(継承した props も含む)
numeric = false

TableCaption

TableCaption({ className, ...props }: React.ComponentProps<"caption">)
Prop型必須既定イベント
…React.ComponentProps<"caption">———
型宣言とソースを確認
// 出典: shadcn/ui new-york-v4/table(commit c1ead5c92572ce6e95dc7bb3221feaf2b3aa59a7、MIT)。
"use client";

import type * as React from "react";
import { cn } from "../../lib/spritestack/utils";

function Table({ className, ...props }: React.ComponentProps<"table">) {
  return (
    <div data-slot="table-container" className="relative w-full overflow-x-auto">
      <table
        data-slot="table"
        className={cn("w-full caption-bottom font-sans text-sm text-foreground", className)}
        {...props}
      />
    </div>
  );
}

function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
  return (
    <thead
      data-slot="table-header"
      className={cn("[&_tr]:border-b [&_tr]:border-border", className)}
      {...props}
    />
  );
}

function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
  return (
    <tbody
      data-slot="table-body"
      className={cn("[&_tr:last-child]:border-0", className)}
      {...props}
    />
  );
}

function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
  return (
    <tfoot
      data-slot="table-footer"
      className={cn(
        "border-t border-border bg-muted font-(weight:--spst-font-weight-control) [&>tr]:last:border-b-0",
        className,
      )}
      {...props}
    />
  );
}

function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
  return (
    <tr
      data-slot="table-row"
      className={cn(
        "border-b border-border transition-colors hover:bg-muted aria-selected:bg-muted",
        className,
      )}
      {...props}
    />
  );
}

function TableHead({ className, ...props }: React.ComponentProps<"th">) {
  return (
    <th
      data-slot="table-head"
      className={cn(
        "px-3 py-2 text-left align-middle font-(weight:--spst-font-weight-control) text-foreground",
        className,
      )}
      {...props}
    />
  );
}

function TableCell({
  className,
  numeric = false,
  ...props
}: React.ComponentProps<"td"> & { numeric?: boolean }) {
  return (
    <td
      data-slot="table-cell"
      className={cn("p-3 align-middle", numeric && "text-right tabular-nums", className)}
      {...props}
    />
  );
}

function TableCaption({ className, ...props }: React.ComponentProps<"caption">) {
  return (
    <caption
      data-slot="table-caption"
      className={cn("mt-4 text-sm text-muted-foreground", className)}
      {...props}
    />
  );
}

export { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow };

アクセシビリティの利用条件

  • 入力には Label または読み上げ名を与え、エラーを aria-describedby で関連づけます。色だけで状態を伝えません。
  • 画像にはモデル名と代替表示を与えます。単独アイコンのボタンにも名前が必要です。
  • Dialog / Sheet に題名と説明を与え、Portal をテーマ内に置きます。Tab・矢印・Escape と閉じた後のフォーカスを利用先でも確認します。
  • Slider は名前と有限の min < max、ToggleGroup は空でない single の値が必要です。pending は親が制御します。

対応画像: 07・09 · 暗色とエラーは設計による補完です。