{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "input-27",
  "title": "Search with loader",
  "description": "The search icon turns into a spinner while results load.",
  "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-27.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useEffect, useState, type ChangeEvent } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  LoaderCircleIcon,\n  MicIcon,\n  SearchIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { Field, FieldLabel } from '@/registry/ndeko/ui/field';\nimport { Input } from '@/registry/ndeko/ui/input';\n\nconst SEARCH_DELAY_MS = 500;\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 searchGlyphOf(isSearching: boolean) {\n  if (isSearching) {\n    return {\n      key: 'searching',\n      icon: <LoaderCircleIcon className='size-4 animate-spin' />,\n    };\n  }\n  return { key: 'idle', icon: <SearchIcon className='size-4' /> };\n}\n\nexport default function Input27() {\n  const [query, setQuery] = useState('');\n  const [isSearching, setIsSearching] = useState(false);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const swapVariants = swapVariantsOf(shouldReduceMotion);\n  const glyph = searchGlyphOf(isSearching);\n\n  useEffect(() => {\n    if (!isSearching) {\n      return;\n    }\n    const timeout = window.setTimeout(() => {\n      setIsSearching(false);\n    }, SEARCH_DELAY_MS);\n    return () => window.clearTimeout(timeout);\n  }, [query, isSearching]);\n\n  function changeQuery(event: ChangeEvent<HTMLInputElement>) {\n    const nextQuery = event.currentTarget.value;\n    setQuery(nextQuery);\n    setIsSearching(nextQuery !== '');\n  }\n\n  return (\n    <Field className='w-full max-w-xs'>\n      <FieldLabel>Search</FieldLabel>\n      <div className='relative'>\n        <Input\n          className='peer ps-8 pe-8'\n          type='search'\n          placeholder='Search messages'\n          value={query}\n          onChange={changeQuery}\n        />\n        <span className='text-muted-foreground pointer-events-none absolute inset-y-0 start-0 flex w-8 items-center justify-center peer-disabled:opacity-50'>\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        </span>\n        <span className='sr-only' role='status'>\n          {isSearching && 'Searching'}\n        </span>\n        <button\n          type='button'\n          className={FIELD_BUTTON}\n          aria-label='Search by voice'\n        >\n          <MicIcon className='size-4' />\n        </button>\n      </div>\n    </Field>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "input"
  ],
  "type": "registry:component"
}