spst-model-card
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-card.jsonAdd to registries in components.json
{"registries":{"@spritestack":"https://spritestack.dev/r/{name}.json"}}npx shadcn@latest add @spritestack/spst-model-cardTargets 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
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-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 | Type | Required | Default | Event |
|---|---|---|---|---|
messages | Partial<ModelCardMessages> | No | — | — |
variant | "catalog" | "owned" | No | "catalog" | — |
title | string | Yes | — | — |
heading | "h2" | "h3" | No | "h3" | — |
author | string | No | — | — |
license | string | No | — | — |
thumbnail | ReactNode | No | — | — |
href | string | Yes | — | — |
linkProps | Omit<ComponentProps<"a">, "href" | "children"> | No | — | — |
linkThumbnail | boolean | No | false | — |
selected | boolean | No | false | — |
onSelect | () => void | No | — | Yes |
stats | readonly { label: string; value: string | number }[] | No | — | — |
actions | ReactNode | No | — | — |
visibility | "public" | "private" | No | — | — |
state | "ready" | "loading" | "empty" | "error" | No | "ready" | — |
Destructuring defaults (including inherited props)
variant = "catalog"
heading = "h3"
linkThumbnail = false
selected = false
state = "ready"Inspect type declarations and source
// 出典: 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>)
)}
</>
);
}
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: 01・02・06 · Dark mode and error states extend the reference design.