{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "form-field",
  "type": "registry:ui",
  "title": "FormField",
  "description": "FormField wraps a control with its label and helper text.",
  "dependencies": [
    "class-variance-authority@^0.7.1"
  ],
  "registryDependencies": [
    "https://wideset.co/r/field-label.json",
    "https://wideset.co/r/helper-text.json",
    "https://wideset.co/r/styles.json",
    "https://wideset.co/r/utils.json"
  ],
  "files": [
    {
      "path": "src/components/form-field/FormField.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/form-field/FormField.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { cn } from '@/lib/wideset/utils';\n\nimport { FieldLabel } from '../field-label/FieldLabel';\nimport { HelperText } from '../helper-text/HelperText';\nimport type { FormFieldProps } from './FormField.types';\nimport {\n  formFieldContentVariants,\n  formFieldLabelVariants,\n  formFieldVariants,\n} from './FormField.variants';\n\nexport const FormField = React.forwardRef<HTMLDivElement | HTMLFieldSetElement, FormFieldProps>(\n  (\n    {\n      children,\n      variant = 'vertical',\n      className,\n      WrapperComponent = 'div',\n      errorText,\n      helperText,\n      helperTextId: helperTextIdProp,\n      label,\n      ...props\n    },\n    ref,\n  ) => {\n    const generatedHelperTextId = React.useId();\n    const helperTextId = helperTextIdProp || generatedHelperTextId;\n    const hasHelperText = Boolean(errorText || helperText);\n\n    const helperTextComponent = hasHelperText ? (\n      <HelperText\n        key={errorText ? 'error' : 'helper'}\n        state={errorText ? 'error' : 'default'}\n        showIcon={!!errorText}\n        id={helperTextId}\n      >\n        {errorText || helperText}\n      </HelperText>\n    ) : null;\n\n    let control = children;\n    if (\n      hasHelperText &&\n      React.isValidElement<React.AriaAttributes>(children) &&\n      children.type !== React.Fragment\n    ) {\n      const own = children.props;\n      // A control that already points at helperTextId keeps one copy, so the text is read once.\n      const describedBy = new Set(own['aria-describedby']?.split(/\\s+/).filter(Boolean));\n      describedBy.add(helperTextId);\n      control = React.cloneElement(children, {\n        'aria-describedby': [...describedBy].join(' '),\n        'aria-invalid': errorText ? true : own['aria-invalid'],\n      });\n    }\n\n    const content = (\n      <>\n        <div className={formFieldLabelVariants({ variant })}>\n          <FieldLabel {...props}>{label}</FieldLabel>\n          {variant === 'horizontal' && helperTextComponent}\n        </div>\n        <div className={formFieldContentVariants({ variant })}>\n          {control}\n          {variant === 'vertical' && helperTextComponent}\n        </div>\n      </>\n    );\n    const combinedClassName = cn(formFieldVariants({ variant }), className);\n\n    if (WrapperComponent === 'fieldset') {\n      return (\n        <fieldset\n          ref={ref as React.Ref<HTMLFieldSetElement>}\n          data-slot=\"form-field\"\n          className={combinedClassName}\n        >\n          {content}\n        </fieldset>\n      );\n    }\n\n    return (\n      <div\n        ref={ref as React.Ref<HTMLDivElement>}\n        data-slot=\"form-field\"\n        className={combinedClassName}\n      >\n        {content}\n      </div>\n    );\n  },\n);\n\nFormField.displayName = 'FormField';\n"
    },
    {
      "path": "src/components/form-field/FormField.types.ts",
      "type": "registry:ui",
      "target": "components/ui/wideset/form-field/FormField.types.ts",
      "content": "import type { VariantProps } from 'class-variance-authority';\nimport type { ReactNode } from 'react';\n\nimport type { FieldLabelProps } from '../field-label/FieldLabel.types';\nimport type { formFieldVariants } from './FormField.variants';\n\n/** A labeled field wrapper with helper and validation text. */\nexport type FormFieldProps = VariantProps<typeof formFieldVariants> & {\n  /** The control. A single element is linked to the helper or error text with `aria-describedby`. */\n  children: ReactNode;\n  /** Additional classes added to the root element. */\n  className?: string;\n  /** Wrapper element. Use `fieldset` to label a group of related controls. */\n  WrapperComponent?: 'div' | 'fieldset';\n  /** Validation message displayed in place of helper text when provided. */\n  errorText?: string;\n  /** Supporting text displayed when there is no error message. */\n  helperText?: string;\n  /** Id of the helper or error text. Generated when omitted. */\n  helperTextId?: string;\n  /** Field label content; connect it to the control with matching IDs. */\n  label: ReactNode;\n} & Omit<FieldLabelProps, 'children' | 'className' | 'description'>;\n"
    },
    {
      "path": "src/components/form-field/FormField.variants.ts",
      "type": "registry:ui",
      "target": "components/ui/wideset/form-field/FormField.variants.ts",
      "content": "import { cva } from 'class-variance-authority';\n\nexport const formFieldVariants = cva('flex', {\n  variants: {\n    variant: {\n      vertical: 'gap-ws-4 flex-col',\n      horizontal: 'gap-ws-5 flex-row items-start',\n    },\n  },\n  defaultVariants: {\n    variant: 'vertical',\n  },\n});\n\nexport const formFieldLabelVariants = cva('', {\n  variants: {\n    variant: {\n      vertical: '',\n      horizontal: 'gap-ws-4 flex w-full max-w-[10rem] shrink-0 flex-col',\n    },\n  },\n  defaultVariants: {\n    variant: 'vertical',\n  },\n});\n\n// Figma stacks FormField's parts with Gap/4; the helper text adds its own Gap/3 padding on top.\nexport const formFieldContentVariants = cva('gap-ws-4 flex flex-col', {\n  variants: {\n    variant: {\n      vertical: '',\n      horizontal: 'min-w-0 flex-1',\n    },\n  },\n  defaultVariants: {\n    variant: 'vertical',\n  },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "commit": "8bb3627"
  }
}
