{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "menu",
  "title": "Menu",
  "description": "A floating panel from a trigger: 12px corners, 36px rows, grows from the trigger. No positioning library.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/dgit/ui/menu.tsx",
      "content": "import { useEffect, useRef, useState, type CSSProperties, type ReactNode } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { Check } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\n/**\n * A floating panel opened from a trigger: account menus, pickers, small action lists.\n * 12px corners, the `shadow-menu` elevation, 36px rows with 8px sides and 6px corners, and a\n * 120 ms grow from the trigger's corner. Closes on Escape and on a click outside.\n */\nfunction panelPosition(side: \"below\" | \"above\", align: \"start\" | \"end\", r: DOMRect): CSSProperties {\n  const vertical = side === \"above\" ? { bottom: window.innerHeight - r.top + 4 } : { top: r.bottom + 4 };\n  const horizontal = align === \"end\" ? { right: window.innerWidth - r.right } : { left: r.left };\n  return { ...vertical, ...horizontal };\n}\n\nexport function Menu({\n  trigger,\n  children,\n  side = \"below\",\n  align = \"start\",\n  className,\n  rootClassName,\n  label,\n}: {\n  /** Render the button that opens it; call `toggle` on click. */\n  trigger: (props: { open: boolean; toggle: () => void; \"aria-expanded\": boolean; \"aria-haspopup\": \"menu\" }) => ReactNode;\n  children: (props: { close: () => void }) => ReactNode;\n  side?: \"below\" | \"above\";\n  align?: \"start\" | \"end\";\n  /** Panel width and extras, e.g. \"w-72\". */\n  className?: string;\n  rootClassName?: string;\n  label?: string;\n}) {\n  const [open, setOpen] = useState(false);\n  const [rect, setRect] = useState<DOMRect | null>(null);\n  const root = useRef<HTMLDivElement>(null);\n  const panel = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    if (!open || !root.current) return;\n    const update = () => setRect(root.current?.getBoundingClientRect() ?? null);\n    update();\n    window.addEventListener(\"scroll\", update, true);\n    window.addEventListener(\"resize\", update);\n    const onDown = (e: PointerEvent) => {\n      const t = e.target as Node;\n      if (!root.current?.contains(t) && !panel.current?.contains(t)) setOpen(false);\n    };\n    const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && setOpen(false);\n    document.addEventListener(\"pointerdown\", onDown);\n    document.addEventListener(\"keydown\", onKey);\n    return () => {\n      window.removeEventListener(\"scroll\", update, true);\n      window.removeEventListener(\"resize\", update);\n      document.removeEventListener(\"pointerdown\", onDown);\n      document.removeEventListener(\"keydown\", onKey);\n    };\n  }, [open]);\n\n  return (\n    <div ref={root} className={cn(\"relative min-w-0\", rootClassName)}>\n      {trigger({ open, toggle: () => setOpen(!open), \"aria-expanded\": open, \"aria-haspopup\": \"menu\" })}\n      {open && rect\n        ? createPortal(\n            <div\n              ref={panel}\n              role=\"menu\"\n              aria-label={label}\n              style={panelPosition(side, align, rect)}\n              className={cn(\n                // On <body>, above dialogs, so no parent's stacking context can cover it.\n                \"fixed z-[70] min-w-[220px] overflow-hidden rounded-xl bg-popover p-1.5 text-popover-foreground shadow-menu animate-menu\",\n                side === \"above\" ? (align === \"end\" ? \"origin-bottom-right\" : \"origin-bottom-left\") : align === \"end\" ? \"origin-top-right\" : \"origin-top-left\",\n                className,\n              )}\n            >\n              {children({ close: () => setOpen(false) })}\n            </div>,\n            document.body,\n          )\n        : null}\n    </div>\n  );\n}\n\nconst ROW =\n  \"flex h-9 w-full cursor-pointer items-center gap-3 rounded-md border-0 bg-transparent px-2 text-left font-[inherit] text-label-14 text-foreground no-underline hover:bg-gray-100 focus-visible:bg-gray-100 focus-visible:outline-none\";\n\n/** One row: a button, or a link with `href`. The icon sits on the right, like a shortcut. */\nexport function MenuItem({\n  children,\n  icon,\n  href,\n  external,\n  onSelect,\n  checked,\n  className,\n}: {\n  children: ReactNode;\n  icon?: ReactNode;\n  href?: string;\n  external?: boolean;\n  onSelect?: () => void;\n  /** Shows a check on the right (for single-choice lists). */\n  checked?: boolean;\n  className?: string;\n}) {\n  const inner = (\n    <>\n      <span className=\"min-w-0 flex-1 truncate\">{children}</span>\n      {checked !== undefined ? <Check className={cn(\"size-4 flex-none\", checked ? \"text-foreground\" : \"text-transparent\")} /> : null}\n      {icon ? <span className=\"flex size-4 flex-none items-center justify-center text-gray-900 [&_svg]:size-4\">{icon}</span> : null}\n    </>\n  );\n  if (href)\n    return (\n      <a role=\"menuitem\" href={href} onClick={onSelect} className={cn(ROW, className)} {...(external ? { target: \"_blank\", rel: \"noreferrer\" } : {})}>\n        {inner}\n      </a>\n    );\n  return (\n    <button type=\"button\" role=\"menuitem\" aria-checked={checked} onClick={onSelect} className={cn(ROW, className)}>\n      {inner}\n    </button>\n  );\n}\n\n/** A full-width rule between groups of rows. */\nexport function MenuSeparator() {\n  return <hr className=\"-mx-1.5 my-1.5 border-0 border-t border-gray-200\" />;\n}\n\n/** Non-interactive text at the top of a menu (who's signed in, a section name). */\nexport function MenuLabel({ children, className }: { children: ReactNode; className?: string }) {\n  return <div className={cn(\"px-2 py-2\", className)}>{children}</div>;\n}\n\n/** A keycap: 20px tall, 4px corners, 12px text. */\nexport function Kbd({ children }: { children: ReactNode }) {\n  return (\n    <kbd className=\"inline-flex h-5 min-w-5 items-center justify-center rounded-sm bg-background px-1 font-sans text-xs text-foreground shadow-[0_0_0_1px_var(--dgit-gray-alpha-400)]\">\n      {children}\n    </kbd>\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}