{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "input-24",
  "title": "Input with clear button",
  "description": "A clear button that appears with a value and empties the field.",
  "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-24.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useRef, useState, type ChangeEvent } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { CircleXIcon } 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\nexport default function Input24() {\n  const [projectName, setProjectName] = useState('Q3 launch plan');\n  const inputRef = useRef<HTMLInputElement>(null);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const swapVariants = swapVariantsOf(shouldReduceMotion);\n  const hasValue = projectName !== '';\n\n  function changeProjectName(event: ChangeEvent<HTMLInputElement>) {\n    setProjectName(event.currentTarget.value);\n  }\n\n  function clearProjectName() {\n    setProjectName('');\n    inputRef.current?.focus();\n  }\n\n  return (\n    <Field className='w-full max-w-xs'>\n      <FieldLabel>Project name</FieldLabel>\n      <div className='relative'>\n        <Input\n          ref={inputRef}\n          className='pe-8'\n          placeholder='Name your project'\n          value={projectName}\n          onChange={changeProjectName}\n        />\n        <AnimatePresence initial={false}>\n          {hasValue && (\n            <motion.button\n              key='clear'\n              type='button'\n              className={FIELD_BUTTON}\n              onClick={clearProjectName}\n              aria-label='Clear project name'\n              variants={swapVariants}\n              initial='enter'\n              animate='visible'\n              exit='exit'\n              transition={SWAP_TRANSITION}\n            >\n              <CircleXIcon className='size-4' />\n            </motion.button>\n          )}\n        </AnimatePresence>\n      </div>\n    </Field>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "input"
  ],
  "type": "registry:component"
}