spst-model-card
実サービスへ通信しない見本です。モデルの描画は静止した代替表示です。
元 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-model-card.jsoncomponents.json の registries に追加
{"registries":{"@spritestack":"https://spritestack.dev/r/{name}.json"}}npx shadcn@latest add @spritestack/spst-model-cardReact 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/spritestack/model-card.tsx
ModelCard
ModelCard({
messages,
variant = "catalog",
title,
heading: Heading = "h3",
author,
license,
thumbnail,
href,
linkProps,
linkThumbnail = false,
selected = false,
onSelect,
stats,
actions,
visibility,
state = "ready",
}: ModelCardProps)| Prop | 型 | 必須 | 既定 | イベント |
|---|---|---|---|---|
messages | Partial<ModelCardMessages> | いいえ | — | — |
variant | "catalog" | "owned" | いいえ | "catalog" | — |
title | string | はい | — | — |
heading | "h2" | "h3" | いいえ | "h3" | — |
author | string | いいえ | — | — |
license | string | いいえ | — | — |
thumbnail | ReactNode | いいえ | — | — |
href | string | はい | — | — |
linkProps | Omit<ComponentProps<"a">, "href" | "children"> | いいえ | — | — |
linkThumbnail | boolean | いいえ | false | — |
selected | boolean | いいえ | false | — |
onSelect | () => void | いいえ | — | はい |
stats | readonly { label: string; value: string | number }[] | いいえ | — | — |
actions | ReactNode | いいえ | — | — |
visibility | "public" | "private" | いいえ | — | — |
state | "ready" | "loading" | "empty" | "error" | いいえ | "ready" | — |
分割代入の既定値(継承した props も含む)
variant = "catalog"
heading = "h3"
linkThumbnail = false
selected = false
state = "ready"型宣言とソースを確認
// 出典: SpriteStack デザインシステム設計 §4.2・§4.4(Issue 313)。基本部品は同梱の shadcn/ui 派生を合成。
"use client";
import type { ComponentProps, ReactNode } from "react";
import { cn } from "../../lib/spritestack/utils";
import { Alert } from "../ui/alert";
import { Badge } from "../ui/badge";
import { Button, buttonVariants } from "../ui/button";
import { Card } from "../ui/card";
import { Skeleton } from "../ui/skeleton";
export type ModelCardMessages = {
public: string;
private: string;
unspecified: string;
noLicense: string;
preview: string;
open: string;
loading: string;
error: string;
empty: string;
noImage: string;
author: (name: string) => string;
};
const defaultMessages: ModelCardMessages = {
public: "公開中",
private: "非公開",
unspecified: "未指定",
noLicense: "使用許諾未指定",
preview: "プレビュー",
open: "モデルのページを開く",
loading: "モデルを読み込み中",
error: "モデルを読み込めませんでした",
empty: "モデルがありません",
noImage: "画像なし",
author: (name: string) => `作者: ${name}`,
};
export type ModelCardProps = {
messages?: Partial<ModelCardMessages>;
variant?: "catalog" | "owned";
title: string;
heading?: "h2" | "h3";
author?: string;
license?: string;
thumbnail?: ReactNode;
href: string;
linkProps?: Omit<ComponentProps<"a">, "href" | "children">;
linkThumbnail?: boolean;
selected?: boolean;
onSelect?: () => void;
stats?: readonly { label: string; value: string | number }[];
actions?: ReactNode;
visibility?: "public" | "private";
state?: "ready" | "loading" | "empty" | "error";
};
export function ModelCard({
messages,
variant = "catalog",
title,
heading: Heading = "h3",
author,
license,
thumbnail,
href,
linkProps,
linkThumbnail = false,
selected = false,
onSelect,
stats,
actions,
visibility,
state = "ready",
}: ModelCardProps) {
const m = { ...defaultMessages, ...messages };
return (
<Card
className={cn(
"min-w-0 gap-3 p-4 [overflow-wrap:anywhere]",
selected && "ring-(length:--spst-focus-width) ring-ring",
)}
data-component="model-card"
data-variant={variant}
aria-busy={state === "loading"}
>
{variant === "owned" && visibility && (
<Badge variant={visibility}>{visibility === "public" ? m.public : m.private}</Badge>
)}
{linkThumbnail ? (
<a
{...linkProps}
className={cn("block rounded-card focus-visible:outline-ring", linkProps?.className)}
href={href}
aria-current={selected ? "true" : undefined}
>
<div className="grid aspect-square place-items-center rounded-card bg-stage text-foreground">
<ModelThumbnail state={state} thumbnail={thumbnail} messages={m} />
</div>
<Heading className="mt-3 text-lg font-(weight:--spst-font-weight-heading)">
{title}
</Heading>
</a>
) : (
<>
<div className="grid aspect-square place-items-center rounded-card bg-stage text-foreground">
<ModelThumbnail state={state} thumbnail={thumbnail} messages={m} />
</div>
<Heading className="text-lg font-(weight:--spst-font-weight-heading)">
<a
{...linkProps}
className={cn(
"text-primary underline focus-visible:outline-ring",
linkProps?.className,
)}
href={href}
aria-current={selected ? "true" : undefined}
>
{title}
</a>
</Heading>
</>
)}
<div className="flex flex-wrap items-center justify-between gap-2">
<span>{m.author(author || m.unspecified)}</span>
<Badge>{license || m.noLicense}</Badge>
</div>
{stats && (
<dl className="flex flex-wrap gap-3">
{stats.map(({ label, value }) => (
<div key={label}>
<dt className="text-sm text-muted-foreground">{label}</dt>
<dd>{value}</dd>
</div>
))}
</dl>
)}
{onSelect && (
<Button variant="outline" aria-pressed={selected} onClick={onSelect}>
{m.preview}
</Button>
)}
{actions && <div className="flex flex-wrap gap-2">{actions}</div>}
{variant === "owned" && (
<a className={cn(buttonVariants(), "whitespace-normal")} href={href}>
{m.open}
</a>
)}
</Card>
);
}
function ModelThumbnail({
state,
thumbnail,
messages: m,
}: Pick<ModelCardProps, "state" | "thumbnail"> & { messages: ModelCardMessages }) {
return (
<>
{" "}
{state === "loading" ? (
<>
<Skeleton className="size-full" />
<span className="sr-only" role="status">
{m.loading}
</span>
</>
) : state === "error" ? (
<Alert variant="error">{m.error}</Alert>
) : state === "empty" ? (
<p>{m.empty}</p>
) : (
(thumbnail ?? <p>{m.noImage}</p>)
)}
</>
);
}
アクセシビリティの利用条件
- 入力には Label または読み上げ名を与え、エラーを aria-describedby で関連づけます。色だけで状態を伝えません。
- 画像にはモデル名と代替表示を与えます。単独アイコンのボタンにも名前が必要です。
- Dialog / Sheet に題名と説明を与え、Portal をテーマ内に置きます。Tab・矢印・Escape と閉じた後のフォーカスを利用先でも確認します。
- Slider は名前と有限の min < max、ToggleGroup は空でない single の値が必要です。pending は親が制御します。
対応画像: 01・02・06 · 暗色とエラーは設計による補完です。