{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "form",
  "title": "Form",
  "description": "Fields that settle back while the form sends, a submit button whose label rises through sending to a drawn check, and server errors that open in place under the field they belong to.",
  "dependencies": [
    "@ui-sdk/core@0.1.0-beta.9",
    "@ui-sdk/react@0.1.0-beta.9"
  ],
  "registryDependencies": [
    "@keyframery/motion",
    "@keyframery/field"
  ],
  "files": [
    {
      "path": "registry/components/keyframery/core/form-core.ts",
      "content": "/* A form, as a UI SDK primitive. UI SDK ships Field (a label, a control, a description and its\n   errors, with the browser's validation shown in the page) but no form around the fields. This is\n   that form, defined with UI SDK's core: the same definition renders in React, Vue, Svelte, Solid\n   and web components.\n\n   It does what Field leaves to the page: it runs your `submit` once every field passes, keeps the\n   status of that submission (submitting, done, refused), and puts the errors your server returns\n   onto the fields they belong to. It puts them there through the browser's own validity\n   (`setCustomValidity`), so UI SDK's Field shows them exactly as it shows its own: in its\n   FieldError, with `aria-invalid` and focus on the first one. Editing a field clears its error. */\n\nimport { announce, type ChangeDetails, createChange, definePrimitive } from \"@ui-sdk/core\"\n\ntype FormStatus = \"idle\" | \"submitting\" | \"success\" | \"error\"\n\n/** What `submit` may return: messages for named fields, and one line for the whole form. */\ntype FormResult = { errors?: Record<string, string>; message?: string } | void | undefined\n\n// None of these reasons is in UI SDK's shared vocabulary.\ntype FormStatusReason = \"submit\" | \"resolve\" | \"reject\" | \"edit\" | \"reset\"\n\ntype FormOptions = {\n  /** Runs when the form is submitted and every field is valid, with the form's data. Return or\n      resolve to `{ errors: { email: \"…\" } }` to mark fields invalid with your messages, and\n      `{ message: \"…\" }` for one line about the whole form. Throwing or rejecting refuses the\n      submission with the error's message. Without it the form submits the browser's way. */\n  submit?: (data: FormData, details: { event?: Event }) => FormResult | Promise<FormResult>\n  /** Called as the submission moves between `idle`, `submitting`, `success` and `error`. */\n  onStatusChange?: (status: FormStatus, details: ChangeDetails<FormStatusReason>) => void\n  /** Clears the fields once a submission succeeds. The success status stays until the next edit. */\n  resetOnSuccess?: boolean\n}\n\ntype FormState = {\n  status: FormStatus\n  /** The line for the whole form from the last submission. */\n  message: string\n}\n\ntype Control = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement\n\nconst isControl = (el: unknown): el is Control =>\n  el instanceof HTMLInputElement || el instanceof HTMLSelectElement || el instanceof HTMLTextAreaElement\n\nconst form = definePrimitive({\n  name: \"form\",\n  options: { submit: \"action\", onStatusChange: \"callback\", resetOnSuccess: \"boolean\" },\n  state: (_options: FormOptions): FormState => ({ status: \"idle\", message: \"\" }),\n  controlled: [\"status\", \"message\"],\n  api: (context) => {\n    const change = createChange(context)\n    let root: HTMLFormElement | null = null\n    /* A reset this form starts itself keeps the success it follows. */\n    let resetting = false\n    /* Only the latest submission may write its outcome. */\n    let run = 0\n\n    const controls = () => (root ? [...root.elements].filter(isControl) : [])\n    const clearErrors = () => controls().forEach((control) => control.validity.customError && control.setCustomValidity(\"\"))\n    const setStatus = (status: FormStatus, reason: FormStatusReason, message: string, event?: Event) => {\n      context.store.set({ message })\n      change(\"status\", status, { reason, event })\n    }\n\n    return {\n      /** Connects the form element. The root part does this; it returns the cleanup. */\n      attach(el: HTMLFormElement) {\n        root = el\n        /* Capture, so the error is cleared before the field reads the control's validity again. */\n        const edit = (event: Event) => {\n          const target = event.target\n          if (isControl(target) && target.validity.customError) target.setCustomValidity(\"\")\n          const { status } = context.store.get()\n          if (status === \"success\" || status === \"error\") setStatus(\"idle\", \"edit\", \"\", event)\n        }\n        el.addEventListener(\"input\", edit, true)\n        el.addEventListener(\"change\", edit, true)\n        return () => {\n          el.removeEventListener(\"input\", edit, true)\n          el.removeEventListener(\"change\", edit, true)\n          root = null\n        }\n      },\n      /** Submits the form the way its submit button would: fields are checked first. */\n      submit() {\n        root?.requestSubmit()\n      },\n      /** Puts every field back to its default and the form back to idle. */\n      reset() {\n        root?.reset()\n      },\n      /** Handles the form's submit event. */\n      async handle(event: SubmitEvent) {\n        const { submit, resetOnSuccess } = context.options()\n        if (!submit || !root) return\n        event.preventDefault()\n        if (context.store.get().status === \"submitting\") return\n        const el = root\n        const mine = ++run\n        clearErrors()\n        setStatus(\"submitting\", \"submit\", \"\", event)\n        let result: FormResult\n        try {\n          result = await submit(new FormData(el, event.submitter), { event })\n        } catch (error) {\n          if (mine !== run) return\n          const message = error instanceof Error ? error.message : String(error ?? \"\")\n          setStatus(\"error\", \"reject\", message)\n          if (message) announce(message, { priority: \"assertive\" })\n          return\n        }\n        if (mine !== run) return\n        const errors = Object.entries(result?.errors ?? {}).filter(([, text]) => text)\n        if (errors.length) {\n          for (const [name, text] of errors) {\n            const named = el.elements.namedItem(name)\n            const target = named instanceof RadioNodeList ? named[0] : named\n            if (isControl(target)) target.setCustomValidity(text)\n          }\n          setStatus(\"error\", \"reject\", result?.message ?? \"\")\n          /* The browser reports the fields now invalid; UI SDK's Field shows each error in the page\n             and the first invalid field takes focus. */\n          el.reportValidity()\n          return\n        }\n        setStatus(\"success\", \"resolve\", result?.message ?? \"\")\n        if (result?.message) announce(result.message)\n        if (resetOnSuccess) {\n          resetting = true\n          el.reset()\n          resetting = false\n        }\n      },\n      /** Handles the form's reset event. */\n      onReset(event: Event) {\n        clearErrors()\n        run++\n        if (resetting) return\n        if (context.store.get().status !== \"idle\") setStatus(\"idle\", \"reset\", \"\", event)\n      },\n    }\n  },\n  slots: (slot) => ({\n    root: slot<{}, { status: FormStatus }>({\n      state: (state) => ({ status: state.status }),\n      attrs: (state) => ({\n        \"data-status\": state.status,\n        \"aria-busy\": state.status === \"submitting\" ? \"true\" : undefined,\n      }),\n      on: {\n        submit: (event, { api }) => void api.handle(event as SubmitEvent),\n        reset: (event, { api }) => api.onReset(event),\n      },\n      bind: (el, part) => (el instanceof HTMLFormElement ? part.api.attach(el) : undefined),\n    }),\n    /* The submit button. It stays focusable while the form submits, and ignores presses then. */\n    submit: slot<{}, { status: FormStatus }>({\n      role: \"button\",\n      focus: \"native\",\n      press: { none: \"A submit button submits its form natively; the form's submit handler does the work.\" },\n      state: (state) => ({ status: state.status }),\n      attrs: (state) => ({\n        type: \"submit\",\n        \"data-status\": state.status,\n        \"aria-disabled\": state.status === \"submitting\" ? \"true\" : undefined,\n      }),\n      on: {\n        click: (event, { store }) => {\n          if (store.get().status === \"submitting\") event.preventDefault()\n        },\n      },\n    }),\n    /* One line about the whole submission: what happened, or why it was refused. */\n    status: slot<{}, { status: FormStatus; message: string }>({\n      role: (state) => (state.status === \"error\" ? \"alert\" : \"status\"),\n      roles: [\"alert\", \"status\"],\n      present: (state) => state.message !== \"\",\n      state: (state) => ({ status: state.status, message: state.message }),\n      attrs: (state) => ({ \"data-status\": state.status }),\n    }),\n  }),\n  agent: { actions: [\"submit\", \"reset\"] },\n})\n\nexport { form, type FormOptions, type FormResult, type FormStatus }\n",
      "type": "registry:component",
      "target": "components/keyframery/core/form-core.ts"
    },
    {
      "path": "registry/components/keyframery/primitives/form.tsx",
      "content": "\"use client\"\n\n/* An animated form, on UI SDK's core and UI SDK's Field. The form's own behaviour (running your\n   `submit`, its status, server errors on the right fields) is defined in `@/components/core/form`\n   with `definePrimitive` and rendered here. The fields are UI SDK's Field, through Keyframery's\n   animated field primitive, under shadcn's names: FormItem (and FormField) is Field, FormLabel is\n   FieldLabel, FormControl is FieldControl, FormDescription is FieldDescription and FormMessage is\n   FieldError. This file adds motion only. Colours, radii, shadows and spacing stay yours.\n\n   - While the form submits, its fields settle back a little and come forward again after.\n   - FormSubmit: Press; its label changes by Direction (up) to the pending label with a spinner,\n     then to the success label as a check draws itself; refused, it comes back down to the start.\n   - FormStatus opens its own height and rises in out of a blur, as a field's error does. */\n\nimport { createParts, type PartProps, usePart } from \"@ui-sdk/react/primitive\"\nimport type { StateOf } from \"@ui-sdk/core\"\nimport * as React from \"react\"\n\nimport {\n  Field,\n  FieldControl,\n  FieldDescription,\n  FieldError,\n  FieldLabel,\n} from \"@/components/keyframery/primitives/field\"\nimport { form } from \"@/components/keyframery/core/form-core\"\nimport { cn } from \"@/lib/utils\"\n\nconst { Root: FormRoot } = createParts(form, { root: \"form\" })\n\n/* UI SDK accepts a class name or a function of state; keep both working. */\nfunction withClass<S>(base: string, className: string | ((state: S) => string | undefined) | undefined) {\n  return typeof className === \"function\" ? (state: S) => cn(base, className(state)) : cn(base, className)\n}\n\nfunction Form({ className, ...props }: React.ComponentProps<typeof FormRoot>) {\n  return (\n    <FormRoot\n      className={withClass(\n        cn(\n          \"[&_[data-slot=field]]:transition-[opacity,filter] [&_[data-slot=field]]:duration-[calc(320ms*var(--kf-speed,1))] [&_[data-slot=field]]:ease-house\",\n          \"data-[status=submitting]:[&_[data-slot=field]]:opacity-55 data-[status=submitting]:[&_[data-slot=field]]:blur-[0.6px]\",\n          \"motion-reduce:[&_[data-slot=field]]:transition-none!\",\n        ),\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\n/* Each label sits in the same grid cell; the one for the current status is in place, the ones\n   before it have risen out of the top and the ones after wait below. */\nconst label = cn(\n  \"col-start-1 row-start-1 inline-flex items-center justify-center gap-[inherit]\",\n  \"transition-[opacity,translate,filter] duration-[calc(420ms*var(--kf-speed,1))] ease-spring\",\n  \"motion-reduce:transition-none!\",\n)\n\nconst hidden = \"pointer-events-none opacity-0 blur-[3px]\"\n\ntype FormSubmitProps = Omit<PartProps<\"button\", StateOf<typeof form, \"submit\">>, \"type\"> & {\n  /** What the button says while the form submits. */\n  pendingLabel?: React.ReactNode\n  /** What the button says once the submission succeeds. */\n  successLabel?: React.ReactNode\n}\n\nfunction FormSubmit({ className, children, pendingLabel = \"Sending\", successLabel = \"Sent\", ...props }: FormSubmitProps) {\n  return usePart(\n    form,\n    \"submit\",\n    {},\n    {\n      ...props,\n      className: withClass(\n        cn(\n          \"group/submit\",\n          \"transition-[scale,background-color,color,box-shadow] duration-[calc(220ms*var(--kf-speed,1))] ease-pop\",\n          \"not-aria-disabled:active:scale-[0.96] not-aria-disabled:active:duration-[calc(90ms*var(--kf-speed,1))] not-aria-disabled:active:ease-house\",\n          \"motion-reduce:transition-none!\",\n        ),\n        className,\n      ),\n      children: (state: { status: string }) => {\n        const content = typeof children === \"function\" ? (children as (s: typeof state) => React.ReactNode)(state) : children\n        const at = state.status === \"submitting\" ? 1 : state.status === \"success\" ? 2 : 0\n        const place = (index: number) => (index === at ? \"\" : cn(hidden, index < at ? \"-translate-y-3\" : \"translate-y-3\"))\n        return (\n          <span className=\"grid gap-[inherit]\">\n            <span data-label=\"idle\" aria-hidden={at !== 0 || undefined} className={cn(label, place(0))}>\n              {content}\n            </span>\n            <span data-label=\"submitting\" aria-hidden={at !== 1 || undefined} className={cn(label, place(1))}>\n              <svg viewBox=\"0 0 16 16\" fill=\"none\" className=\"size-3.5 animate-[spin_calc(800ms*var(--kf-speed,1))_linear_infinite] motion-reduce:animate-none\" aria-hidden>\n                <circle cx=\"8\" cy=\"8\" r=\"6\" stroke=\"currentColor\" strokeOpacity=\"0.3\" strokeWidth=\"1.75\" />\n                <path d=\"M14 8a6 6 0 0 0-6-6\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" />\n              </svg>\n              {pendingLabel}\n            </span>\n            <span data-label=\"success\" aria-hidden={at !== 2 || undefined} className={cn(label, place(2))}>\n              {/* Draw: the check strokes itself in once the label is in place. */}\n              <svg viewBox=\"0 0 16 16\" fill=\"none\" className=\"size-3.5\" aria-hidden>\n                <path\n                  d=\"M3.5 8.5 6.5 11.5 12.5 4.5\"\n                  stroke=\"currentColor\"\n                  strokeWidth=\"1.75\"\n                  strokeLinecap=\"round\"\n                  strokeLinejoin=\"round\"\n                  pathLength={1}\n                  className={cn(\n                    \"[stroke-dasharray:1] transition-[stroke-dashoffset] duration-[calc(320ms*var(--kf-speed,1))] ease-house\",\n                    at === 2 ? \"[stroke-dashoffset:0] delay-[calc(140ms*var(--kf-speed,1))]\" : \"[stroke-dashoffset:1] duration-0\",\n                    \"motion-reduce:transition-none!\",\n                  )}\n                />\n              </svg>\n              {successLabel}\n            </span>\n          </span>\n        )\n      },\n    },\n    \"button\",\n  )\n}\n\n/* One line about the whole submission. With no children it shows the message `submit` returned. */\nfunction FormStatus({ className, children, ...props }: PartProps<\"p\", StateOf<typeof form, \"status\">>) {\n  return usePart(\n    form,\n    \"status\",\n    {},\n    {\n      ...props,\n      className: withClass(\n        cn(\n          \"overflow-hidden [interpolate-size:allow-keywords]\",\n          \"[transition:height_calc(480ms*var(--kf-speed,1))_var(--ease-house),opacity_calc(380ms*var(--kf-speed,1))_var(--ease-house),translate_calc(700ms*var(--kf-speed,1))_var(--ease-spring),filter_calc(480ms*var(--kf-speed,1))_var(--ease-house)]\",\n          \"starting:h-0 starting:translate-y-3 starting:opacity-0 starting:blur-[4px]\",\n          \"motion-reduce:[transition:none]!\",\n        ),\n        className,\n      ),\n      children: children ?? ((state) => state.message),\n    },\n    \"p\",\n  )\n}\n\n/* shadcn's names for UI SDK's field parts. A field takes `name`, and its control and errors wire\n   themselves; there is no separate controller to render. */\nconst FormItem = Field\nconst FormField = Field\nconst FormLabel = FieldLabel\nconst FormControl = FieldControl\nconst FormDescription = FieldDescription\nconst FormMessage = FieldError\n\nexport {\n  Form,\n  FormControl,\n  FormDescription,\n  FormField,\n  FormItem,\n  FormLabel,\n  FormMessage,\n  FormStatus,\n  FormSubmit,\n}\nexport { useFieldControl } from \"@/components/keyframery/primitives/field\"\n",
      "type": "registry:component",
      "target": "components/keyframery/primitives/form.tsx"
    },
    {
      "path": "registry/components/keyframery/form.tsx",
      "content": "\"use client\"\n\nexport * from \"@/components/keyframery/primitives/form\"\n\n/* Theming variables (set on a part or ancestor; absent values preserve the theme):\n   --form-face: Submit surface; default: bg-primary.\n   --form-ink: Submit label; default: text-primary-foreground.\n   --form-muted: Status colour; default: text-muted-foreground.\n   --form-radius: Submit corners; default: rounded-[10px].\n   --form-font: Submit size; default: text-[13px].\n   --form-gap: Form section gap; default: gap-4.\n   --form-height: Submit height; default: h-9.\n   --form-inset-x: Submit padding; default: px-4.\n*/\n\n/* Styled form: the animated primitive plus the Keyframery look. The fields are Keyframery's styled\n   Field (`@/components/ui/field`), so a form item looks and moves exactly like a field; shadcn's\n   part names point at them. The submit button is a primary key that turns the success green when\n   the submission lands. */\n\nimport * as React from \"react\"\n\nimport {\n  Field,\n  FieldControl,\n  FieldDescription,\n  FieldError,\n  FieldLabel,\n  useFieldControl,\n} from \"@/components/keyframery/field\"\nimport {\n  Form as FormPrimitive,\n  FormStatus as FormStatusPrimitive,\n  FormSubmit as FormSubmitPrimitive,\n} from \"@/components/keyframery/primitives/form\"\nimport { Speed, type SpeedProps } from \"@/lib/keyframery\"\nimport { cn } from \"@/lib/utils\"\n\n/* UI SDK accepts a class name or a function of state; keep both working. */\nfunction withClass<S>(base: string, className: string | ((state: S) => string | undefined) | undefined) {\n  return typeof className === \"function\" ? (state: S) => cn(base, className(state)) : cn(base, className)\n}\n\nfunction Form({ speed, className, ...props }: React.ComponentProps<typeof FormPrimitive> & SpeedProps) {\n  return (\n    <Speed speed={speed}>\n      <FormPrimitive className={withClass(\"flex min-w-0 flex-col gap-[var(--form-gap,1rem)]\", className)} {...props} />\n    </Speed>\n  )\n}\n\nfunction FormSubmit({ className, ...props }: React.ComponentProps<typeof FormSubmitPrimitive>) {\n  return (\n    <FormSubmitPrimitive\n      className={withClass(\n        cn(\n          \"inline-flex h-[var(--form-height,2.25rem)] cursor-pointer items-center justify-center gap-1.5 rounded-[var(--form-radius,10px)] px-[var(--form-inset-x,1rem)] text-[length:var(--form-font,13px)] leading-none font-medium whitespace-nowrap outline-none select-none\",\n          \"bg-[var(--form-face,var(--primary))] text-[color:var(--form-ink,var(--primary-foreground))] shadow-[inset_0_1px_0_rgb(255_255_255/0.14),0_1px_2px_rgb(0_0_0/0.25)]\",\n          \"dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.7),0_1px_2px_rgb(0_0_0/0.5)]\",\n          \"not-aria-disabled:hover:bg-[color-mix(in_oklab,var(--primary),var(--background)_10%)]\",\n          \"aria-disabled:cursor-progress\",\n          /* The one payoff colour, for the moment it lands. */\n          \"data-[status=success]:bg-[oklch(0.62_0.16_150)] data-[status=success]:text-white data-[status=success]:hover:bg-[oklch(0.62_0.16_150)]\",\n          \"dark:data-[status=success]:shadow-[inset_0_1px_0_rgb(255_255_255/0.25),0_1px_2px_rgb(0_0_0/0.5)]\",\n          \"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n        ),\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction FormStatus({ className, ...props }: React.ComponentProps<typeof FormStatusPrimitive>) {\n  return (\n    <FormStatusPrimitive\n      className={withClass(\n        cn(\n          \"text-[12.5px] leading-[1.45] text-[color:var(--form-muted,var(--muted-foreground))]\",\n          \"data-[status=error]:font-medium data-[status=error]:text-destructive\",\n        ),\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\n/* shadcn's names for the field parts. FormItem and FormField are the same part: a field takes the\n   `name` its control submits under, and wires its label, description and errors itself. */\nconst FormItem = Field\nconst FormField = Field\nconst FormLabel = FieldLabel\nconst FormControl = FieldControl\nconst FormDescription = FieldDescription\nconst FormMessage = FieldError\n\nexport {\n  Form,\n  FormControl,\n  FormDescription,\n  FormField,\n  FormItem,\n  FormLabel,\n  FormMessage,\n  FormStatus,\n  FormSubmit,\n  useFieldControl,\n}\n",
      "type": "registry:component",
      "target": "components/keyframery/form.tsx"
    }
  ],
  "type": "registry:component"
}