{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "contact-form",
  "type": "registry:block",
  "title": "Contact form",
  "description": "A contact form built from Input, Select and Textarea, with your contact details beside it. It checks required fields, shows errors from your server on the right field, and announces the result. It makes no network call itself.",
  "categories": [
    "section"
  ],
  "dependencies": [
    "@base-ui/react@^1.9.0"
  ],
  "registryDependencies": [
    "https://facadeui.dev/r/button.json",
    "https://facadeui.dev/r/container.json",
    "https://facadeui.dev/r/input.json",
    "https://facadeui.dev/r/section.json",
    "https://facadeui.dev/r/section-header.json",
    "https://facadeui.dev/r/select.json",
    "https://facadeui.dev/r/textarea.json",
    "https://facadeui.dev/r/types.json",
    "https://facadeui.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "src/sections/contact-form.tsx",
      "type": "registry:component",
      "target": "components/sections/contact-form.tsx",
      "content": "\"use client\"\n\n/**\n * ContactForm — a contact form built from `Input`, `Select` and `Textarea`,\n * with optional contact details beside it.\n *\n * Presentation and wiring only, like `Newsletter`: it owns no network call.\n * `onSubmit` gets the values; drive `status` and `errors` from whatever your\n * form action or mutation returns.\n *\n * a11y:\n *\n *  - Base UI's `Form` checks required fields and email format on submit, shows\n *    the browser's message under each field and focuses the first problem.\n *  - Server errors passed in `errors` are shown under their fields, marked\n *    invalid, and focus moves to the first one, so nobody has to hunt for it.\n *    Editing a field clears its error, so the form can be sent again.\n *  - The outcome is announced through a polite live region that exists from\n *    the first render. While sending, the button is `aria-busy` and keeps its\n *    label.\n *  - Contact details are a `<dl>`, so each value is read with its label.\n *\n * Dependencies: @base-ui/react, react, @/lib/types,\n * @/lib/utils, @/components/ui/*.\n */\n\nimport { Form } from \"@base-ui/react/form\"\nimport {\n  useEffect,\n  useRef,\n  type ElementType,\n  type FormEvent,\n  type ReactNode,\n} from \"react\"\n\nimport type { LinkComponent, SectionBaseProps } from \"@/lib/types\"\nimport { cn, slugId } from \"@/lib/utils\"\nimport { Button } from \"@/components/ui/button\"\nimport { Container } from \"@/components/ui/container\"\nimport { Input } from \"@/components/ui/input\"\nimport { Section } from \"@/components/ui/section\"\nimport { SectionHeader } from \"@/components/ui/section-header\"\nimport { Select, type SelectOption } from \"@/components/ui/select\"\nimport { Textarea } from \"@/components/ui/textarea\"\n\nexport type ContactFormStatus = \"idle\" | \"submitting\" | \"success\" | \"error\"\n\nexport interface ContactField {\n  /** The key in the submitted values and in `errors`. */\n  name: string\n  label: string\n  /** Defaults to `text`. */\n  type?: \"text\" | \"email\" | \"tel\" | \"select\" | \"textarea\"\n  required?: boolean\n  /** The browser's autofill hint, such as `name`, `email` or `organization`. */\n  autoComplete?: string\n  placeholder?: string\n  description?: string\n  /** The choices, for `type: \"select\"`. */\n  options?: SelectOption[]\n  /** Visible lines, for `type: \"textarea\"`. */\n  rows?: number\n  /** `half` puts two fields side by side from `sm` up. */\n  width?: \"full\" | \"half\"\n}\n\nexport interface ContactDetail {\n  label: string\n  value: ReactNode\n  /** Makes the value a link, such as `mailto:` or `tel:`. */\n  href?: string\n}\n\nexport interface ContactFormProps extends SectionBaseProps {\n  title: string\n  eyebrow?: string\n  description?: string\n  /** The fields, in order. Defaults to name, email, company and message. */\n  fields?: ContactField[]\n  /** Called with the values once the browser's checks pass. */\n  onSubmit?: (values: Record<string, string>) => void\n  /** Controls the button, the live region and the error messages. */\n  status?: ContactFormStatus\n  /** Field errors from your server, keyed by field `name`. */\n  errors?: Record<string, string>\n  /** Announced on success. */\n  successMessage?: ReactNode\n  /** Announced on failure. */\n  errorMessage?: ReactNode\n  submitLabel?: string\n  /** Small print under the button, such as how the data is used. */\n  note?: ReactNode\n  /** Ways to reach you, shown beside the form. */\n  details?: ContactDetail[]\n  link?: LinkComponent\n  /** `card` puts the form on a bordered surface; `muted` on a tinted one. */\n  variant?: \"plain\" | \"muted\" | \"card\"\n}\n\nconst DEFAULT_FIELDS: ContactField[] = [\n  { name: \"name\", label: \"Name\", autoComplete: \"name\", required: true, width: \"half\" },\n  {\n    name: \"email\",\n    label: \"Email\",\n    type: \"email\",\n    autoComplete: \"email\",\n    required: true,\n    width: \"half\",\n  },\n  { name: \"company\", label: \"Company\", autoComplete: \"organization\" },\n  { name: \"message\", label: \"Message\", type: \"textarea\", rows: 5, required: true },\n]\n\nconst surfaces = {\n  plain: \"\",\n  muted: \"bg-muted rounded-2xl p-6 sm:p-8\",\n  card: \"bg-card text-card-foreground rounded-2xl border p-6 sm:p-8\",\n} as const\n\nfunction FieldFor({ field, disabled }: { field: ContactField; disabled: boolean }) {\n  const shared = {\n    label: field.label,\n    name: field.name,\n    required: field.required,\n    description: field.description,\n    disabled,\n  }\n\n  if (field.type === \"select\") {\n    return (\n      <Select {...shared} items={field.options ?? []} placeholder={field.placeholder} />\n    )\n  }\n  if (field.type === \"textarea\") {\n    return <Textarea {...shared} rows={field.rows} placeholder={field.placeholder} />\n  }\n  return (\n    <Input\n      {...shared}\n      type={field.type ?? \"text\"}\n      autoComplete={field.autoComplete}\n      placeholder={field.placeholder}\n    />\n  )\n}\n\nexport function ContactForm({\n  title,\n  eyebrow,\n  description,\n  fields = DEFAULT_FIELDS,\n  onSubmit,\n  status = \"idle\",\n  errors,\n  successMessage = \"Thanks — we will reply within two working days.\",\n  errorMessage = \"That did not send. Check the form and try again.\",\n  submitLabel = \"Send message\",\n  note,\n  details,\n  link,\n  variant = \"card\",\n  headingLevel = 2,\n  as = \"section\",\n  spacing = \"md\",\n  className,\n  id,\n}: ContactFormProps) {\n  const titleId = id ? `${id}-title` : slugId(title)\n  const formRef = useRef<HTMLFormElement>(null)\n  const submitting = status === \"submitting\"\n  const Link = (link ?? \"a\") as ElementType\n\n  // Move focus to the first field the server rejected, once per new `errors`.\n  const firstError = errors ? fields.find((field) => errors[field.name])?.name : undefined\n  useEffect(() => {\n    if (!firstError || !formRef.current) return\n    const control = formRef.current.elements.namedItem(firstError)\n    if (control instanceof HTMLElement) control.focus()\n  }, [errors, firstError])\n\n  const handleSubmit = (event: FormEvent<HTMLFormElement>) => {\n    event.preventDefault()\n    if (!onSubmit) return\n    const data = new FormData(event.currentTarget)\n    const values: Record<string, string> = {}\n    for (const field of fields) values[field.name] = String(data.get(field.name) ?? \"\")\n    onSubmit(values)\n  }\n\n  return (\n    <Section as={as} spacing={spacing} labelledBy={titleId} id={id} className={className}>\n      <Container\n        size={details?.length ? \"lg\" : \"md\"}\n        className={cn(\n          \"grid gap-12\",\n          details?.length && \"lg:grid-cols-[minmax(0,2fr)_minmax(0,3fr)] lg:gap-16\",\n        )}\n      >\n        <div className=\"flex flex-col gap-8\">\n          <SectionHeader\n            eyebrow={eyebrow}\n            title={title}\n            description={description}\n            headingLevel={headingLevel}\n            titleId={titleId}\n          />\n\n          {details?.length ? (\n            <dl className=\"flex flex-col gap-5\">\n              {details.map((detail) => (\n                <div key={detail.label} className=\"flex flex-col gap-1\">\n                  <dt className=\"text-muted-foreground text-sm\">{detail.label}</dt>\n                  <dd className=\"text-foreground font-medium\">\n                    {detail.href ? (\n                      <Link\n                        href={detail.href}\n                        className=\"focus-visible:ring-ring rounded-sm underline underline-offset-4 focus-visible:outline-none focus-visible:ring-2\"\n                      >\n                        {detail.value}\n                      </Link>\n                    ) : (\n                      detail.value\n                    )}\n                  </dd>\n                </div>\n              ))}\n            </dl>\n          ) : null}\n        </div>\n\n        {/* Form shows each error under the field with that name, and clears it\n            once the field is edited, so a corrected form can be sent again. */}\n        <Form\n          ref={formRef}\n          errors={errors}\n          onSubmit={handleSubmit}\n          aria-labelledby={titleId}\n          className={cn(\"flex flex-col gap-6\", surfaces[variant])}\n        >\n          <div className=\"grid gap-6 sm:grid-cols-2\">\n            {fields.map((field) => (\n              <div\n                key={field.name}\n                className={cn(field.width !== \"half\" && \"sm:col-span-2\")}\n              >\n                <FieldFor field={field} disabled={submitting} />\n              </div>\n            ))}\n          </div>\n\n          <div className=\"flex flex-col gap-3\">\n            <Button\n              type=\"submit\"\n              loading={submitting}\n              loadingLabel=\"Sending\"\n              className=\"self-start\"\n            >\n              {submitLabel}\n            </Button>\n            {note ? (\n              <p className=\"text-muted-foreground text-pretty text-sm\">{note}</p>\n            ) : null}\n\n            {/*\n              Always rendered, never conditionally mounted: a live region that\n              appears at the same moment as its message is routinely missed.\n            */}\n            <p\n              aria-live=\"polite\"\n              className={cn(\n                \"text-pretty text-sm\",\n                status === \"error\" ? \"text-destructive\" : \"text-muted-foreground\",\n              )}\n            >\n              {status === \"success\" ? successMessage : null}\n              {status === \"error\" ? errorMessage : null}\n            </p>\n          </div>\n        </Form>\n      </Container>\n    </Section>\n  )\n}\n"
    }
  ],
  "docs": "Import styles/facade-tokens.css in your global stylesheet, after @import \"tailwindcss\". Set headingLevel to fit the page outline (sections default to h2). Pass next/link and next/image through the link and image props. Docs: https://facadeui.dev/components/contact-form"
}
