{
  "name": "form-fields",
  "type": "registry:ui",
  "framework": "react",
  "title": "Form Fields",
  "description": "Inputs, textareas, selects, labels, helper text, switches and checkboxes styled for the newt/ui dark theme.",
  "dependencies": [
    "radix-ui"
  ],
  "files": [
    {
      "path": "ui/form-fields.tsx",
      "content": "\"use client\"\n\nimport {\n  Checkbox as CheckboxPrimitive,\n  Label as LabelPrimitive,\n  Switch as SwitchPrimitive,\n} from \"radix-ui\"\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface FieldProps extends React.ComponentProps<\"div\"> {\n  /**\n   * Marks the whole field as failing validation. The controls inside it read\n   * `data-invalid` from this wrapper, so one prop restyles the group rather\n   * than each control being told separately.\n   */\n  invalid?: boolean\n}\n\nconst Field = React.forwardRef<HTMLDivElement, FieldProps>(\n  ({ className, invalid = false, ...props }, ref) => (\n    <div\n      ref={ref}\n      data-invalid={invalid || undefined}\n      className={cn(\"group/field flex flex-col gap-2\", className)}\n      {...props}\n    />\n  )\n)\nField.displayName = \"Field\"\n\n/*\n * Radix Label is a native `<label>` that does not select its text on a\n * double press, so a quick second press on it only reaches the control.\n */\nconst Label = React.forwardRef<\n  React.ComponentRef<typeof LabelPrimitive.Root>,\n  React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>\n>(({ className, ...props }, ref) => (\n  <LabelPrimitive.Root\n    ref={ref}\n    className={cn(\n      \"text-xs font-bold uppercase tracking-[0.02em] text-newt-text-secondary\",\n      className\n    )}\n    {...props}\n  />\n))\nLabel.displayName = \"Label\"\n\n/*\n * The invalid border is driven by the field wrapper rather than by a prop on\n * each control, so a form library that only knows \"this field is in error\"\n * needs to say it once.\n */\nconst controlClassName =\n  \"w-full rounded-[var(--newt-radius-sm)] border border-newt-border bg-newt-bg-input px-3 py-2.5 font-[family-name:var(--newt-font-sans)] text-sm text-newt-text-primary transition-colors duration-fast ease-newt placeholder:text-newt-text-muted focus:border-newt-brand focus:outline-none group-data-[invalid]/field:border-newt-danger aria-[invalid=true]:border-newt-danger\"\n\nconst Input = React.forwardRef<HTMLInputElement, React.ComponentProps<\"input\">>(\n  ({ className, type = \"text\", ...props }, ref) => (\n    <input\n      ref={ref}\n      type={type}\n      className={cn(controlClassName, className)}\n      {...props}\n    />\n  )\n)\nInput.displayName = \"Input\"\n\nconst Textarea = React.forwardRef<\n  HTMLTextAreaElement,\n  React.ComponentProps<\"textarea\">\n>(({ className, ...props }, ref) => (\n  <textarea\n    ref={ref}\n    className={cn(controlClassName, \"min-h-[80px] resize-y\", className)}\n    {...props}\n  />\n))\nTextarea.displayName = \"Textarea\"\n\nconst Select = React.forwardRef<\n  HTMLSelectElement,\n  React.ComponentProps<\"select\">\n>(({ className, ...props }, ref) => (\n  <select ref={ref} className={cn(controlClassName, className)} {...props} />\n))\nSelect.displayName = \"Select\"\n\nexport interface FieldHelpProps extends React.ComponentProps<\"span\"> {\n  /**\n   * `error` colours the text and announces it: a validation message that\n   * appears after a submit is useless to a reader who never sees it.\n   */\n  variant?: \"help\" | \"error\"\n}\n\nconst FieldHelp = React.forwardRef<HTMLSpanElement, FieldHelpProps>(\n  ({ className, variant = \"help\", ...props }, ref) => (\n    <span\n      ref={ref}\n      role={variant === \"error\" ? \"alert\" : undefined}\n      className={cn(\n        \"text-xs\",\n        variant === \"error\" ? \"text-newt-danger\" : \"text-newt-text-muted\",\n        className\n      )}\n      {...props}\n    />\n  )\n)\nFieldHelp.displayName = \"FieldHelp\"\n\n/*\n * Radix owns the behaviour of the two toggles: the role, the checked state,\n * the space bar and the hidden input a form reads when they carry a `name`.\n */\nconst Switch = React.forwardRef<\n  React.ComponentRef<typeof SwitchPrimitive.Root>,\n  React.ComponentPropsWithoutRef<typeof SwitchPrimitive.Root>\n>(({ className, ...props }, ref) => (\n  <SwitchPrimitive.Root\n    ref={ref}\n    className={cn(\n      \"relative inline-flex h-6 w-10 shrink-0 cursor-pointer rounded-full border border-newt-border bg-newt-bg-elevated transition-colors duration-base ease-newt disabled:cursor-not-allowed disabled:opacity-50\",\n      \"data-[state=checked]:border-newt-online data-[state=checked]:bg-newt-online\",\n      className\n    )}\n    {...props}\n  >\n    <SwitchPrimitive.Thumb className=\"absolute start-0.5 top-0.5 h-[18px] w-[18px] rounded-full bg-newt-text-muted transition-[transform,background-color] duration-base ease-newt data-[state=checked]:translate-x-[calc(var(--newt-dir)*1rem)] data-[state=checked]:bg-newt-on-accent\" />\n  </SwitchPrimitive.Root>\n))\nSwitch.displayName = \"Switch\"\n\nconst Checkbox = React.forwardRef<\n  React.ComponentRef<typeof CheckboxPrimitive.Root>,\n  React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>\n>(({ className, ...props }, ref) => (\n  <CheckboxPrimitive.Root\n    ref={ref}\n    className={cn(\n      \"group inline-flex h-5 w-5 shrink-0 cursor-pointer items-center justify-center rounded-[var(--newt-radius-sm)] border border-newt-border bg-newt-bg-input text-newt-on-accent transition-colors duration-fast ease-newt focus-visible:border-newt-brand focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50\",\n      \"data-[state=checked]:border-newt-brand data-[state=checked]:bg-newt-brand data-[state=indeterminate]:border-newt-brand data-[state=indeterminate]:bg-newt-brand\",\n      className\n    )}\n    {...props}\n  >\n    <CheckboxPrimitive.Indicator className=\"flex\">\n      <svg\n        aria-hidden=\"true\"\n        viewBox=\"0 0 16 16\"\n        width=\"12\"\n        height=\"12\"\n        fill=\"none\"\n        stroke=\"currentColor\"\n        strokeWidth=\"2.5\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n      >\n        {/* A mixed state draws a dash, so a partial group does not read as full. */}\n        <path\n          className=\"group-data-[state=indeterminate]:hidden\"\n          d=\"M3 8.5 6.5 12 13 4.5\"\n        />\n        <path\n          className=\"hidden group-data-[state=indeterminate]:block\"\n          d=\"M4 8h8\"\n        />\n      </svg>\n    </CheckboxPrimitive.Indicator>\n  </CheckboxPrimitive.Root>\n))\nCheckbox.displayName = \"Checkbox\"\n\nexport { Field, Label, Input, Textarea, Select, FieldHelp, Switch, Checkbox }\n",
      "type": "registry:ui"
    }
  ]
}