spst-viewer-controls
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-viewer-controls.jsonAdd to registries in components.json
{"registries":{"@spritestack":"https://spritestack.dev/r/{name}.json"}}npx shadcn@latest add @spritestack/spst-viewer-controlsTargets 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/viewer-controls.tsx
ViewerControls
ViewerControls(props: ViewerControlsProps)| Prop | Type | Required | Default | Event |
|---|---|---|---|---|
messages | Partial<ViewerControlsMessages> | No | — | — |
mode | "2d" | "3d" | Yes | — | — |
onModeChange | (mode: "2d" | "3d") => void | Yes | — | Yes |
disabled | boolean | No | — | — |
container | ComponentProps<typeof TooltipContent>["container"] | No | — | — |
… | (
| {
variant?: "full";
gap: number;
onGapChange: (gap: number) => void;
gapMin: number;
gapMax: number;
gapStep?: number;
onRotate: (direction: "left" | "right") => void;
}
| {
variant: "site";
spread: boolean;
canSpread: boolean;
onSpreadChange: (spread: boolean) => void;
}
) | — | — | — |
Inspect type declarations and source
// 出典: SpriteStack デザインシステム設計 §4.2・§4.4(Issue 313)。基本部品は同梱の shadcn/ui 派生を合成。
"use client";
import type { ComponentProps } from "react";
import { Button } from "../ui/button";
import { Slider } from "../ui/slider";
import { ToggleGroup, ToggleGroupItem } from "../ui/toggle-group";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip";
export type ViewerControlsMessages = {
mode: string;
spread?: string;
gap: string;
gapValue: string;
gapHelp: string;
gapDescription: string;
left: string;
right: string;
};
const defaultMessages: ViewerControlsMessages = {
mode: "描画方法",
spread: "すき間を開く",
gap: "すき間",
gapValue: "すき間の値",
gapHelp: "すき間の説明",
gapDescription: "層を離す量です",
left: "左へ回す",
right: "右へ回す",
};
type CommonProps = {
messages?: Partial<ViewerControlsMessages>;
mode: "2d" | "3d";
onModeChange: (mode: "2d" | "3d") => void;
disabled?: boolean;
container?: ComponentProps<typeof TooltipContent>["container"];
};
export type ViewerControlsProps = CommonProps &
(
| {
variant?: "full";
gap: number;
onGapChange: (gap: number) => void;
gapMin: number;
gapMax: number;
gapStep?: number;
onRotate: (direction: "left" | "right") => void;
}
| {
variant: "site";
spread: boolean;
canSpread: boolean;
onSpreadChange: (spread: boolean) => void;
}
);
export function ViewerControls(props: ViewerControlsProps) {
const { messages, mode, onModeChange, disabled, container } = props;
const m = { ...defaultMessages, ...messages };
return (
<div data-component="viewer-controls" className="flex min-w-0 flex-wrap items-center gap-4">
<ToggleGroup
value={mode}
onValueChange={(value) => onModeChange(value as "2d" | "3d")}
disabled={disabled}
aria-label={m.mode}
>
<ToggleGroupItem value="2d">2D</ToggleGroupItem>
<ToggleGroupItem value="3d">3D</ToggleGroupItem>
</ToggleGroup>
{props.variant === "site" ? (
mode === "2d" &&
props.canSpread && (
<Button
variant="outline"
disabled={disabled}
aria-pressed={props.spread}
onClick={() => props.onSpreadChange(!props.spread)}
>
{m.spread}
</Button>
)
) : (
<>
<div className="min-w-0 grow">
<div className="flex flex-wrap items-center gap-2">
<span>{m.gap}</span>
<output aria-label={m.gapValue}>{props.gap}</output>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<Button variant="ghost" disabled={disabled} aria-label={m.gapHelp}>
?
</Button>
</TooltipTrigger>
<TooltipContent container={container}>{m.gapDescription}</TooltipContent>
</Tooltip>
</TooltipProvider>
</div>
<Slider
aria-label={m.gap}
value={[props.gap]}
onValueChange={([value]) => {
if (value !== undefined) props.onGapChange(value);
}}
min={props.gapMin}
max={props.gapMax}
step={props.gapStep ?? 1}
disabled={disabled}
/>
</div>
<Button variant="outline" disabled={disabled} onClick={() => props.onRotate("left")}>
{m.left}
</Button>
<Button variant="outline" disabled={disabled} onClick={() => props.onRotate("right")}>
{m.right}
</Button>
</>
)}
</div>
);
}
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〜04・08 · Dark mode and error states extend the reference design.