{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "floating-label-input",
  "type": "registry:ui",
  "title": "Text Field with Floating Label",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Soft rounded input field with a spring-animated floating label, accent focus ring, inline clear button, password visibility toggle, and validation caption.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/floating-label-input.tsx",
      "content": "\"use client\";\n\nimport React, { useState, useId } from \"react\";\nimport { motion, useReducedMotion } from \"framer-motion\";\nimport { X, Eye, EyeOff, CheckCircle2, AlertCircle } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface FloatingLabelInputProps {\n  /** Floating label text */\n  label?: string;\n  /** Controlled input value */\n  value?: string;\n  /** Initial value for uncontrolled mode */\n  defaultValue?: string;\n  /** Callback fired when input value changes */\n  onChange?: (value: string) => void;\n  /** Input type. Default: \"text\" */\n  type?: \"text\" | \"email\" | \"password\" | \"url\";\n  /** Optional helper text below the field */\n  helperText?: string;\n  /** Optional error message (renders error ring and alert icon) */\n  error?: string;\n  /** Show clear (X) button when field has text. Default: true */\n  clearable?: boolean;\n  /** Disable input */\n  disabled?: boolean;\n  className?: string;\n}\n\nexport function FloatingLabelInput({\n  label = \"Apple ID or Email Address\",\n  value: controlledValue,\n  defaultValue = \"rishabh@boseui.com\",\n  onChange,\n  type = \"email\",\n  helperText = \"Your email is used for CLI registry authentication.\",\n  error,\n  clearable = true,\n  disabled = false,\n  className,\n}: FloatingLabelInputProps) {\n  const shouldReduceMotion = useReducedMotion() ?? false;\n  const inputId = useId();\n  const isControlled = controlledValue !== undefined;\n\n  const [internalValue, setInternalValue] = useState(defaultValue);\n  const [focused, setFocused] = useState(false);\n  const [showPassword, setShowPassword] = useState(false);\n\n  const currentValue = isControlled ? controlledValue : internalValue;\n  const isFloated = focused || currentValue.length > 0;\n\n  const updateValue = (next: string) => {\n    if (!isControlled) {\n      setInternalValue(next);\n    }\n    onChange?.(next);\n  };\n\n  const resolvedType =\n    type === \"password\" ? (showPassword ? \"text\" : \"password\") : type;\n\n  return (\n    <div className={cn(\"w-full max-w-sm\", className)}>\n      <div\n        className={cn(\n          \"relative flex h-14 w-full items-center rounded-2xl border bg-white px-4 transition-all dark:bg-[#0A0A0A]\",\n          error\n            ? \"border-red-500 ring-3 ring-red-500/15 dark:border-red-500\"\n            : focused\n              ? \"border-neutral-900 ring-3 ring-neutral-900/10 dark:border-white dark:ring-white/15\"\n              : \"border-neutral-200 hover:border-neutral-300 dark:border-neutral-800 dark:hover:border-neutral-700\",\n          disabled && \"cursor-not-allowed opacity-50\"\n        )}\n      >\n        {/* Floating Label */}\n        <motion.label\n          htmlFor={inputId}\n          initial={false}\n          animate={{\n            y: isFloated ? -10 : 0,\n            scale: isFloated ? 0.82 : 1,\n          }}\n          transition={\n            shouldReduceMotion\n              ? { duration: 0 }\n              : { type: \"spring\", stiffness: 420, damping: 30 }\n          }\n          style={{ originX: 0 }}\n          className={cn(\n            \"pointer-events-none absolute left-4 select-none text-sm font-medium transition-colors\",\n            error\n              ? \"text-red-600 dark:text-red-400\"\n              : focused\n                ? \"text-neutral-900 dark:text-white\"\n                : \"text-neutral-400 dark:text-neutral-500\"\n          )}\n        >\n          {label}\n        </motion.label>\n\n        {/* Native Input */}\n        <input\n          id={inputId}\n          type={resolvedType}\n          disabled={disabled}\n          value={currentValue}\n          onFocus={() => setFocused(true)}\n          onBlur={() => setFocused(false)}\n          onChange={(e) => updateValue(e.target.value)}\n          className=\"mt-4 w-full bg-transparent text-sm font-medium text-neutral-950 focus:outline-none disabled:cursor-not-allowed dark:text-white\"\n        />\n\n        {/* Right Controls: Clear / Password Toggle / Status */}\n        <div className=\"ml-2 flex shrink-0 items-center gap-1\">\n          {type === \"password\" && (\n            <button\n              type=\"button\"\n              aria-label={showPassword ? \"Hide password\" : \"Show password\"}\n              onClick={() => setShowPassword((v) => !v)}\n              className=\"rounded-lg p-1 text-neutral-400 transition-colors hover:bg-neutral-100 hover:text-neutral-900 dark:hover:bg-neutral-900 dark:hover:text-white\"\n            >\n              {showPassword ? (\n                <EyeOff className=\"h-4 w-4\" />\n              ) : (\n                <Eye className=\"h-4 w-4\" />\n              )}\n            </button>\n          )}\n\n          {clearable && currentValue.length > 0 && !disabled && (\n            <button\n              type=\"button\"\n              aria-label=\"Clear input\"\n              onMouseDown={(e) => e.preventDefault()}\n              onClick={() => updateValue(\"\")}\n              className=\"rounded-full bg-neutral-100 p-1 text-neutral-500 transition-colors hover:bg-neutral-200 hover:text-neutral-900 dark:bg-neutral-900 dark:text-neutral-400 dark:hover:bg-neutral-800 dark:hover:text-white\"\n            >\n              <X className=\"h-3 w-3\" />\n            </button>\n          )}\n        </div>\n      </div>\n\n      {/* Helper or Error Caption */}\n      {(error || helperText) && (\n        <div className=\"mt-1.5 flex items-center gap-1.5 px-1 text-[11px]\">\n          {error ? (\n            <>\n              <AlertCircle className=\"h-3.5 w-3.5 shrink-0 text-red-500\" />\n              <span className=\"font-medium text-red-600 dark:text-red-400\">\n                {error}\n              </span>\n            </>\n          ) : (\n            <>\n              <CheckCircle2 className=\"h-3.5 w-3.5 shrink-0 text-neutral-400\" />\n              <span className=\"text-neutral-500 dark:text-neutral-400\">\n                {helperText}\n              </span>\n            </>\n          )}\n        </div>\n      )}\n    </div>\n  );\n}\n\nexport default FloatingLabelInput;\n",
      "type": "registry:ui",
      "target": "components/ui/floating-label-input.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
