{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "form",
  "type": "registry:ui",
  "title": "Form",
  "description": "Locks fields while saving and moves focus to the first error.",
  "categories": [
    "forms"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://sprout.tulipfarm.ai/r/sprout-base.json",
    "https://sprout.tulipfarm.ai/r/alert.json",
    "https://sprout.tulipfarm.ai/r/badge.json",
    "https://sprout.tulipfarm.ai/r/button.json",
    "https://sprout.tulipfarm.ai/r/field.json"
  ],
  "files": [
    {
      "path": "registry/sprout/components/ui/form.tsx",
      "type": "registry:ui",
      "target": "components/ui/form.tsx",
      "content": "'use client';\n\nimport { useEffect, useRef, useState, type ReactElement, type ReactNode } from 'react';\nimport { cn } from '@/lib/sprout/classes';\nimport { Alert } from '@/components/ui/alert';\nimport { Badge } from '@/components/ui/badge';\nimport {\n  Button,\n  jumpTo,\n  useActionControl,\n  type ButtonBlockerFix as ActionBlockerFix,\n  type ButtonState as ActionControlState,\n} from '@/components/ui/button';\nimport { FieldsDisabled } from '@/components/ui/field';\n\nexport const formFooterLayoutNames = ['bar', 'stack', 'compact'] as const;\nexport const formSectionLevelNames = [2, 3] as const;\n\nexport type FormFooterLayout = (typeof formFooterLayoutNames)[number];\nexport type FormSectionLevel = (typeof formSectionLevelNames)[number];\nexport type FormBlockerFix = ActionBlockerFix;\nexport type FormActionState = ActionControlState;\n\nexport interface FormProps {\n  id?: string | undefined;\n  disabled?: boolean | undefined;\n  onSubmit: () => 'invalid' | void;\n  label?: string | undefined;\n  className?: string | undefined;\n  children: ReactNode;\n}\n\nexport function Form({ id, disabled = false, onSubmit, label, className, children }: FormProps) {\n  const formRef = useRef<HTMLFormElement>(null);\n  const [failedSubmits, setFailedSubmits] = useState(0);\n  useEffect(() => {\n    const invalid = failedSubmits > 0 ? formRef.current?.querySelector('[aria-invalid=\"true\"]') : null;\n    if (invalid) jumpTo(invalid);\n  }, [failedSubmits]);\n  return (\n    <FieldsDisabled value={disabled}>\n      <form\n        id={id}\n        ref={formRef}\n        data-slot=\"form\"\n        noValidate\n        aria-label={label}\n        className={cn('sprout-form', className)}\n        onSubmit={event => {\n          event.preventDefault();\n          if (onSubmit() === 'invalid') setFailedSubmits(count => count + 1);\n        }}\n      >\n        {children}\n      </form>\n    </FieldsDisabled>\n  );\n}\n\nexport interface FormSectionProps {\n  title: string;\n  description?: string | undefined;\n  meta?: string | undefined;\n  label?: string | undefined;\n  id?: string | undefined;\n  level?: FormSectionLevel | undefined;\n  className?: string | undefined;\n  children: ReactNode;\n}\n\nexport function FormSection({ title, description, meta, label, id, level = 2, className, children }: FormSectionProps) {\n  const Heading = level === 3 ? 'h3' : 'h2';\n  return (\n    <section\n      id={id}\n      data-slot=\"form-section\"\n      aria-label={label ?? title}\n      className={cn('sprout-form-section', className)}\n    >\n      <div className=\"sprout-form-section-header\">\n        <div className=\"sprout-form-section-text\">\n          <Heading className=\"sprout-form-section-title\">{title}</Heading>\n          {description && <p className=\"sprout-form-section-description\">{description}</p>}\n        </div>\n        {meta && <Badge variant=\"secondary\">{meta}</Badge>}\n      </div>\n      <div className=\"sprout-form-section-content\">{children}</div>\n    </section>\n  );\n}\n\nexport type FormCancel =\n  | { kind: 'reset'; label: string; onReset: () => void }\n  | { kind: 'leave'; label: string; link: ReactElement };\n\nexport interface FormFooterSubmit {\n  label: string;\n  pendingLabel: string;\n  state: FormActionState;\n}\n\nexport interface FormFooterSecondarySubmit {\n  label: string;\n  disabled: boolean;\n  onSelect: () => void;\n}\n\nexport interface FormFooterProps {\n  form?: string | undefined;\n  summary?: ReactNode;\n  submit: FormFooterSubmit;\n  secondarySubmit?: FormFooterSecondarySubmit | undefined;\n  dirty: boolean;\n  cancel?: FormCancel | undefined;\n  note?: string | undefined;\n  error?: string | undefined;\n  layout?: FormFooterLayout | undefined;\n  className?: string | undefined;\n  children?: ReactNode;\n}\n\nexport function FormFooter({\n  form,\n  summary,\n  submit,\n  secondarySubmit,\n  dirty,\n  cancel,\n  note,\n  error,\n  layout = 'bar',\n  className,\n  children,\n}: FormFooterProps) {\n  const action = useActionControl(submit.state);\n  const stack = layout === 'stack';\n  const compact = layout === 'compact';\n  const size = stack ? 'lg' : 'md';\n  const wide = stack ? 'sprout-form-footer-wide' : undefined;\n  const save = (\n    <Button type=\"submit\" form={form} size={size} className={wide} {...action.button}>\n      {submit.state.kind === 'busy' ? submit.pendingLabel : submit.label}\n    </Button>\n  );\n  const secondary = secondarySubmit && (\n    <Button\n      type=\"submit\"\n      form={form}\n      size={size}\n      variant=\"outline\"\n      className={wide}\n      disabled={secondarySubmit.disabled}\n      onClick={secondarySubmit.onSelect}\n    >\n      {secondarySubmit.label}\n    </Button>\n  );\n  const cancelButton = !cancel ? null : cancel.kind === 'leave' ? (\n    <Button variant=\"outline\" size={size} className={wide} nativeButton={false} render={cancel.link}>\n      {cancel.label}\n    </Button>\n  ) : dirty && submit.state.kind !== 'busy' ? (\n    <Button variant=\"outline\" size={size} className={wide} onClick={cancel.onReset}>\n      {cancel.label}\n    </Button>\n  ) : null;\n  const status = (\n    <>\n      {dirty && (\n        <p className=\"sprout-form-footer-dirty\">\n          <span aria-hidden=\"true\" className=\"sprout-form-footer-dirty-dot\" />\n          Unsaved changes\n        </p>\n      )}\n      {note && <p className=\"sprout-form-footer-note\">{note}</p>}\n    </>\n  );\n  return (\n    <div data-slot=\"form-footer\" data-layout={layout} className={cn('sprout-form-footer', className)}>\n      {stack ? (\n        <>\n          {status}\n          <div className=\"sprout-form-footer-stack\">\n            {save}\n            {secondary}\n            {cancelButton}\n          </div>\n        </>\n      ) : (\n        <div className=\"sprout-form-footer-row\">\n          <div className={compact && !summary ? 'sprout-form-footer-sr-only' : 'sprout-form-footer-status'}>\n            {summary ?? status}\n          </div>\n          <div className=\"sprout-form-footer-actions\">\n            {compact && children}\n            {cancelButton}\n            {secondary}\n            {save}\n          </div>\n        </div>\n      )}\n      {action.reason}\n      {error && <Alert variant=\"destructive\">{error}</Alert>}\n      {!compact && children}\n    </div>\n  );\n}\n"
    }
  ],
  "docs": "Docs and examples: https://sprout.tulipfarm.ai/components/form/",
  "meta": {
    "source": "packages/sprout/src/components/form.tsx"
  }
}
