{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-toolbar-dynamic",
  "title": "Toolbar dynamic",
  "description": "A toolbar component with dynamic appearance based on user interaction.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "components/core/toolbar-dynamic.tsx",
      "content": "'use client';\nimport React, { useRef, useState } from 'react';\nimport { motion, MotionConfig } from 'motion/react';\nimport useClickOutside from '@/hooks/useClickOutside';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  ArrowLeftIcon,\n  SearchIcon,\n  UserIcon,\n} from '@/registry/ndeko/lib/icons';\n\nconst transition = {\n  type: 'spring' as const,\n  bounce: 0.1,\n  duration: 0.2,\n};\n\nconst OPEN_WIDTH = '300px';\n\nconst CLOSED_WIDTH = '98px';\n\nfunction ReducedMotionConfig({ children }: { children: React.ReactNode }) {\n  const prefersReducedMotion = usePrefersReducedMotion();\n  if (!prefersReducedMotion) {\n    return children;\n  }\n  return <MotionConfig reducedMotion='always'>{children}</MotionConfig>;\n}\n\nfunction toolbarWidthOf(isOpen: boolean) {\n  if (isOpen) {\n    return OPEN_WIDTH;\n  }\n  return CLOSED_WIDTH;\n}\n\nfunction Button({\n  children,\n  onClick,\n  disabled,\n  ariaLabel,\n}: {\n  children: React.ReactNode;\n  onClick?: () => void;\n  disabled?: boolean;\n  ariaLabel?: string;\n}) {\n  return (\n    <button\n      className='text-muted-foreground hover:bg-foreground/5 hover:text-foreground focus-visible:ring-ring relative flex h-9 w-9 shrink-0 scale-100 appearance-none items-center justify-center rounded-lg transition-[color,background-color,scale] duration-150 ease-(--ease-out-strong) select-none focus-visible:ring-2 focus-visible:outline-hidden active:scale-[0.97] disabled:pointer-events-none disabled:opacity-50'\n      type='button'\n      onClick={onClick}\n      disabled={disabled}\n      aria-label={ariaLabel}\n    >\n      {children}\n    </button>\n  );\n}\n\nexport default function ToolbarDynamic() {\n  const [isOpen, setIsOpen] = useState(false);\n  const containerRef = useRef<HTMLDivElement>(null);\n\n  useClickOutside(containerRef, () => {\n    setIsOpen(false);\n  });\n\n  return (\n    <ReducedMotionConfig>\n      <MotionConfig transition={transition}>\n        <div className='absolute bottom-8' ref={containerRef}>\n          <div className='bg-card hairline-ring ring-border h-full w-full rounded-xl shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n            <motion.div\n              animate={{\n                width: toolbarWidthOf(isOpen),\n              }}\n              initial={false}\n            >\n              <div className='overflow-hidden p-2'>\n                {!isOpen && (\n                  <div className='flex space-x-2'>\n                    <Button disabled ariaLabel='User profile'>\n                      <UserIcon className='size-5' />\n                    </Button>\n                    <Button\n                      onClick={() => setIsOpen(true)}\n                      ariaLabel='Search notes'\n                    >\n                      <SearchIcon className='size-5' />\n                    </Button>\n                  </div>\n                )}\n                {isOpen && (\n                  <div className='flex space-x-2'>\n                    <Button onClick={() => setIsOpen(false)} ariaLabel='Back'>\n                      <ArrowLeftIcon className='size-5' />\n                    </Button>\n                    <div className='relative w-full'>\n                      <input\n                        className='hairline-ring ring-border text-foreground placeholder:text-muted-foreground focus-visible:ring-ring/25 h-9 w-full rounded-lg bg-transparent p-2 text-base focus:outline-hidden focus-visible:ring-[3px] md:text-[13px]'\n                        autoFocus\n                        aria-label='Search notes'\n                        placeholder='Search notes'\n                      />\n                      <div className='absolute top-0 right-1 flex h-full items-center justify-center'></div>\n                    </div>\n                  </div>\n                )}\n              </div>\n            </motion.div>\n          </div>\n        </div>\n      </MotionConfig>\n    </ReducedMotionConfig>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/core/toolbar-dynamic.tsx"
    },
    {
      "path": "hooks/useClickOutside.tsx",
      "content": "import { RefObject, useEffect } from 'react';\n\nfunction useClickOutside<T extends HTMLElement>(\n  ref: RefObject<T | null>,\n  handler: (event: MouseEvent | TouchEvent) => void\n): void {\n  useEffect(() => {\n    const handleClickOutside = (event: MouseEvent | TouchEvent) => {\n      if (!ref || !ref.current || ref.current.contains(event.target as Node)) {\n        return;\n      }\n\n      handler(event);\n    };\n\n    document.addEventListener('mousedown', handleClickOutside);\n    document.addEventListener('touchstart', handleClickOutside);\n\n    return () => {\n      document.removeEventListener('mousedown', handleClickOutside);\n      document.removeEventListener('touchstart', handleClickOutside);\n    };\n  }, [ref, handler]);\n}\n\nexport default useClickOutside;\n",
      "type": "registry:hook"
    }
  ],
  "categories": [
    "motion"
  ],
  "type": "registry:component"
}