spst-model-table
These examples do not call the service. Model rendering is a static placeholder.
Source commit: d204666f04a0ee7b6f18543f8aec414b4128874e · shadcn build 4.23.1
Noto Sans JP · @fontsource/noto-sans-jp 5.3.1 · OFL-1.1
Preview
Install (publication pending)
These URLs are planned for publication and are not available yet. Inspect existing file differences before installing; do not use --overwrite by default.
npx shadcn@latest add https://spritestack.dev/r/spst-model-table.jsonAdd to registries in components.json
{"registries":{"@spritestack":"https://spritestack.dev/r/{name}.json"}}npx shadcn@latest add @spritestack/spst-model-tableTargets React 19, Tailwind v4 and shadcn projects with src/. Layouts without src/ are unverified. Installation copies source files; updates are not automatic.
import "./styles/spritestack/theme.css";
<div className="spst-theme" data-theme="light">
{/* Render components here. */}
</div>Pass an element inside .spst-theme to container / portalContainer for portals. Self-host Noto Sans JP weights 400, 600 and 700 in your application; system-ui is the fallback.
Dependencies
react@19.2.4- spst-alert
- spst-alert-dialog
- spst-button
- spst-input
- spst-pagination
- spst-select
- spst-table
- spst-theme
Props / API
Generated by parsing the actual source. Rows marked … reference inherited React / Radix public types. — means no default is declared in this function parameter. See the type declarations for union-specific requirements.
src/components/spritestack/model-table.tsx
ModelTable
ModelTable({
messages,
rows,
search,
onSearchChange,
sort,
sortOptions,
onSortChange,
pageSize,
pageSizes,
onPageSizeChange,
page,
pageCount,
total,
onPageChange,
onMakePrivate,
loading,
error,
pending,
portalContainer,
}: ModelTableProps)| Prop | Type | Required | Default | Event |
|---|---|---|---|---|
messages | Partial<ModelTableMessages> | No | — | — |
rows | readonly ModelTableRow[] | Yes | — | — |
search | string | Yes | — | — |
onSearchChange | (value: string) => void | Yes | — | Yes |
sort | string | Yes | — | — |
sortOptions | readonly { value: string; label: string }[] | Yes | — | — |
onSortChange | (value: string) => void | Yes | — | Yes |
pageSize | number | Yes | — | — |
pageSizes | readonly number[] | Yes | — | — |
onPageSizeChange | (value: number) => void | Yes | — | Yes |
page | number | Yes | — | — |
pageCount | number | Yes | — | — |
total | number | Yes | — | — |
onPageChange | (page: number) => void | Yes | — | Yes |
onMakePrivate | (id: string) => void | Yes | — | Yes |
loading | boolean | No | — | — |
error | string | No | — | — |
pending | boolean | No | — | — |
portalContainer | HTMLElement | null | No | — | — |
Inspect type declarations and source
// 出典: SpriteStack デザインシステム設計 §4.2・§4.4(Issue 313)。基本部品は同梱の shadcn/ui 派生を合成。
"use client";
import { type ReactNode, useState } from "react";
import { Alert } from "../ui/alert";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogTitle,
AlertDialogTrigger,
} from "../ui/alert-dialog";
import { Button } from "../ui/button";
import { Input } from "../ui/input";
import {
Pagination,
PaginationContent,
PaginationItem,
type PaginationMessages,
PaginationNext,
PaginationPrevious,
} from "../ui/pagination";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../ui/table";
export type ModelTableRow = {
id: string;
title: string;
author: string;
publishedAt: string;
thumbnail?: ReactNode;
};
export type ModelTableMessages = {
pagination: Partial<PaginationMessages>;
label: string;
title: string;
search: string;
sort: string;
thumbnail: string;
name: string;
id: string;
author: string;
publishedAt: string;
actions: string;
loading: string;
error: string;
noImage: string;
makePrivate: string;
confirmTitle: string;
cancel: string;
empty: string;
pageSize: string;
total: (count: number) => string;
count: (count: number) => string;
privateLabel: (title: string) => string;
confirmDescription: (title: string) => string;
};
const defaultMessages: ModelTableMessages = {
pagination: {},
label: "モデル一覧",
title: "公開中のモデル一覧",
search: "モデルを検索",
sort: "並び順",
thumbnail: "サムネイル",
name: "モデル名",
id: "ID",
author: "作者",
publishedAt: "公開日",
actions: "操作",
loading: "読み込み中",
error: "モデルを表示できません",
noImage: "画像なし",
makePrivate: "非公開にする",
confirmTitle: "モデルを非公開にしますか",
cancel: "戻る",
empty: "モデルはありません",
pageSize: "表示件数",
total: (count: number) => `全 ${count} 件`,
count: (count: number) => `${count} 件`,
privateLabel: (title: string) => `${title} を非公開にする`,
confirmDescription: (title: string) => `${title} を非公開にします。`,
};
export type ModelTableProps = {
messages?: Partial<ModelTableMessages>;
rows: readonly ModelTableRow[];
search: string;
onSearchChange: (value: string) => void;
sort: string;
sortOptions: readonly { value: string; label: string }[];
onSortChange: (value: string) => void;
pageSize: number;
pageSizes: readonly number[];
onPageSizeChange: (value: number) => void;
page: number;
pageCount: number;
total: number;
onPageChange: (page: number) => void;
onMakePrivate: (id: string) => void;
loading?: boolean;
error?: string;
pending?: boolean;
portalContainer?: HTMLElement | null;
};
export function ModelTable({
messages,
rows,
search,
onSearchChange,
sort,
sortOptions,
onSortChange,
pageSize,
pageSizes,
onPageSizeChange,
page,
pageCount,
total,
onPageChange,
onMakePrivate,
loading,
error,
pending,
portalContainer,
}: ModelTableProps) {
const m = { ...defaultMessages, ...messages };
const [target, setTarget] = useState<string | null>(null);
const blocked = pending || loading || !!error;
return (
<section
data-component="model-table"
className="grid min-w-0 content-start gap-4"
aria-label={m.label}
aria-busy={loading || pending || undefined}
>
<h2 className="text-xl font-(weight:--spst-font-weight-heading)">{m.title}</h2>
<p>{m.total(total)}</p>
<div className="flex flex-wrap gap-3">
<Input
type="search"
className="flex-1"
aria-label={m.search}
value={search}
disabled={pending}
onChange={(event) => onSearchChange(event.target.value)}
/>
<Select value={sort} onValueChange={onSortChange} disabled={pending}>
<SelectTrigger aria-label={m.sort}>
<SelectValue placeholder={m.sort} />
</SelectTrigger>
<SelectContent container={portalContainer}>
{sortOptions.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{error && <Alert variant="error">{error}</Alert>}
<Table>
<TableHeader>
<TableRow>
{[m.thumbnail, m.name, m.id, m.author, m.publishedAt, m.actions].map((name) => (
<TableHead key={name} scope="col">
{name}
</TableHead>
))}
</TableRow>
</TableHeader>
<TableBody>
{loading || error ? (
<TableRow>
<TableCell colSpan={6}>{loading ? m.loading : m.error}</TableCell>
</TableRow>
) : rows.length ? (
rows.map((row) => (
<TableRow key={row.id}>
<TableCell>{row.thumbnail || m.noImage}</TableCell>
<TableCell>{row.title}</TableCell>
<TableCell>{row.id}</TableCell>
<TableCell>{row.author}</TableCell>
<TableCell>{row.publishedAt}</TableCell>
<TableCell>
<AlertDialog
open={target === row.id}
onOpenChange={(open) => {
if (!pending) setTarget(open ? row.id : null);
}}
pending={pending}
>
<AlertDialogTrigger asChild>
<Button
variant="outline"
disabled={blocked}
aria-label={m.privateLabel(row.title)}
>
{m.makePrivate}
</Button>
</AlertDialogTrigger>
<AlertDialogContent container={portalContainer}>
<AlertDialogTitle>{m.confirmTitle}</AlertDialogTitle>
<AlertDialogDescription>
{m.confirmDescription(row.title)}
</AlertDialogDescription>
<AlertDialogFooter>
<AlertDialogCancel>{m.cancel}</AlertDialogCancel>
<AlertDialogAction
onClick={() => {
if (!blocked) onMakePrivate(row.id);
}}
>
{m.makePrivate}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</TableCell>
</TableRow>
))
) : (
<TableRow>
<TableCell colSpan={6}>{m.empty}</TableCell>
</TableRow>
)}
</TableBody>
</Table>
<div className="flex flex-wrap items-center gap-3">
<Select
value={String(pageSize)}
onValueChange={(value) => onPageSizeChange(Number(value))}
disabled={pending}
>
<SelectTrigger aria-label={m.pageSize}>
<SelectValue />
</SelectTrigger>
<SelectContent container={portalContainer}>
{pageSizes.map((size) => (
<SelectItem key={size} value={String(size)}>
{m.count(size)}
</SelectItem>
))}
</SelectContent>
</Select>
<Pagination messages={m.pagination}>
<PaginationContent>
<PaginationItem>
<PaginationPrevious
messages={m.pagination}
href="#previous"
disabled={blocked || page <= 1}
onClick={(event) => {
event.preventDefault();
onPageChange(page - 1);
}}
/>
</PaginationItem>
<PaginationItem>
<span aria-current="page">
{page} / {Math.max(1, pageCount)}
</span>
</PaginationItem>
<PaginationItem>
<PaginationNext
messages={m.pagination}
href="#next"
disabled={blocked || page >= pageCount}
onClick={(event) => {
event.preventDefault();
onPageChange(page + 1);
}}
/>
</PaginationItem>
</PaginationContent>
</Pagination>
</div>
</section>
);
}
Accessibility requirements
- Give inputs a label or accessible name and associate errors with aria-describedby. Do not communicate state using color alone.
- Provide model names and image fallbacks. Icon-only buttons need accessible names.
- Provide dialog and sheet titles and descriptions, and place portals inside the theme. Test Tab, arrow keys, Escape and focus restoration in the consuming app.
- Slider requires a name and finite min < max. ToggleGroup requires a nonempty single value. The parent controls pending state.
Reference images: 09 · Dark mode and error states extend the reference design.