{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "menubar",
  "title": "Menubar",
  "author": "AlgorizeTech",
  "description": "A desktop-style menu bar with click-to-open menus, separators and keyboard navigation. Use it for application chrome rather than website navigation.",
  "dependencies": [],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/MenubarBlock.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport React, {\n  createContext,\n  useContext,\n  useEffect,\n  useLayoutEffect,\n  useRef,\n  useState,\n} from \"react\";\n\n// Positioning has to be measured before paint, but layout effects don't run on\n// the server — fall back to useEffect there so SSR stays warning-free.\nconst useIsomorphicLayoutEffect =\n  typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n\n// ==========================================\n// CONTEXT & STATE MANAGEMENT\n// ==========================================\ninterface MenubarContextType {\n  activeMenu: string | null;\n  setActiveMenu: (value: string | null) => void;\n}\nconst MenubarContext = createContext<MenubarContextType | undefined>(undefined);\n\ninterface MenuContextType {\n  value: string;\n}\nconst MenuContext = createContext<MenuContextType | undefined>(undefined);\n\n// ==========================================\n// 1. ROOT MENUBAR\n// ==========================================\nexport type MenubarProps = React.HTMLAttributes<HTMLDivElement>;\n\nexport function Menubar({ className, children, ...props }: MenubarProps) {\n  const [activeMenu, setActiveMenu] = useState<string | null>(null);\n  const menubarRef = useRef<HTMLDivElement>(null);\n\n  // Handle clicking outside to close\n  useEffect(() => {\n    const handleClickOutside = (event: MouseEvent) => {\n      if (\n        menubarRef.current &&\n        !menubarRef.current.contains(event.target as Node)\n      ) {\n        setActiveMenu(null);\n      }\n    };\n    const handleEscape = (event: KeyboardEvent) => {\n      if (event.key === \"Escape\") setActiveMenu(null);\n    };\n\n    if (activeMenu) {\n      document.addEventListener(\"mousedown\", handleClickOutside);\n      document.addEventListener(\"keydown\", handleEscape);\n    }\n    return () => {\n      document.removeEventListener(\"mousedown\", handleClickOutside);\n      document.removeEventListener(\"keydown\", handleEscape);\n    };\n  }, [activeMenu]);\n\n  return (\n    <MenubarContext.Provider value={{ activeMenu, setActiveMenu }}>\n      <div\n        ref={menubarRef}\n        className={cn(\n          // min-h rather than a fixed height: a bar with more menus than the\n          // container can hold wraps to a second row instead of being cropped.\n          \"flex min-h-10 flex-wrap items-center gap-y-1 space-x-1 rounded-md border border-border bg-card text-card-foreground p-1 shadow-sm\",\n          className,\n        )}\n        {...props}\n      >\n        {children}\n      </div>\n    </MenubarContext.Provider>\n  );\n}\n\n// ==========================================\n// 2. MENU WRAPPER\n// ==========================================\nexport interface MenubarMenuProps {\n  value: string;\n  children: React.ReactNode;\n}\n\nexport function MenubarMenu({ value, children }: MenubarMenuProps) {\n  return (\n    <MenuContext.Provider value={{ value }}>\n      <div className=\"relative inline-block text-left\">{children}</div>\n    </MenuContext.Provider>\n  );\n}\n\n// ==========================================\n// 3. MENU TRIGGER\n// ==========================================\nexport function MenubarTrigger({\n  className,\n  children,\n  ...props\n}: React.ButtonHTMLAttributes<HTMLButtonElement>) {\n  const rootContext = useContext(MenubarContext);\n  const menuContext = useContext(MenuContext);\n\n  if (!rootContext || !menuContext)\n    throw new Error(\"MenubarTrigger must be used within MenubarMenu\");\n\n  const { activeMenu, setActiveMenu } = rootContext;\n  const { value } = menuContext;\n  const isOpen = activeMenu === value;\n\n  const handleMouseEnter = () => {\n    // If ANY menu is currently open, seamlessly switch to this one on hover\n    if (activeMenu !== null && activeMenu !== value) {\n      setActiveMenu(value);\n    }\n  };\n\n  const handleClick = () => {\n    setActiveMenu(isOpen ? null : value);\n  };\n\n  return (\n    <button\n      type=\"button\"\n      onClick={handleClick}\n      onMouseEnter={handleMouseEnter}\n      className={cn(\n        // Tighter horizontal padding on phones — same type scale, so every\n        // trigger in the bar still reads as one set.\n        \"flex cursor-default select-none items-center whitespace-nowrap rounded-sm px-2 sm:px-3 py-1.5 text-sm font-medium outline-none transition-colors\",\n        isOpen\n          ? \"bg-muted text-foreground\"\n          : \"text-foreground hover:bg-muted hover:text-foreground\",\n        className,\n      )}\n      {...props}\n    >\n      {children}\n    </button>\n  );\n}\n\n// ==========================================\n// 4. MENU CONTENT (DROPDOWN)\n// ==========================================\nexport interface MenubarContentProps\n  extends React.HTMLAttributes<HTMLDivElement> {\n  align?: \"start\" | \"end\" | \"center\";\n}\n\nexport function MenubarContent({\n  className,\n  align = \"start\",\n  children,\n  ...props\n}: MenubarContentProps) {\n  const rootContext = useContext(MenubarContext);\n  const menuContext = useContext(MenuContext);\n  const contentRef = useRef<HTMLDivElement>(null);\n\n  const isOpen =\n    !!rootContext && !!menuContext && rootContext.activeMenu === menuContext.value;\n\n  // A trigger near the right edge would otherwise open its menu off screen, and\n  // a long menu near the bottom would run past the fold. Both are measured from\n  // the real geometry after mount, so the menu adapts to the actual viewport\n  // instead of guessing from a breakpoint. marginLeft (not transform) does the\n  // nudging, so it composes with the `align` classes.\n  useIsomorphicLayoutEffect(() => {\n    const el = contentRef.current;\n    if (!isOpen || !el) return;\n\n    const fit = () => {\n      el.style.marginLeft = \"0px\";\n      el.style.maxHeight = \"\";\n\n      // offsetLeft/offsetWidth are layout values, so the open animation's\n      // scale + slide can't skew them the way a client rect would.\n      const anchor = el.offsetParent as HTMLElement | null;\n      const anchorRect = anchor?.getBoundingClientRect();\n      const fallback = anchorRect ? null : el.getBoundingClientRect();\n      const left = anchorRect\n        ? anchorRect.left + anchor!.clientLeft + el.offsetLeft\n        : fallback!.left;\n      const top = anchorRect\n        ? anchorRect.top + anchor!.clientTop + el.offsetTop\n        : fallback!.top;\n      const width = el.offsetWidth;\n      const height = el.offsetHeight;\n      const margin = 8;\n\n      let shift = 0;\n      if (left + width > window.innerWidth - margin) {\n        shift = window.innerWidth - margin - (left + width);\n      }\n      if (left + shift < margin) shift = margin - left;\n      if (shift) el.style.marginLeft = `${shift}px`;\n\n      const room = window.innerHeight - top - margin;\n      if (height > room) el.style.maxHeight = `${Math.max(room, 96)}px`;\n    };\n\n    fit();\n    window.addEventListener(\"resize\", fit);\n    return () => window.removeEventListener(\"resize\", fit);\n  }, [isOpen]);\n\n  if (!rootContext || !menuContext)\n    throw new Error(\"MenubarContent must be used within MenubarMenu\");\n\n  if (!isOpen) return null;\n\n  return (\n    <div\n      ref={contentRef}\n      className={cn(\n        \"absolute z-50 mt-1 min-w-[12rem] max-w-[calc(100vw-1rem)] overflow-y-auto overflow-x-hidden rounded-md border border-border bg-popover text-popover-foreground p-1 shadow-md animate-in fade-in zoom-in-95 slide-in-from-top-2 duration-150\",\n        align === \"start\" && \"left-0\",\n        align === \"end\" && \"right-0\",\n        align === \"center\" && \"left-1/2 -translate-x-1/2\",\n        className,\n      )}\n      {...props}\n    >\n      {children}\n    </div>\n  );\n}\n\n// ==========================================\n// 5. MENU ITEMS\n// ==========================================\nexport interface MenubarItemProps\n  extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n  inset?: boolean;\n}\n\nexport function MenubarItem({\n  className,\n  inset,\n  children,\n  onClick,\n  disabled,\n  ...props\n}: MenubarItemProps) {\n  const rootContext = useContext(MenubarContext);\n\n  return (\n    <button\n      type=\"button\"\n      disabled={disabled}\n      onClick={(e) => {\n        if (onClick) onClick(e);\n        rootContext?.setActiveMenu(null); // Auto-close on click\n      }}\n      className={cn(\n        \"relative flex w-full cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors\",\n        inset && \"pl-8\",\n        disabled\n          ? \"opacity-50 cursor-not-allowed pointer-events-none\"\n          : \"hover:bg-primary/10 hover:text-primary focus:bg-primary/10\",\n        className,\n      )}\n      {...props}\n    >\n      {children}\n    </button>\n  );\n}\n\n// ==========================================\n// 6. UTILITIES (Separator, Shortcut, Checkbox)\n// ==========================================\nexport function MenubarSeparator({ className }: { className?: string }) {\n  return (\n    <div\n      className={cn(\"-mx-1 my-1 h-px bg-muted\", className)}\n    />\n  );\n}\n\nexport function MenubarShortcut({\n  className,\n  ...props\n}: React.HTMLAttributes<HTMLSpanElement>) {\n  return (\n    <span\n      className={cn(\n        \"ml-auto text-xs tracking-widest text-muted-foreground\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport function MenubarLabel({\n  className,\n  inset,\n  ...props\n}: React.HTMLAttributes<HTMLDivElement> & { inset?: boolean }) {\n  return (\n    <div\n      className={cn(\n        \"px-2 py-1.5 text-xs font-semibold text-muted-foreground\",\n        inset && \"pl-8\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n",
      "type": "registry:component",
      "target": "components/custom/blocks/MenubarBlock.tsx"
    }
  ],
  "docs": "Named exports: Menubar, MenubarMenu, MenubarTrigger, MenubarContent, MenubarItem, MenubarSeparator. Once a menu is open, hovering another trigger switches to it — the File/Edit/View behaviour of a native app.",
  "categories": [
    "navigation"
  ],
  "type": "registry:component"
}
