{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "field",
  "title": "Field",
  "description": "Layout for a control with its label, description and error, plus fieldset and group helpers. Independent of any form library.",
  "dependencies": [
    "class-variance-authority"
  ],
  "registryDependencies": [
    "@corsair-ui/utils",
    "@corsair-ui/label"
  ],
  "files": [
    {
      "path": "registry/default/ui/field.tsx",
      "content": "import { cva, type VariantProps } from \"class-variance-authority\";\nimport type { ComponentProps } from \"react\";\n\nimport { cn } from \"@/registry/default/lib/utils\";\nimport { Label } from \"@/registry/default/ui/label\";\n\n/**\n * Layout for a form control with its label, description and error. It does\n * not depend on any form library: wire `id`, `htmlFor`, `aria-invalid` and\n * `aria-describedby` yourself, or use FormField from the form item.\n */\n\nfunction FieldSet({ className, ...props }: ComponentProps<\"fieldset\">) {\n  return (\n    <fieldset\n      data-slot=\"field-set\"\n      className={cn(\"flex min-w-0 flex-col gap-6\", className)}\n      {...props}\n    />\n  );\n}\n\nfunction FieldLegend({\n  className,\n  variant = \"legend\",\n  ...props\n}: ComponentProps<\"legend\"> & { variant?: \"legend\" | \"label\" }) {\n  return (\n    <legend\n      data-slot=\"field-legend\"\n      data-variant={variant}\n      className={cn(\n        \"mb-3 font-medium data-[variant=label]:text-sm data-[variant=legend]:text-base\",\n        className\n      )}\n      {...props}\n    />\n  );\n}\n\nfunction FieldGroup({ className, ...props }: ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"field-group\"\n      className={cn(\"flex w-full flex-col gap-6\", className)}\n      {...props}\n    />\n  );\n}\n\nconst fieldVariants = cva(\"group data-[invalid=true]:text-destructive flex w-full gap-3\", {\n  variants: {\n    orientation: {\n      vertical: \"flex-col [&>*]:w-full [&>.sr-only]:w-auto\",\n      // The label may sit inside FieldContent, out of reach of `peer-enabled`.\n      horizontal:\n        \"flex-row items-center [&:has(>.peer:enabled)_[data-slot=field-label]]:cursor-pointer [&>[data-slot=field-label]]:flex-auto\",\n    },\n  },\n  defaultVariants: {\n    orientation: \"vertical\",\n  },\n});\n\n/**\n * Set `data-invalid` to colour the label and `data-disabled` to dim it.\n * Horizontal puts the control and its label side by side (checkboxes, switches).\n */\nfunction Field({\n  className,\n  orientation = \"vertical\",\n  ...props\n}: ComponentProps<\"div\"> & VariantProps<typeof fieldVariants>) {\n  return (\n    <div\n      role=\"group\"\n      data-slot=\"field\"\n      data-orientation={orientation}\n      className={cn(fieldVariants({ orientation }), className)}\n      {...props}\n    />\n  );\n}\n\n/** Stacks a label and description next to a control in a horizontal Field. */\nfunction FieldContent({ className, ...props }: ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"field-content\"\n      className={cn(\"flex flex-1 flex-col gap-1.5 leading-snug\", className)}\n      {...props}\n    />\n  );\n}\n\nfunction FieldLabel({ className, ...props }: ComponentProps<typeof Label>) {\n  return (\n    <Label data-slot=\"field-label\" className={cn(\"w-fit leading-snug\", className)} {...props} />\n  );\n}\n\nfunction FieldDescription({ className, ...props }: ComponentProps<\"p\">) {\n  return (\n    <p\n      data-slot=\"field-description\"\n      className={cn(\n        \"text-muted-foreground text-sm leading-normal font-normal\",\n        \"[&>a:hover]:text-foreground [&>a]:underline [&>a]:underline-offset-4\",\n        className\n      )}\n      {...props}\n    />\n  );\n}\n\ninterface FieldErrorProps extends ComponentProps<\"div\"> {\n  /** Errors in the shape most form libraries use; duplicates and empty entries are dropped. */\n  errors?: ({ message?: string } | undefined)[];\n}\n\n/** Renders nothing when there is no message, so it can always be mounted. */\nfunction FieldError({ className, children, errors, ...props }: FieldErrorProps) {\n  const messages = [\n    ...new Set(errors?.map((error) => error?.message).filter((m): m is string => !!m)),\n  ];\n  const content =\n    children ??\n    (messages.length > 1 ? (\n      <ul className=\"ml-4 flex list-disc flex-col gap-1\">\n        {messages.map((message) => (\n          <li key={message}>{message}</li>\n        ))}\n      </ul>\n    ) : (\n      messages[0]\n    ));\n\n  if (!content) return null;\n\n  return (\n    <div\n      role=\"alert\"\n      data-slot=\"field-error\"\n      className={cn(\n        \"text-destructive text-sm font-normal\",\n        // Errors show up in response to input, so ease them in instead of popping.\n        \"fade-in-0 slide-in-from-top-1 motion-safe:animate-in ease-out\",\n        className\n      )}\n      {...props}\n    >\n      {content}\n    </div>\n  );\n}\n\nexport {\n  Field,\n  FieldContent,\n  FieldDescription,\n  FieldError,\n  FieldGroup,\n  FieldLabel,\n  FieldLegend,\n  FieldSet,\n  fieldVariants,\n  type FieldErrorProps,\n};\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}