{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-toolbar-expandable",
  "title": "Toolbar expandable",
  "description": "An expandable toolbar that reveals additional options with animations.",
  "dependencies": [
    "motion",
    "react-use-measure"
  ],
  "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",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "components/core/toolbar-expandable.tsx",
      "content": "'use client';\n\nimport React, { useRef, useState } from 'react';\nimport useMeasure from 'react-use-measure';\nimport { AnimatePresence, motion, MotionConfig } from 'motion/react';\nimport { cn } from '@/lib/utils';\nimport useClickOutside from '@/hooks/useClickOutside';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  FolderIcon,\n  MessageCircleIcon,\n  UserIcon,\n  WalletIcon,\n} from '@/registry/ndeko/lib/icons';\n\nconst transition = {\n  type: 'spring' as const,\n  bounce: 0.1,\n  duration: 0.25,\n};\n\nconst PANEL_BUTTON =\n  'bg-card text-foreground hairline-ring ring-foreground/12 hover:bg-foreground/[0.03] focus-visible:ring-ring relative h-8 w-full scale-100 appearance-none items-center justify-center rounded-full px-3.5 text-[13px] font-medium shadow-[0_1px_2px_rgb(0_0_0/0.05)] transition-[color,background-color,scale] duration-150 ease-(--ease-out-strong) select-none focus-visible:ring-2 active:scale-[0.97] dark:bg-foreground/[0.04] dark:ring-foreground/15';\n\nconst TOOL_BUTTON =\n  '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]';\n\nfunction toolStateOf(isActive: boolean) {\n  if (isActive) {\n    return 'bg-foreground/[0.06] text-foreground';\n  }\n  return '';\n}\n\nfunction panelDisplayOf(isSelected: boolean) {\n  if (isSelected) {\n    return 'block';\n  }\n  return 'hidden';\n}\n\nfunction panelOpacityOf(isSelected: boolean) {\n  if (isSelected) {\n    return 1;\n  }\n  return 0;\n}\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\nconst ITEMS = [\n  {\n    id: 1,\n    label: 'User',\n    title: <UserIcon className='size-5' />,\n    content: (\n      <div className='flex flex-col space-y-4'>\n        <div className='text-foreground flex flex-col space-y-1'>\n          <div className='bg-primary/15 text-primary-ink flex h-8 w-8 items-center justify-center rounded-full text-xs font-medium'>\n            NC\n          </div>\n          <span>ndekocode</span>\n        </div>\n        <button className={PANEL_BUTTON} type='button'>\n          Edit profile\n        </button>\n      </div>\n    ),\n  },\n  {\n    id: 2,\n    label: 'Messages',\n    title: <MessageCircleIcon className='size-5' />,\n    content: (\n      <div className='flex flex-col space-y-4'>\n        <div className='text-foreground'>You have 3 new messages.</div>\n        <button className={PANEL_BUTTON} type='button'>\n          View more\n        </button>\n      </div>\n    ),\n  },\n  {\n    id: 3,\n    label: 'Documents',\n    title: <FolderIcon className='size-5' />,\n    content: (\n      <div className='flex flex-col space-y-4'>\n        <div className='text-foreground flex flex-col'>\n          <div className='space-y-1'>\n            <div>Project_Proposal.pdf</div>\n            <div>Meeting_Notes.docx</div>\n            <div>Financial_Report.xls</div>\n          </div>\n        </div>\n        <button className={PANEL_BUTTON} type='button'>\n          Manage documents\n        </button>\n      </div>\n    ),\n  },\n  {\n    id: 4,\n    label: 'Wallet',\n    title: <WalletIcon className='size-5' />,\n    content: (\n      <div className='flex flex-col space-y-4'>\n        <div className='text-foreground flex flex-col'>\n          <span className='text-muted-foreground'>Current balance</span>\n          <span className='tabular-nums'>$1,250.32</span>\n        </div>\n        <button className={PANEL_BUTTON} type='button'>\n          View transactions\n        </button>\n      </div>\n    ),\n  },\n];\n\nexport default function ToolbarExpandable() {\n  const [active, setActive] = useState<number | null>(null);\n  const [contentRef, { height: heightContent }] = useMeasure();\n  const [menuRef, { width: widthContainer }] = useMeasure();\n  const ref = useRef<HTMLDivElement>(null);\n  const [isOpen, setIsOpen] = useState(false);\n  const [maxWidth, setMaxWidth] = useState(0);\n\n  useClickOutside(ref, () => {\n    setIsOpen(false);\n    setActive(null);\n  });\n\n  const isFirstMeasure = Boolean(widthContainer) && maxWidth === 0;\n  if (isFirstMeasure) {\n    setMaxWidth(widthContainer);\n  }\n\n  return (\n    <ReducedMotionConfig>\n      <MotionConfig transition={transition}>\n        <div className='absolute bottom-8' ref={ref}>\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            <div className='overflow-hidden'>\n              <AnimatePresence initial={false} mode='sync'>\n                {isOpen && (\n                  <motion.div\n                    key='content'\n                    initial={{ height: 0 }}\n                    animate={{ height: heightContent || 0 }}\n                    exit={{ height: 0 }}\n                    style={{\n                      width: maxWidth,\n                    }}\n                  >\n                    <div ref={contentRef} className='p-2'>\n                      {ITEMS.map((item) => {\n                        const isSelected = active === item.id;\n\n                        return (\n                          <motion.div\n                            key={item.id}\n                            initial={{ opacity: 0 }}\n                            animate={{ opacity: panelOpacityOf(isSelected) }}\n                            exit={{ opacity: 0 }}\n                          >\n                            <div\n                              className={cn(\n                                'px-2 pt-2 text-[13px]',\n                                panelDisplayOf(isSelected)\n                              )}\n                            >\n                              {item.content}\n                            </div>\n                          </motion.div>\n                        );\n                      })}\n                    </div>\n                  </motion.div>\n                )}\n              </AnimatePresence>\n            </div>\n            <div className='flex space-x-2 p-2' ref={menuRef}>\n              {ITEMS.map((item) => (\n                <button\n                  key={item.id}\n                  aria-label={item.label}\n                  className={cn(TOOL_BUTTON, toolStateOf(active === item.id))}\n                  type='button'\n                  onClick={() => {\n                    if (!isOpen) setIsOpen(true);\n                    if (active === item.id) {\n                      setIsOpen(false);\n                      setActive(null);\n                      return;\n                    }\n\n                    setActive(item.id);\n                  }}\n                >\n                  {item.title}\n                </button>\n              ))}\n            </div>\n          </div>\n        </div>\n      </MotionConfig>\n    </ReducedMotionConfig>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/core/toolbar-expandable.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"
}