{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "password-input",
  "title": "Password Input",
  "description": "A password field with an animated show/hide eye toggle, a four-segment strength meter, a live requirements checklist and a Caps Lock warning.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/password-input/password-input.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence } 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 PasswordInputSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface PasswordInputProps {\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  placeholder?: string;\n  label?: string;\n  helperText?: string;\n  minLength?: number;\n  showStrength?: boolean;\n  showRequirements?: boolean;\n  size?: PasswordInputSize;\n  theme?: \"dark\" | \"light\";\n  width?: number | string;\n  name?: string;\n  autoComplete?: string;\n  autoFocus?: boolean;\n  disabled?: boolean;\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.5)\", faint: \"rgba(245,244,241,0.16)\", bg: \"rgba(255,255,255,0.03)\", hover: \"rgba(255,255,255,0.08)\", border: \"rgba(255,255,255,0.12)\", borderHover: \"rgba(255,255,255,0.24)\", focus: \"rgba(245,244,241,0.85)\", warn: \"#F2A841\", checkBg: \"#F5F4F1\", checkFg: \"#0A0A0A\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.5)\", faint: \"rgba(10,10,10,0.12)\", bg: \"#FFFFFF\", hover: \"rgba(10,10,10,0.06)\", border: \"rgba(10,10,10,0.16)\", borderHover: \"rgba(10,10,10,0.3)\", focus: \"rgba(10,10,10,0.85)\", warn: \"#B7791F\", checkBg: \"#0A0A0A\", checkFg: \"#FFFFFF\" },\n};\n\nconst SIZES: Record<PasswordInputSize, { font: number; height: number; radius: number; padX: number; icon: number }> = {\n  sm: { font: 13, height: 36, radius: 11, padX: 12, icon: 15 },\n  md: { font: 14.5, height: 44, radius: 13, padX: 14, icon: 17 },\n  lg: { font: 16.5, height: 52, radius: 15, padX: 16, icon: 19 },\n};\n\nconst STRENGTH_LABELS = [\"\", \"Weak\", \"Fair\", \"Good\", \"Strong\"];\n\nfunction EyeIcon({ size, hidden }: { size: number; hidden: boolean }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d=\"M1.8 10S5 4.5 10 4.5 18.2 10 18.2 10 15 15.5 10 15.5 1.8 10 1.8 10Z\" />\n      <circle cx=\"10\" cy=\"10\" r=\"2.5\" />\n      <motion.path d=\"M3.5 16.5L16.5 3.5\" initial={false} animate={{ pathLength: hidden ? 1 : 0, opacity: hidden ? 1 : 0 }} transition={{ duration: 0.22, ease: \"easeOut\" }} />\n    </svg>\n  );\n}\n\nexport function checkPassword(pw: string, minLength = 8) {\n  const rules = [\n    { id: \"length\", label: `At least ${minLength} characters`, ok: pw.length >= minLength },\n    { id: \"case\", label: \"Upper and lower case letters\", ok: /[a-z]/.test(pw) && /[A-Z]/.test(pw) },\n    { id: \"number\", label: \"A number\", ok: /\\d/.test(pw) },\n    { id: \"symbol\", label: \"A symbol (e.g. ! @ #)\", ok: /[^A-Za-z0-9]/.test(pw) },\n  ];\n  const passed = rules.filter((r) => r.ok).length;\n  const score = pw.length === 0 ? 0 : Math.max(1, Math.min(4, passed - (pw.length < minLength ? 1 : 0) + (pw.length >= 14 && passed >= 3 ? 1 : 0)));\n  return { rules, score };\n}\n\nexport function PasswordInput({\n  value,\n  defaultValue = \"\",\n  onValueChange,\n  placeholder = \"Enter your password\",\n  label,\n  helperText,\n  minLength = 8,\n  showStrength = true,\n  showRequirements = true,\n  size = \"md\",\n  theme = \"dark\",\n  width = 340,\n  name,\n  autoComplete = \"new-password\",\n  autoFocus,\n  disabled = false,\n  className,\n}: PasswordInputProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const uid = React.useId();\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const controlled = value !== undefined;\n  const [internal, setInternal] = React.useState(defaultValue);\n  const [visible, setVisible] = React.useState(false);\n  const [focused, setFocused] = React.useState(false);\n  const [hovered, setHovered] = React.useState(false);\n  const [caps, setCaps] = React.useState(false);\n  const pw = controlled ? value : internal;\n  const { rules, score } = React.useMemo(() => checkPassword(pw, minLength), [pw, minLength]);\n  const borderColor = focused ? p.focus : hovered ? p.borderHover : p.border;\n  const showPanel = (showStrength || showRequirements) && pw.length > 0;\n\n  const update = (next: string) => {\n    if (!controlled) setInternal(next);\n    onValueChange?.(next);\n  };\n\n  const trackCaps = (e: React.KeyboardEvent<HTMLInputElement>) => setCaps(e.getModifierState?.(\"CapsLock\") ?? false);\n\n  return (\n    <div className={cn(\"inline-flex flex-col gap-2\", className)} style={{ width, maxWidth: \"100%\", fontFamily: \"Inter, sans-serif\", opacity: disabled ? 0.5 : 1 }}>\n      {label && (\n        <label htmlFor={`${uid}-input`} className=\"font-semibold tracking-[-0.01em]\" style={{ color: p.text, fontSize: s.font }}>\n          {label}\n        </label>\n      )}\n\n      <div\n        onMouseEnter={() => setHovered(true)}\n        onMouseLeave={() => setHovered(false)}\n        onClick={() => inputRef.current?.focus()}\n        className=\"flex items-center\"\n        style={{ height: s.height, padding: `0 6px 0 ${s.padX}px`, gap: 8, borderRadius: s.radius, background: p.bg, border: `1px solid ${borderColor}`, boxShadow: focused ? `0 0 0 3px color-mix(in srgb, ${p.focus} 14%, transparent)` : \"0 0 0 0 transparent\", transition: \"border-color 0.18s ease, box-shadow 0.18s ease\", cursor: disabled ? \"default\" : \"text\" }}\n      >\n        <input\n          ref={inputRef}\n          id={`${uid}-input`}\n          name={name}\n          type={visible ? \"text\" : \"password\"}\n          value={pw}\n          placeholder={placeholder}\n          autoComplete={autoComplete}\n          autoFocus={autoFocus}\n          disabled={disabled}\n          spellCheck={false}\n          autoCapitalize=\"off\"\n          aria-describedby={showPanel || helperText ? `${uid}-help` : undefined}\n          onChange={(e) => update(e.target.value)}\n          onFocus={() => setFocused(true)}\n          onBlur={() => {\n            setFocused(false);\n            setCaps(false);\n          }}\n          onKeyDown={trackCaps}\n          onKeyUp={trackCaps}\n          className=\"min-w-0 flex-1 border-none bg-transparent p-0 font-medium outline-none placeholder:opacity-45\"\n          style={{ color: p.text, fontSize: s.font, letterSpacing: !visible && pw ? \"0.12em\" : undefined, [\"--tw-placeholder-color\" as string]: p.muted }}\n        />\n\n        <motion.button\n          type=\"button\"\n          disabled={disabled}\n          aria-label={visible ? \"Hide password\" : \"Show password\"}\n          aria-pressed={visible}\n          onMouseDown={(e) => e.preventDefault()}\n          onClick={() => setVisible((v) => !v)}\n          whileTap={{ scale: 0.88 }}\n          className=\"flex shrink-0 cursor-pointer items-center justify-center border-none bg-transparent outline-none focus-visible:ring-2 disabled:cursor-default\"\n          style={{ width: s.height - 14, height: s.height - 14, borderRadius: s.radius - 5, color: visible ? p.text : p.muted, transition: \"background 0.14s ease, color 0.14s ease\", [\"--tw-ring-color\" as string]: p.focus }}\n          onMouseEnter={(e) => (e.currentTarget.style.background = p.hover)}\n          onMouseLeave={(e) => (e.currentTarget.style.background = \"transparent\")}\n        >\n          <EyeIcon size={s.icon} hidden={visible} />\n        </motion.button>\n      </div>\n\n      <AnimatePresence initial={false}>\n        {caps && (\n          <motion.div key=\"caps\" role=\"status\" initial={{ opacity: 0, height: 0 }} animate={{ opacity: 1, height: \"auto\" }} exit={{ opacity: 0, height: 0 }} transition={{ duration: 0.16 }} className=\"overflow-hidden\">\n            <div className=\"flex items-center gap-1.5\" style={{ color: p.warn, fontSize: s.font - 1.5 }}>\n              <svg width=\"13\" height=\"13\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"M8 2L3 8h3v3h4V8h3L8 2ZM6 13.5h4\" />\n              </svg>\n              Caps Lock is on\n            </div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n\n      <div id={`${uid}-help`} className=\"flex flex-col gap-2\">\n        <AnimatePresence initial={false}>\n          {showPanel && showStrength && (\n            <motion.div key=\"strength\" initial={{ opacity: 0, height: 0 }} animate={{ opacity: 1, height: \"auto\" }} exit={{ opacity: 0, height: 0 }} transition={{ duration: 0.2 }} className=\"overflow-hidden\">\n              <div className=\"flex items-center gap-3 pt-0.5\">\n                <div className=\"flex flex-1 gap-1.5\" role=\"meter\" aria-label=\"Password strength\" aria-valuemin={0} aria-valuemax={4} aria-valuenow={score} aria-valuetext={STRENGTH_LABELS[score]}>\n                  {[1, 2, 3, 4].map((i) => (\n                    <div key={i} className=\"relative h-1 flex-1 overflow-hidden rounded-full\" style={{ background: p.faint }}>\n                      <motion.div className=\"absolute inset-0 rounded-full\" style={{ background: p.text, originX: 0 }} initial={false} animate={{ scaleX: score >= i ? 1 : 0, opacity: 0.35 + score * 0.16 }} transition={{ type: \"spring\", stiffness: 380, damping: 32 }} />\n                    </div>\n                  ))}\n                </div>\n                <span className=\"w-11 text-right font-semibold\" style={{ color: p.text, fontSize: s.font - 2 }} aria-hidden=\"true\">\n                  {STRENGTH_LABELS[score]}\n                </span>\n              </div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n\n        <AnimatePresence initial={false}>\n          {showPanel && showRequirements && (\n            <motion.ul key=\"rules\" initial={{ opacity: 0, height: 0 }} animate={{ opacity: 1, height: \"auto\" }} exit={{ opacity: 0, height: 0 }} transition={{ duration: 0.2 }} className=\"m-0 flex list-none flex-col gap-1.5 overflow-hidden p-0\">\n              {rules.map((r) => (\n                <li key={r.id} className=\"flex items-center gap-2\" style={{ color: r.ok ? p.text : p.muted, fontSize: s.font - 2, transition: \"color 0.2s ease\" }}>\n                  <span className=\"relative flex shrink-0 items-center justify-center rounded-full\" style={{ width: 15, height: 15, border: `1.5px solid ${r.ok ? p.checkBg : p.border}`, background: r.ok ? p.checkBg : \"transparent\", transition: \"background 0.2s ease, border-color 0.2s ease\" }}>\n                    <svg width=\"9\" height=\"9\" viewBox=\"0 0 12 12\" fill=\"none\" aria-hidden=\"true\">\n                      <motion.path d=\"M2.5 6.5L5 9L9.5 3.5\" stroke={p.checkFg} strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" initial={false} animate={{ pathLength: r.ok ? 1 : 0, opacity: r.ok ? 1 : 0 }} transition={{ duration: 0.22, ease: \"easeOut\" }} />\n                    </svg>\n                  </span>\n                  <span>{r.label}</span>\n                  <span className=\"sr-only\">{r.ok ? \"(met)\" : \"(not met)\"}</span>\n                </li>\n              ))}\n            </motion.ul>\n          )}\n        </AnimatePresence>\n\n        {helperText && !showPanel && <span style={{ color: p.muted, fontSize: s.font - 1.5, lineHeight: 1.4 }}>{helperText}</span>}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}