Skip to content
This page is a translation of the Japanese version. The Japanese version is authoritative; if they differ, follow the Japanese version.

spst-file-dropzone

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

Open full page

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-file-dropzone.json

Add to registries in components.json

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

Targets 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/file-dropzone.tsx

FileDropzone

FileDropzone({
  messages,
  file,
  disabled = false,
  onFileChange,
  onReject,
}: FileDropzoneProps)
PropTypeRequiredDefaultEvent
messagesPartial<FileDropzoneMessages>No——
fileFile | nullNo——
disabledbooleanNofalse—
onFileChange(file: File) => voidYes—Yes
onReject(message: string) => voidNo—Yes
Destructuring defaults (including inherited props)
disabled = false
Inspect type declarations and source
// 出典: SpriteStack デザインシステム設計 §4.2・§4.4(Issue 313)。基本部品は同梱の shadcn/ui 派生を合成。
"use client";
import { useId, useRef, useState } from "react";
import { Alert } from "../ui/alert";
import { Button } from "../ui/button";
export type FileDropzoneMessages = {
  reject: string;
  label: string;
  drop: string;
  fileLabel: string;
  choose: string;
  empty: string;
  selected: (name: string, size: number) => string;
};
const defaultMessages: FileDropzoneMessages = {
  reject: ".ss ファイルを1つ選んでください",
  label: "ファイル選択",
  drop: ".ss ファイルをここにドラッグ&ドロップ",
  fileLabel: ".ss ファイル",
  choose: "ファイルを選ぶ",
  empty: "ファイル未選択",
  selected: (name: string, size: number) => `${name}(${size} バイト)を選択中`,
};
export type FileDropzoneProps = {
  messages?: Partial<FileDropzoneMessages>;
  file?: File | null;
  disabled?: boolean;
  onFileChange: (file: File) => void;
  onReject?: (message: string) => void;
};
export function FileDropzone({
  messages,
  file,
  disabled = false,
  onFileChange,
  onReject,
}: FileDropzoneProps) {
  const m = { ...defaultMessages, ...messages };
  const id = useId();
  const input = useRef<HTMLInputElement>(null);
  const [dragover, setDragover] = useState(false);
  const [error, setError] = useState("");
  function select(files: FileList | null) {
    const selected = files?.[0];
    if (disabled || !files || !selected) return;
    if (files.length !== 1 || !selected.name.toLowerCase().endsWith(".ss")) {
      const message = m.reject;
      setError(message);
      onReject?.(message);
      return;
    }
    setError("");
    onFileChange(selected);
  }
  return (
    <section
      data-component="file-dropzone"
      data-dragover={(dragover && !disabled) || undefined}
      aria-label={m.label}
      className="grid min-w-0 gap-4 rounded-card border border-input border-dashed bg-card p-6 text-foreground data-[dragover]:bg-accent"
      onDragOver={(event) => {
        event.preventDefault();
        if (!disabled) setDragover(true);
      }}
      onDragLeave={() => setDragover(false)}
      onDrop={(event) => {
        event.preventDefault();
        setDragover(false);
        select(event.dataTransfer.files);
      }}
    >
      <p>{m.drop}</p>
      <input
        ref={input}
        tabIndex={-1}
        id={id}
        className="sr-only"
        type="file"
        accept=".ss"
        aria-label={m.fileLabel}
        aria-describedby={error ? `${id}-error` : undefined}
        aria-invalid={!!error}
        disabled={disabled}
        onChange={(event) => {
          select(event.target.files);
          event.target.value = "";
        }}
      />
      <Button variant="outline" disabled={disabled} onClick={() => input.current?.click()}>
        {m.choose}
      </Button>
      <p role="status" className="break-all">
        {file ? m.selected(file.name, file.size) : m.empty}
      </p>
      {error && (
        <Alert variant="error" id={`${id}-error`}>
          {error}
        </Alert>
      )}
    </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: 04・08 · Dark mode and error states extend the reference design.