{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "floating-label-input",
  "title": "Floating Label Input",
  "description": "A text field whose label sits inside it and floats up on focus or once filled, in outlined (label in a notch in the border), filled or underline styles, with an optional icon, clear button, validity tick, character count, helper text and a shake on error.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/floating-label-input/floating-label-input.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type FloatingLabelSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface FloatingLabelInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, \"size\" | \"value\" | \"defaultValue\" | \"onChange\"> {\n  label: string;\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  /** outlined: label sits in a notch in the border. filled: shaded field. underline: a line that grows on focus. */\n  variant?: \"outlined\" | \"filled\" | \"underline\";\n  helperText?: string;\n  error?: string;\n  /** Shows a green tick (e.g. after validation passes). */\n  valid?: boolean;\n  icon?: React.ReactNode;\n  clearable?: boolean;\n  /** Show \"12 / 40\" when maxLength is set. */\n  showCount?: boolean;\n  size?: FloatingLabelSize;\n  /** Background behind the field, used to cut the outlined notch. */\n  surface?: string;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.5)\", faint: \"rgba(245,244,241,0.3)\", fill: \"rgba(255,255,255,0.05)\", fillHover: \"rgba(255,255,255,0.08)\", border: \"rgba(255,255,255,0.14)\", borderHover: \"rgba(255,255,255,0.28)\", focus: \"#F5F4F1\", error: \"#FF7A6B\", ok: \"#3FBF7F\", surface: \"#0A0A0A\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.5)\", faint: \"rgba(10,10,10,0.3)\", fill: \"rgba(10,10,10,0.04)\", fillHover: \"rgba(10,10,10,0.07)\", border: \"rgba(10,10,10,0.18)\", borderHover: \"rgba(10,10,10,0.32)\", focus: \"#0A0A0A\", error: \"#E5484D\", ok: \"#1F9D5C\", surface: \"#FFFFFF\" },\n};\n\nconst SIZES: Record<FloatingLabelSize, { h: number; font: number; small: number; pad: number; radius: number }> = {\n  sm: { h: 44, font: 14, small: 11.5, pad: 12, radius: 11 },\n  md: { h: 52, font: 15, small: 12, pad: 14, radius: 13 },\n  lg: { h: 60, font: 16.5, small: 12.5, pad: 16, radius: 15 },\n};\n\nexport function FloatingLabelInput({\n  label,\n  value,\n  defaultValue = \"\",\n  onValueChange,\n  variant = \"outlined\",\n  helperText,\n  error,\n  valid = false,\n  icon,\n  clearable = false,\n  showCount = false,\n  size = \"md\",\n  surface,\n  theme = \"dark\",\n  className,\n  id,\n  maxLength,\n  disabled,\n  onFocus,\n  onBlur,\n  ...rest\n}: FloatingLabelInputProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const reduce = Boolean(useReducedMotion());\n  const autoId = React.useId();\n  const inputId = id ?? autoId;\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const [internal, setInternal] = React.useState(defaultValue);\n  const text = value ?? internal;\n  const [focused, setFocused] = React.useState(false);\n  const [hover, setHover] = React.useState(false);\n  const floated = focused || text.length > 0;\n  const bg = surface ?? p.surface;\n\n  const set = (v: string) => {\n    if (value === undefined) setInternal(v);\n    onValueChange?.(v);\n  };\n\n  const accent = error ? p.error : focused ? p.focus : hover ? p.borderHover : p.border;\n  const outlined = variant === \"outlined\";\n  const filled = variant === \"filled\";\n  const underline = variant === \"underline\";\n  const padLeft = icon ? s.pad + 26 : s.pad;\n  const spring = reduce ? { duration: 0 } : { type: \"spring\" as const, stiffness: 520, damping: 36 };\n\n  // Where the label rests and where it floats to.\n  const labelRest = { y: 0, scale: 1, x: 0 };\n  const labelUp = outlined ? { y: -s.h / 2, scale: 0.8, x: icon ? -26 : 0 } : { y: -s.h * 0.22, scale: 0.78, x: 0 };\n\n  return (\n    <div className={cn(\"flex w-full flex-col\", className)} style={{ gap: 6, fontFamily: \"Inter, sans-serif\" }}>\n      <motion.div\n        className=\"relative\"\n        animate={error && !reduce ? { x: [0, -6, 5, -3, 2, 0] } : { x: 0 }}\n        transition={{ duration: 0.4 }}\n        onMouseEnter={() => setHover(true)}\n        onMouseLeave={() => setHover(false)}\n        style={{ opacity: disabled ? 0.5 : 1 }}\n      >\n        <div\n          className=\"relative flex items-center\"\n          style={{\n            height: s.h,\n            borderRadius: underline ? 0 : s.radius,\n            background: filled ? (hover || focused ? p.fillHover : p.fill) : \"transparent\",\n            border: outlined ? `1px solid ${accent}` : \"none\",\n            borderBottom: underline || filled ? `1px solid ${error ? p.error : p.border}` : outlined ? `1px solid ${accent}` : undefined,\n            boxShadow: outlined && focused ? `0 0 0 3px color-mix(in srgb, ${error ? p.error : p.focus} 14%, transparent)` : \"none\",\n            borderBottomLeftRadius: filled ? 0 : undefined,\n            borderBottomRightRadius: filled ? 0 : undefined,\n            transition: \"border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease\",\n          }}\n        >\n          {icon && (\n            <span className=\"pointer-events-none absolute flex\" style={{ left: s.pad, color: focused ? p.text : p.muted, transition: \"color 0.18s ease\" }}>\n              {icon}\n            </span>\n          )}\n          <input\n            ref={inputRef}\n            id={inputId}\n            value={text}\n            maxLength={maxLength}\n            disabled={disabled}\n            onChange={(e) => set(e.target.value)}\n            onFocus={(e) => {\n              setFocused(true);\n              onFocus?.(e);\n            }}\n            onBlur={(e) => {\n              setFocused(false);\n              onBlur?.(e);\n            }}\n            aria-invalid={error ? true : undefined}\n            aria-describedby={error || helperText ? `${inputId}-desc` : undefined}\n            className=\"h-full w-full min-w-0 border-none bg-transparent outline-none placeholder:opacity-0\"\n            style={{ paddingLeft: underline ? 0 : padLeft, paddingRight: s.pad + (clearable || valid ? 28 : 0), paddingTop: outlined ? 0 : s.h * 0.28, fontSize: s.font, color: p.text }}\n            {...rest}\n          />\n          <motion.label\n            htmlFor={inputId}\n            className=\"pointer-events-none absolute origin-left font-medium whitespace-nowrap\"\n            style={{ left: underline ? 0 : padLeft, top: \"50%\", marginTop: -s.font * 0.7, fontSize: s.font, lineHeight: `${s.font * 1.4}px`, padding: outlined ? \"0 5px\" : 0, marginLeft: outlined ? -5 : 0, background: outlined && floated ? bg : \"transparent\", color: error ? p.error : floated ? (focused ? p.text : p.muted) : p.muted, borderRadius: 4 }}\n            initial={false}\n            animate={floated ? labelUp : labelRest}\n            transition={spring}\n          >\n            {label}\n          </motion.label>\n          <div className=\"absolute flex items-center\" style={{ right: s.pad, gap: 6 }}>\n            <AnimatePresence initial={false}>\n              {clearable && text && !disabled && (\n                <motion.button\n                  key=\"clear\"\n                  type=\"button\"\n                  aria-label={`Clear ${label}`}\n                  onMouseDown={(e) => e.preventDefault()}\n                  onClick={() => {\n                    set(\"\");\n                    inputRef.current?.focus();\n                  }}\n                  className=\"flex cursor-pointer items-center justify-center rounded-full border-none outline-none focus-visible:ring-2\"\n                  style={{ width: 20, height: 20, background: p.fillHover, color: p.muted }}\n                  initial={{ scale: 0, opacity: 0 }}\n                  animate={{ scale: 1, opacity: 1 }}\n                  exit={{ scale: 0, opacity: 0 }}\n                >\n                  <svg width=\"9\" height=\"9\" viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                    <path d=\"M3 3l6 6M9 3L3 9\" />\n                  </svg>\n                </motion.button>\n              )}\n              {valid && !error && (\n                <motion.span key=\"ok\" className=\"flex items-center justify-center rounded-full\" style={{ width: 20, height: 20, background: p.ok }} initial={{ scale: 0 }} animate={{ scale: 1 }} exit={{ scale: 0 }} transition={{ type: \"spring\", stiffness: 600, damping: 24 }} aria-label=\"Valid\" role=\"img\">\n                  <svg width=\"10\" height=\"10\" viewBox=\"0 0 12 12\" fill=\"none\" aria-hidden=\"true\">\n                    <path d=\"M2.4 6.3 4.9 8.7 9.6 3.4\" stroke=\"#0A0A0A\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n                  </svg>\n                </motion.span>\n              )}\n            </AnimatePresence>\n          </div>\n          {(underline || filled) && <motion.span aria-hidden=\"true\" className=\"absolute right-0 -bottom-px left-0 block\" style={{ height: 2, background: error ? p.error : p.focus, originX: 0.5 }} initial={false} animate={{ scaleX: focused || error ? 1 : 0 }} transition={{ duration: reduce ? 0 : 0.25, ease: [0.22, 1, 0.36, 1] }} />}\n        </div>\n      </motion.div>\n      {(helperText || error || (showCount && maxLength)) && (\n        <div className=\"flex justify-between\" style={{ gap: 12, paddingLeft: underline ? 0 : 4, fontSize: s.small }}>\n          <AnimatePresence mode=\"wait\" initial={false}>\n            <motion.span key={error ? \"err\" : \"help\"} id={`${inputId}-desc`} role={error ? \"alert\" : undefined} style={{ color: error ? p.error : p.muted }} initial={{ opacity: 0, y: -3 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: -3 }} transition={{ duration: 0.15 }}>\n              {error ?? helperText}\n            </motion.span>\n          </AnimatePresence>\n          {showCount && maxLength && (\n            <span className=\"tabular-nums\" style={{ color: text.length >= maxLength ? p.error : p.faint }}>\n              {text.length} / {maxLength}\n            </span>\n          )}\n        </div>\n      )}\n    </div>\n  );\n}\n\nexport default FloatingLabelInput;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}