{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "menu",
  "type": "registry:ui",
  "title": "Menu",
  "description": "A dropdown menu of actions with icons, shortcuts, check and radio items, separators and danger items. Built on Radix Dropdown Menu.",
  "dependencies": [
    "lucide-react@^1.49.0",
    "radix-ui@^1.6.7"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/menu.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/menu.tsx",
      "content": "import { createContext, useContext, useState, type ReactNode } from 'react';\nimport { DropdownMenu as M } from 'radix-ui';\nimport { Check, ChevronRight } from 'lucide-react';\nimport { ThemeRootScope, useThemeRoot } from '../lib/theme-root';\nimport { cn } from '../lib/utils';\n\nconst CloseCtx = createContext<() => void>(() => {});\n\n/** Root of a menu. Compose with MenuTrigger (asChild around a Button) and MenuContent. Controlled with open and onOpenChange, or not. */\nexport function Menu({ children, open, defaultOpen, onOpenChange, ...rest }: React.ComponentProps<typeof M.Root>) {\n  const [inner, setInner] = useState(defaultOpen ?? false);\n  const isOpen = open ?? inner;\n  const change = (o: boolean) => {\n    setInner(o);\n    onOpenChange?.(o);\n  };\n  return (\n    <ThemeRootScope>\n      <CloseCtx.Provider value={() => change(false)}>\n        <M.Root open={isOpen} onOpenChange={change} {...rest}>{children}</M.Root>\n      </CloseCtx.Provider>\n    </ThemeRootScope>\n  );\n}\nexport const MenuTrigger = M.Trigger;\n\nconst item = 'flex min-h-11 cursor-pointer select-none items-center gap-3 rounded-kh px-3 text-kh-small outline-none transition-colors duration-(--kh-dur) data-[disabled]:pointer-events-none data-[disabled]:opacity-50';\n\n/** `onCloseAutoFocus`: call `e.preventDefault()` to keep focus where an item moved it instead of back on the trigger. */\nexport function MenuContent({ children, align = 'start', side = 'bottom', className, onCloseAutoFocus }: { children: ReactNode; align?: 'start' | 'center' | 'end'; side?: 'top' | 'right' | 'bottom' | 'left'; className?: string; onCloseAutoFocus?: (e: Event) => void }) {\n  const root = useThemeRoot();\n  const close = useContext(CloseCtx);\n  return (\n    <M.Portal container={root}>\n      <M.Content\n        // Tab leaves the menu: close it, and focus goes back to the trigger.\n        onKeyDown={(e) => e.key === 'Tab' && close()}\n        onCloseAutoFocus={onCloseAutoFocus}\n        align={align}\n        side={side}\n        sideOffset={6}\n        collisionPadding={12}\n        className={cn('z-50 min-w-56 max-w-[calc(100vw-1.5rem)] rounded-kh-lg border border-kh-line bg-kh-surface p-1 text-kh-ink shadow-kh-3', className)}\n      >\n        {children}\n      </M.Content>\n    </M.Portal>\n  );\n}\n\nexport function MenuItem({ icon, shortcut, danger, children, onSelect, disabled }: { icon?: ReactNode; shortcut?: string; danger?: boolean; children: ReactNode; onSelect?: () => void; disabled?: boolean }) {\n  return (\n    <M.Item disabled={disabled} onSelect={onSelect} className={cn(item, danger ? 'text-kh-danger data-[highlighted]:bg-kh-surface-2' : 'text-kh-ink data-[highlighted]:bg-kh-surface-2')}>\n      {icon && <span aria-hidden className=\"flex size-4 items-center justify-center text-kh-muted [&_svg]:size-4\">{icon}</span>}\n      <span className=\"flex-1\">{children}</span>\n      {shortcut && <span className=\"font-kh-mono text-kh-caption text-kh-muted\">{shortcut}</span>}\n    </M.Item>\n  );\n}\n\nexport function MenuCheckItem({ checked, onCheckedChange, children }: { checked: boolean; onCheckedChange: (checked: boolean) => void; children: ReactNode }) {\n  return (\n    <M.CheckboxItem checked={checked} onCheckedChange={onCheckedChange} onSelect={(e) => e.preventDefault()} className={cn(item, 'text-kh-ink data-[highlighted]:bg-kh-surface-2')}>\n      <span className=\"flex-1\">{children}</span>\n      <M.ItemIndicator>\n        <Check aria-hidden className=\"size-4\" />\n      </M.ItemIndicator>\n    </M.CheckboxItem>\n  );\n}\n\n/** A choice of one among several. Picking an item keeps the menu open, like MenuCheckItem. */\nexport function MenuRadioGroup({ value, onValueChange, children }: { value: string; onValueChange: (value: string) => void; children: ReactNode }) {\n  return <M.RadioGroup value={value} onValueChange={onValueChange}>{children}</M.RadioGroup>;\n}\n\nexport function MenuRadioItem({ value, children, description, badge, checkAt = 'end', closes }: {\n  value: string; children: ReactNode;\n  /** A second, quieter line under the name (what a model is for). */\n  description?: ReactNode;\n  /** A small tag at the end (\"New\"). */\n  badge?: ReactNode;\n  /** Where the check sits: at the end, or at the start in its own column (a picker of models). */\n  checkAt?: 'start' | 'end';\n  /** Picking closes the menu (a picker), instead of keeping it open. */\n  closes?: boolean;\n}) {\n  const check = <Check aria-hidden className=\"size-4\" />;\n  return (\n    <M.RadioItem value={value} onSelect={closes ? undefined : (e) => e.preventDefault()} className={cn(item, 'text-kh-ink data-[highlighted]:bg-kh-surface-2', description && 'py-2')}>\n      {checkAt === 'start' && <span className=\"flex size-4 shrink-0 items-center justify-center\"><M.ItemIndicator>{check}</M.ItemIndicator></span>}\n      <span className=\"flex min-w-0 flex-1 flex-col\">\n        <span>{children}</span>\n        {description && <span className=\"text-kh-caption text-kh-muted\">{description}</span>}\n      </span>\n      {badge && <span className=\"shrink-0 rounded-kh-pill bg-kh-surface-2 px-2 py-0.5 text-kh-caption text-kh-ink-2\">{badge}</span>}\n      {checkAt === 'end' && <M.ItemIndicator>{check}</M.ItemIndicator>}\n    </M.RadioItem>\n  );\n}\n\nexport const MenuSeparator = () => <M.Separator className=\"-mx-1 my-1 h-px bg-kh-line\" />;\nexport const MenuLabel = ({ children }: { children: ReactNode }) => <M.Label className=\"px-3 py-1.5 text-kh-caption font-medium text-kh-muted\">{children}</M.Label>;\n\n/** An item that opens a submenu (a chevron at the end; Right arrow or a tap opens it, Left or Escape goes back). */\nexport function MenuSub({ icon, label, children, className }: { icon?: ReactNode; label: ReactNode; children: ReactNode; className?: string }) {\n  const root = useThemeRoot();\n  return (\n    <M.Sub>\n      <M.SubTrigger className={cn(item, 'text-kh-ink data-[highlighted]:bg-kh-surface-2 data-[state=open]:bg-kh-surface-2')}>\n        {icon && <span aria-hidden className=\"flex size-4 items-center justify-center text-kh-muted [&_svg]:size-4\">{icon}</span>}\n        <span className=\"flex-1\">{label}</span>\n        <ChevronRight aria-hidden className=\"size-4 text-kh-muted\" />\n      </M.SubTrigger>\n      <M.Portal container={root}>\n        <M.SubContent sideOffset={6} collisionPadding={12} className={cn('z-50 min-w-48 max-w-[calc(100vw-1.5rem)] rounded-kh-lg border border-kh-line bg-kh-surface p-1 text-kh-ink shadow-kh-3', className)}>\n          {children}\n        </M.SubContent>\n      </M.Portal>\n    </M.Sub>\n  );\n}\n"
    }
  ]
}
