{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "input-23",
  "title": "Password with show toggle",
  "description": "An eye button reveals or hides the password and swaps its icon.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/field.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/input/input-23.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useId, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { EyeIcon, EyeOffIcon } from '@/registry/ndeko/lib/icons';\nimport { Field, FieldLabel } from '@/registry/ndeko/ui/field';\nimport { Input } from '@/registry/ndeko/ui/input';\n\nconst FIELD_BUTTON =\n  'text-muted-foreground hover:bg-foreground/5 hover:text-foreground focus-visible:ring-ring/25 absolute inset-y-0 end-1 my-auto flex size-6 items-center justify-center rounded-md outline-none transition-[color,background-color,box-shadow] focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50';\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst SWAP_VARIANTS: Variants = {\n  enter: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nfunction swapVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SWAP_VARIANTS;\n}\n\nfunction inputTypeOf(isVisible: boolean) {\n  if (isVisible) {\n    return 'text';\n  }\n  return 'password';\n}\n\nfunction visibilityGlyphOf(isVisible: boolean) {\n  if (isVisible) {\n    return { key: 'hide', icon: <EyeOffIcon className='size-4' /> };\n  }\n  return { key: 'show', icon: <EyeIcon className='size-4' /> };\n}\n\nexport default function Input23() {\n  const inputId = useId();\n  const [isVisible, setIsVisible] = useState(false);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const swapVariants = swapVariantsOf(shouldReduceMotion);\n  const glyph = visibilityGlyphOf(isVisible);\n\n  function toggleVisibility() {\n    setIsVisible((current) => !current);\n  }\n\n  return (\n    <Field className='w-full max-w-xs'>\n      <FieldLabel>Password</FieldLabel>\n      <div className='relative'>\n        <Input\n          id={inputId}\n          className='pe-8'\n          type={inputTypeOf(isVisible)}\n          placeholder='At least 8 characters'\n        />\n        <button\n          type='button'\n          className={FIELD_BUTTON}\n          onClick={toggleVisibility}\n          aria-label='Show password'\n          aria-pressed={isVisible}\n          aria-controls={inputId}\n        >\n          <AnimatePresence mode='popLayout' initial={false}>\n            <motion.span\n              key={glyph.key}\n              className='flex'\n              variants={swapVariants}\n              initial='enter'\n              animate='visible'\n              exit='exit'\n              transition={SWAP_TRANSITION}\n            >\n              {glyph.icon}\n            </motion.span>\n          </AnimatePresence>\n        </button>\n      </div>\n    </Field>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "input"
  ],
  "type": "registry:component"
}