{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "input-61",
  "title": "Password with Caps Lock warning",
  "description": "The hint under the field becomes a warning while Caps Lock is on and the field has focus.",
  "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/kbd.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/input/input-61.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { TriangleAlertIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Field, FieldDescription, FieldLabel } from '@/registry/ndeko/ui/field';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { Kbd } from '@/registry/ndeko/ui/kbd';\n\ntype ModifierEvent = { getModifierState: (key: 'CapsLock') => boolean };\n\nconst LINE = 'flex h-5 items-center gap-1.5';\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst LINE_VARIANTS: Variants = {\n  enter: { opacity: 0, filter: 'blur(2px)' },\n  visible: { opacity: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, filter: 'blur(2px)' },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nfunction lineVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return LINE_VARIANTS;\n}\n\nfunction isCapsLockOnIn(event: ModifierEvent) {\n  return event.getModifierState('CapsLock');\n}\n\nfunction lineToneOf(showsWarning: boolean) {\n  if (showsWarning) {\n    return 'text-warning-foreground';\n  }\n  return '';\n}\n\nfunction HintLine({ showsWarning }: { showsWarning: boolean }) {\n  if (showsWarning) {\n    return (\n      <>\n        <TriangleAlertIcon className='size-3.5' />\n        <Kbd>Caps Lock</Kbd>\n        is on\n      </>\n    );\n  }\n  return 'Use 12 or more characters';\n}\n\nexport default function Input61() {\n  const [isCapsLockOn, setIsCapsLockOn] = useState(false);\n  const [isFocused, setIsFocused] = useState(false);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const lineVariants = lineVariantsOf(shouldReduceMotion);\n  const showsWarning = isCapsLockOn && isFocused;\n  const lineKey = String(showsWarning);\n\n  function readCapsLock(event: ModifierEvent) {\n    setIsCapsLockOn(isCapsLockOnIn(event));\n  }\n\n  function markFocused() {\n    setIsFocused(true);\n  }\n\n  function markBlurred() {\n    setIsFocused(false);\n  }\n\n  return (\n    <Field className='w-full max-w-xs'>\n      <FieldLabel>Password</FieldLabel>\n      <Input\n        type='password'\n        autoComplete='current-password'\n        placeholder='Enter your password'\n        onKeyDown={readCapsLock}\n        onKeyUp={readCapsLock}\n        onPointerDown={readCapsLock}\n        onFocus={markFocused}\n        onBlur={markBlurred}\n      />\n      <FieldDescription className='relative flex'>\n        <AnimatePresence mode='popLayout' initial={false}>\n          <motion.span\n            key={lineKey}\n            className={cn(LINE, lineToneOf(showsWarning))}\n            variants={lineVariants}\n            initial='enter'\n            animate='visible'\n            exit='exit'\n            transition={SWAP_TRANSITION}\n          >\n            <HintLine showsWarning={showsWarning} />\n          </motion.span>\n        </AnimatePresence>\n      </FieldDescription>\n      <span className='sr-only' role='status'>\n        {showsWarning && 'Caps Lock is on'}\n      </span>\n    </Field>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "input"
  ],
  "type": "registry:component"
}