{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "retro-form",
  "title": "RetroForm",
  "description": "A React Hook Form integration with Mac OS 9 styling. Provides RetroForm, RetroFormField, RetroFormItem, RetroFormLabel, RetroFormControl, RetroFormDescription, and RetroFormMessage components following the shadcn Form pattern.",
  "dependencies": [
    "@ui-sdk/core@0.1.0-beta.1",
    "@ui-sdk/react@0.1.0-beta.1",
    "react-hook-form"
  ],
  "registryDependencies": [
    "https://nostalgia-ui.com/r/nostalgia-theme.json",
    "https://nostalgia-ui.com/r/retro-label.json"
  ],
  "files": [
    {
      "path": "registry/new-york/ui/retro-form.tsx",
      "content": "\"use client\"\n\n/*\n * RetroForm: react-hook-form wiring with OS 9 labels, help text and errors.\n *\n * Crafted moment: none, static. Errors appear in red bold Geneva as soon\n * as react-hook-form reports them.\n *\n * RetroFormControl hands its id and aria-* to the one element inside it\n * (or to `render`), via UI SDK's renderElement. RetroFormLabel is UI SDK's\n * Label, so it names controls that render buttons (checkbox, switch,\n * radio group) as well as inputs.\n */\n\nimport * as React from \"react\"\nimport { Label as LabelPrimitive } from \"@ui-sdk/react/label\"\nimport { renderElement, type RenderProp } from \"@ui-sdk/react/primitive\"\nimport {\n  Controller,\n  FormProvider,\n  useFormContext,\n  type ControllerProps,\n  type FieldPath,\n  type FieldValues,\n} from \"react-hook-form\"\n\nimport { cn } from \"@/lib/utils\"\nimport { retroLabelVariants } from \"@/registry/new-york/ui/retro-label\"\n\nconst RetroForm = FormProvider\n\ntype RetroFormFieldContextValue<\n  TFieldValues extends FieldValues = FieldValues,\n  TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> = {\n  name: TName\n}\n\nconst RetroFormFieldContext =\n  React.createContext<RetroFormFieldContextValue | null>(null)\n\nconst RetroFormField = <\n  TFieldValues extends FieldValues = FieldValues,\n  TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({\n  ...props\n}: ControllerProps<TFieldValues, TName>) => {\n  return (\n    <RetroFormFieldContext.Provider value={{ name: props.name }}>\n      <Controller {...props} />\n    </RetroFormFieldContext.Provider>\n  )\n}\n\nconst useRetroFormField = () => {\n  const fieldContext = React.useContext(RetroFormFieldContext)\n  const itemContext = React.useContext(RetroFormItemContext)\n  const { getFieldState, formState } = useFormContext()\n\n  if (!fieldContext) {\n    throw new Error(\"useRetroFormField should be used within <RetroFormField>\")\n  }\n  if (!itemContext) {\n    throw new Error(\"useRetroFormField should be used within <RetroFormItem>\")\n  }\n\n  const fieldState = getFieldState(fieldContext.name, formState)\n\n  const { id } = itemContext\n\n  return {\n    id,\n    name: fieldContext.name,\n    formItemId: `${id}-form-item`,\n    formDescriptionId: `${id}-form-item-description`,\n    formMessageId: `${id}-form-item-message`,\n    ...fieldState,\n  }\n}\n\ntype RetroFormItemContextValue = {\n  id: string\n}\n\nconst RetroFormItemContext =\n  React.createContext<RetroFormItemContextValue | null>(null)\n\nconst RetroFormItem = React.forwardRef<\n  HTMLDivElement,\n  React.HTMLAttributes<HTMLDivElement>\n>(function RetroFormItem({ className, ...props }, ref) {\n  const id = React.useId()\n\n  return (\n    <RetroFormItemContext.Provider value={{ id }}>\n      <div ref={ref} className={cn(\"space-y-1\", className)} {...props} />\n    </RetroFormItemContext.Provider>\n  )\n})\nRetroFormItem.displayName = \"RetroFormItem\"\n\nfunction RetroFormLabel({\n  className,\n  ...props\n}: Omit<React.ComponentProps<typeof LabelPrimitive>, \"className\" | \"children\"> & {\n  className?: string\n  children?: React.ReactNode\n}) {\n  const { error, formItemId } = useRetroFormField()\n\n  return (\n    <LabelPrimitive\n      className={cn(\n        retroLabelVariants(),\n        error && \"text-[#cc0000]\",\n        className\n      )}\n      htmlFor={formItemId}\n      {...props}\n    />\n  )\n}\n\n/**\n * Passes the field's id and aria-* to its only child element (or to `render`),\n * so the label and messages point at the real control.\n */\nfunction RetroFormControl({\n  children,\n  render,\n  ...props\n}: Omit<React.HTMLAttributes<HTMLElement>, \"children\"> & {\n  children?: React.ReactElement<Record<string, unknown>>\n  render?: RenderProp\n  ref?: React.Ref<HTMLElement>\n}) {\n  const { error, formItemId, formDescriptionId, formMessageId } =\n    useRetroFormField()\n\n  return renderElement(\n    \"div\",\n    {\n      id: formItemId,\n      \"aria-describedby\": !error\n        ? `${formDescriptionId}`\n        : `${formDescriptionId} ${formMessageId}`,\n      \"aria-invalid\": !!error,\n      ...props,\n    },\n    render ?? children\n  )\n}\n\nconst RetroFormDescription = React.forwardRef<\n  HTMLParagraphElement,\n  React.HTMLAttributes<HTMLParagraphElement>\n>(function RetroFormDescription({ className, ...props }, ref) {\n  const { formDescriptionId } = useRetroFormField()\n\n  return (\n    <p\n      ref={ref}\n      id={formDescriptionId}\n      className={cn(\n        \"font-[family-name:var(--os9-font-sans)] text-[9px] text-os9-gray-700\",\n        className\n      )}\n      {...props}\n    />\n  )\n})\nRetroFormDescription.displayName = \"RetroFormDescription\"\n\nconst RetroFormMessage = React.forwardRef<\n  HTMLParagraphElement,\n  React.HTMLAttributes<HTMLParagraphElement>\n>(function RetroFormMessage({ className, children, ...props }, ref) {\n  const { error, formMessageId } = useRetroFormField()\n  const body = error ? String(error.message ?? \"\") : children\n\n  if (!body) {\n    return null\n  }\n\n  return (\n    <p\n      ref={ref}\n      id={formMessageId}\n      className={cn(\n        \"font-[family-name:var(--os9-font-sans)] text-[10px] font-bold text-[#cc0000]\",\n        className\n      )}\n      {...props}\n    >\n      {body}\n    </p>\n  )\n})\nRetroFormMessage.displayName = \"RetroFormMessage\"\n\nexport {\n  useRetroFormField,\n  RetroForm,\n  RetroFormItem,\n  RetroFormLabel,\n  RetroFormControl,\n  RetroFormDescription,\n  RetroFormMessage,\n  RetroFormField,\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}