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-contact-fields

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-contact-fields.json

Add to registries in components.json

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

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/contact-fields.tsx

ContactFields

ContactFields({
  messages,
  value,
  onValueChange,
  onSubmit,
  errors = {},
  error,
  pending,
  completed,
  portalContainer,
}: ContactFieldsProps)
PropTypeRequiredDefaultEvent
messagesPartial<ContactFieldsMessages>No——
valueContactValueYes——
onValueChange(value: ContactValue) => voidYes—Yes
onSubmit() => voidYes—Yes
errorsPartial<Record<keyof ContactValue, string>>No{}—
errorstringNo——
pendingbooleanNo——
completedbooleanNo——
portalContainerHTMLElement | nullNo——
Destructuring defaults (including inherited props)
errors = {}
Inspect type declarations and source
// 出典: SpriteStack デザインシステム設計 §4.2・§4.4(Issue 313)。基本部品は同梱の shadcn/ui 派生を合成。
"use client";
import { useId } from "react";
import { Alert } from "../ui/alert";
import { Button } from "../ui/button";
import { Input } from "../ui/input";
import { Label } from "../ui/label";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select";
import { Textarea } from "../ui/textarea";
export const contactKinds = [
  "要望",
  "不具合",
  "取材",
  "権利の申し立て",
  "個人情報の開示訂正削除",
  "脆弱性の報告",
  "その他",
] as const;
export type ContactValue = { kind: string; body: string; replyTo: string };
export type ContactFieldsMessages = {
  kindLabel: (kind: (typeof contactKinds)[number]) => string;
  kind: string;
  placeholder: string;
  body: string;
  replyTo: string;
  submit: string;
  completed: string;
  pending: string;
};
const defaultMessages: ContactFieldsMessages = {
  kindLabel: (kind) => kind,
  kind: "種類",
  placeholder: "選択してください",
  body: "本文",
  replyTo: "返信先",
  submit: "送信",
  completed: "送信が完了しました",
  pending: "処理中",
};
export type ContactFieldsProps = {
  messages?: Partial<ContactFieldsMessages>;
  value: ContactValue;
  onValueChange: (value: ContactValue) => void;
  onSubmit: () => void;
  errors?: Partial<Record<keyof ContactValue, string>>;
  error?: string;
  pending?: boolean;
  completed?: boolean;
  portalContainer?: HTMLElement | null;
};
export function ContactFields({
  messages,
  value,
  onValueChange,
  onSubmit,
  errors = {},
  error,
  pending,
  completed,
  portalContainer,
}: ContactFieldsProps) {
  const m = { ...defaultMessages, ...messages };
  const id = useId();
  const disabled = pending || completed;
  return (
    <form
      data-component="contact-fields"
      className="grid gap-4"
      aria-busy={pending || undefined}
      onSubmit={(event) => {
        event.preventDefault();
        if (!disabled && !Object.values(errors).some(Boolean)) onSubmit();
      }}
    >
      <Label htmlFor={`${id}-kind`}>{m.kind}</Label>
      <Select
        value={value.kind}
        onValueChange={(kind) => onValueChange({ ...value, kind })}
        disabled={disabled}
      >
        <SelectTrigger
          id={`${id}-kind`}
          aria-invalid={!!errors.kind}
          aria-describedby={errors.kind ? `${id}-kind-error` : undefined}
        >
          <SelectValue placeholder={m.placeholder} />
        </SelectTrigger>
        <SelectContent container={portalContainer}>
          {contactKinds.map((kind) => (
            <SelectItem key={kind} value={kind}>
              {m.kindLabel(kind)}
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
      {errors.kind && (
        <Alert variant="error" id={`${id}-kind-error`}>
          {errors.kind}
        </Alert>
      )}
      {(
        [
          ["body", m.body],
          ["replyTo", m.replyTo],
        ] as const
      ).map(([key, label]) => {
        const props = {
          id: `${id}-${key}`,
          value: value[key],
          disabled,
          "aria-invalid": !!errors[key],
          "aria-describedby": errors[key] ? `${id}-${key}-error` : undefined,
          onChange: (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) =>
            onValueChange({ ...value, [key]: event.target.value }),
        };
        return (
          <div key={key} className="grid gap-2">
            <Label htmlFor={props.id}>{label}</Label>
            {key === "body" ? <Textarea {...props} /> : <Input type="email" {...props} />}
            {errors[key] && (
              <Alert variant="error" id={`${id}-${key}-error`}>
                {errors[key]}
              </Alert>
            )}
          </div>
        );
      })}
      {error && <Alert variant="error">{error}</Alert>}
      <Button
        type="submit"
        pending={pending}
        pendingLabel={m.pending}
        disabled={completed || Object.values(errors).some(Boolean)}
      >
        {m.submit}
      </Button>
      <p role="status">{completed ? m.completed : ""}</p>
    </form>
  );
}

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: 10 · Dark mode and error states extend the reference design.