{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "field",
  "title": "Field",
  "author": "Tori Bryan",
  "description": "A label, description and error wired to one form control, with a group that sets the size of a whole form.",
  "dependencies": [
    "@base-ui/react",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "registry/ui/field.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Field as FieldPrimitive } from \"@base-ui/react/field\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\n\nimport { FieldSizeContext, type FieldSize } from \"@/lib/field-size\"\nimport { cn } from \"@/lib/utils\"\n\n// Base UI shows an error for a failed validity check; this carries the\n// `invalid` prop too, so an error set from outside, such as by a server, shows.\nconst FieldInvalidContext = React.createContext(false)\n\nconst fieldVariants = cva(\"group/field flex\", {\n  variants: {\n    orientation: {\n      vertical: \"flex-col gap-2\",\n      // A switch or checkbox leads, with its label and description beside it.\n      horizontal: \"flex-row items-start gap-3\",\n    },\n  },\n  defaultVariants: {\n    orientation: \"vertical\",\n  },\n})\n\nfunction FieldGroup({\n  size,\n  className,\n  ...props\n}: React.ComponentProps<\"div\"> & {\n  /** Sets the size of every control in the group; a field's or control's own size still wins. */\n  size?: FieldSize\n}) {\n  const inherited = React.useContext(FieldSizeContext)\n  return (\n    <FieldSizeContext.Provider value={size ?? inherited}>\n      <div\n        data-slot=\"field-group\"\n        data-size={size}\n        className={cn(\n          \"flex w-full flex-col gap-6 data-[size=sm]:gap-4\",\n          className\n        )}\n        {...props}\n      />\n    </FieldSizeContext.Provider>\n  )\n}\n\nfunction Field({\n  size,\n  orientation = \"vertical\",\n  invalid,\n  className,\n  ...props\n}: FieldPrimitive.Root.Props &\n  VariantProps<typeof fieldVariants> & {\n    /** Sets the size of the control inside; its own size still wins. */\n    size?: FieldSize\n  }) {\n  const inherited = React.useContext(FieldSizeContext)\n  return (\n    <FieldSizeContext.Provider value={size ?? inherited}>\n      <FieldInvalidContext.Provider value={invalid ?? false}>\n        <FieldPrimitive.Root\n          data-slot=\"field\"\n          data-orientation={orientation}\n          invalid={invalid}\n          className={cn(fieldVariants({ orientation }), className)}\n          {...props}\n        />\n      </FieldInvalidContext.Provider>\n    </FieldSizeContext.Provider>\n  )\n}\n\n/** One option in a radio or checkbox group, with its own label and description. */\nfunction FieldItem({ className, ...props }: FieldPrimitive.Item.Props) {\n  return (\n    <FieldPrimitive.Item\n      data-slot=\"field-item\"\n      className={cn(\"flex items-start gap-3\", className)}\n      {...props}\n    />\n  )\n}\n\nfunction FieldContent({ className, ...props }: React.ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"field-content\"\n      className={cn(\"flex min-w-0 flex-1 flex-col gap-1.5\", className)}\n      {...props}\n    />\n  )\n}\n\nfunction FieldLabel({ className, ...props }: FieldPrimitive.Label.Props) {\n  return (\n    <FieldPrimitive.Label\n      data-slot=\"field-label\"\n      className={cn(\n        \"group/field-label flex w-fit items-center gap-2 text-sm leading-none font-medium select-none group-data-disabled/field:cursor-not-allowed group-data-disabled/field:opacity-50\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction FieldDescription({\n  className,\n  ...props\n}: FieldPrimitive.Description.Props) {\n  return (\n    <FieldPrimitive.Description\n      data-slot=\"field-description\"\n      className={cn(\n        \"text-sm text-muted-foreground group-data-disabled/field:opacity-50\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction FieldError({\n  match,\n  className,\n  ...props\n}: FieldPrimitive.Error.Props) {\n  const invalid = React.useContext(FieldInvalidContext)\n  return (\n    <FieldPrimitive.Error\n      data-slot=\"field-error\"\n      match={match ?? (invalid || undefined)}\n      className={cn(\"text-sm text-destructive\", className)}\n      {...props}\n    />\n  )\n}\n\nexport {\n  Field,\n  FieldContent,\n  FieldDescription,\n  FieldError,\n  FieldGroup,\n  FieldItem,\n  FieldLabel,\n  fieldVariants,\n}\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/lib/field-size.ts",
      "content": "import * as React from \"react\"\n\nexport type FieldSize = \"sm\" | \"default\"\n\n/**\n * The size a FieldGroup or Field sets for the controls inside it. It lives\n * here rather than in the Field part so a control can read it without\n * installing Field.\n */\nexport const FieldSizeContext = React.createContext<FieldSize | undefined>(\n  undefined\n)\n\n/** A control's own size wins, then the nearest Field's or FieldGroup's. */\nexport function useFieldSize(size?: FieldSize): FieldSize {\n  const inherited = React.useContext(FieldSizeContext)\n  return size ?? inherited ?? \"default\"\n}\n",
      "type": "registry:lib"
    }
  ],
  "cssVars": {
    "theme": {
      "text-color-destructive": "var(--destructive-text)"
    },
    "light": {
      "destructive-text": "var(--destructive)"
    },
    "dark": {
      "destructive-text": "var(--destructive)"
    }
  },
  "meta": {
    "tier": "base-components",
    "group": "Forms",
    "docs": "https://fibo.toribryan.com/?path=/docs/base-components-forms-field--docs"
  },
  "docs": "Docs and live examples: https://fibo.toribryan.com/?path=/docs/base-components-forms-field--docs",
  "categories": [
    "base-components",
    "forms"
  ],
  "type": "registry:ui"
}