{
  "schemaVersion": 1,
  "target": "react",
  "name": "context-menu",
  "version": "0.1.1",
  "category": "overlays",
  "title": "Context Menu",
  "description": "A right-click menu with submenus, checkbox and radio items, shortcuts, and destructive items, built on Base UI Context Menu with the Dropdown Menu surface and items.",
  "tags": [
    "overlay",
    "menu",
    "right-click",
    "actions",
    "base-ui"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "@base-ui/react": "^1.9.0"
  },
  "registryDependencies": [
    {
      "name": "dropdown-menu",
      "version": "0.2.1"
    }
  ],
  "docsPath": "/components/context-menu",
  "props": [
    {
      "name": "ContextMenu open / defaultOpen / onOpenChange",
      "type": "boolean / boolean / (open, details) => void",
      "description": "Root state."
    },
    {
      "name": "ContextMenuTrigger",
      "type": "Base UI ContextMenu.Trigger props",
      "description": "The area that opens the menu on right click, long press, Shift+F10, or the Menu key. Renders a div; add tabIndex={0} and a label when it is not focusable."
    },
    {
      "name": "ContextMenuContent sideOffset / alignOffset",
      "type": "number",
      "default": "2 / 2",
      "description": "Offset from the pointer, in pixels."
    },
    {
      "name": "ContextMenuItem destructive / disabled",
      "type": "boolean",
      "default": "false",
      "description": "Red styling for delete-style actions; disabled keeps the item visible but skips it."
    },
    {
      "name": "ContextMenuCheckboxItem checked / defaultChecked / onCheckedChange",
      "type": "boolean / boolean / (checked) => void",
      "description": "A toggle with a check in the leading slot. Stays open after a click."
    },
    {
      "name": "ContextMenuRadioGroup value / onValueChange",
      "type": "any / (value) => void",
      "description": "Exactly one ContextMenuRadioItem is chosen; the chosen one shows a dot."
    },
    {
      "name": "ContextMenuSub / ContextMenuSubTrigger / ContextMenuSubContent",
      "type": "Base UI SubmenuRoot / SubmenuTrigger / Dropdown Menu content props",
      "description": "A nested menu. The trigger takes an optional icon; the panel opens beside it with its first item level with the trigger."
    },
    {
      "name": "ContextMenuGroup / ContextMenuLabel / ContextMenuSeparator / ContextMenuShortcut",
      "type": "Dropdown Menu parts",
      "description": "Grouping, section labels, dividers, and shortcut hints, shared with Dropdown Menu."
    }
  ],
  "accessibility": [
    "The panel has role=\"menu\"; items are menuitem, menuitemcheckbox, or menuitemradio with aria-checked.",
    "Right click and long press open the menu at the pointer; on a focused trigger, Shift+F10 and the Menu key open it at the start of the area.",
    "Arrow keys move the highlight, Home and End jump, typing a letter jumps to a matching item, and Escape closes and returns focus.",
    "Submenu triggers set aria-haspopup and open with the right arrow key, closing with the left arrow key.",
    "Disabled items set aria-disabled and stay reachable with the arrow keys.",
    "The highlight changes color instantly with no animated movement; the panel grows from the pointer in 160ms and fades out in 110ms, and reduced motion removes both."
  ],
  "states": [
    "closed",
    "open",
    "submenu open"
  ],
  "files": [
    {
      "path": "ui/context-menu.tsx",
      "content": "\"use client\";\n\nimport { ContextMenu as BaseContextMenu } from \"@base-ui/react/context-menu\";\nimport { Menu as BaseMenu } from \"@base-ui/react/menu\";\nimport type { ReactNode } from \"react\";\nimport {\n  DropdownMenuContent,\n  type DropdownMenuContentProps,\n  DropdownMenuGroup,\n  DropdownMenuItem,\n  DropdownMenuLabel,\n  DropdownMenuSeparator,\n  DropdownMenuShortcut,\n} from \"./dropdown-menu\";\n\ntype ClassName<State> = string | ((state: State) => string | undefined) | undefined;\n\nfunction cx(...classes: (string | false | null | undefined)[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\n/** Prepends base classes while keeping Base UI's state-function form of className working. */\nfunction withBase<State>(base: string, className: ClassName<State>) {\n  return typeof className === \"function\" ? (state: State) => cx(base, className(state)) : cx(base, className);\n}\n\n/** Groups the context menu parts and holds its open state. */\nexport const ContextMenu = BaseContextMenu.Root;\n\n/**\n * The area that opens the menu on right click, on long press with touch, and with Shift+F10 or\n * the Menu key when it has focus. Renders a `<div>`; give it `tabIndex={0}` and a label if it is\n * not already focusable, so keyboard users can reach the menu too.\n */\nexport function ContextMenuTrigger({ onKeyDown, ...props }: BaseContextMenu.Trigger.Props) {\n  return (\n    <BaseContextMenu.Trigger\n      onKeyDown={(event) => {\n        onKeyDown?.(event);\n        if (event.defaultPrevented) return;\n        if (!((event.shiftKey && event.key === \"F10\") || event.key === \"ContextMenu\")) return;\n        // Browsers disagree on whether these keys fire `contextmenu`, and where. Open the menu\n        // at the start of the focused area every time instead.\n        event.preventDefault();\n        const target = event.currentTarget as HTMLElement;\n        const rect = target.getBoundingClientRect();\n        target.dispatchEvent(\n          new MouseEvent(\"contextmenu\", {\n            bubbles: true,\n            cancelable: true,\n            button: 2,\n            clientX: rect.left + Math.min(16, rect.width / 2),\n            clientY: rect.top + Math.min(rect.height, 32),\n          }),\n        );\n      }}\n      {...props}\n    />\n  );\n}\n\nexport interface ContextMenuContentProps extends Omit<DropdownMenuContentProps, \"side\" | \"align\"> {}\n\n/** The menu panel, opened at the pointer. Shares its surface and motion with Dropdown Menu. */\nexport function ContextMenuContent({ sideOffset = 2, alignOffset = 2, ...props }: ContextMenuContentProps) {\n  return <DropdownMenuContent side=\"bottom\" align=\"start\" sideOffset={sideOffset} alignOffset={alignOffset} {...props} />;\n}\n\n/** An action. `destructive` styles it for deleting; `disabled` keeps it visible but skips it. */\nexport const ContextMenuItem = DropdownMenuItem;\n\n/** Groups related items. Put a ContextMenuLabel inside to name the group. */\nexport const ContextMenuGroup = DropdownMenuGroup;\n\n/** Names a ContextMenuGroup or ContextMenuRadioGroup. Must be rendered inside the group it labels. */\nexport const ContextMenuLabel = DropdownMenuLabel;\n\n/** A divider between groups of items. */\nexport const ContextMenuSeparator = DropdownMenuSeparator;\n\n/** A keyboard shortcut hint shown at the end of an item. */\nexport const ContextMenuShortcut = DropdownMenuShortcut;\n\n// The same row recipe as Dropdown Menu items, so checkbox, radio, and submenu rows line up with them.\nconst row = cx(\n  \"flex h-8 cursor-default items-center gap-2.5 rounded-md px-2 text-sm text-zinc-700 outline-none select-none\",\n  \"[&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-zinc-500\",\n  \"data-[highlighted]:bg-zinc-950/[0.05] data-[highlighted]:text-zinc-950 data-[highlighted]:[&_svg]:text-zinc-950\",\n  \"dark:text-zinc-300 dark:[&_svg]:text-zinc-500 dark:data-[highlighted]:bg-white/[0.08] dark:data-[highlighted]:text-white dark:data-[highlighted]:[&_svg]:text-white\",\n  \"data-[disabled]:pointer-events-none data-[disabled]:opacity-45\",\n);\n\n// Indicators appear and disappear without motion: toggling is a high-frequency action.\nconst indicatorSlot = \"flex size-4 shrink-0 items-center justify-center\";\n\nexport interface ContextMenuCheckboxItemProps extends BaseMenu.CheckboxItem.Props {}\n\n/**\n * An item that toggles a setting on and off, with a check in the leading slot when on. Stays\n * open after a click by default so several settings can be changed in a row.\n */\nexport function ContextMenuCheckboxItem({ className, children, ...props }: ContextMenuCheckboxItemProps) {\n  return (\n    <BaseMenu.CheckboxItem className={withBase(row, className)} {...props}>\n      <span className={indicatorSlot}>\n        <BaseMenu.CheckboxItemIndicator className=\"flex\">\n          <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\">\n            <path d=\"m3.75 8.25 2.75 2.75 5.75-6\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n          </svg>\n        </BaseMenu.CheckboxItemIndicator>\n      </span>\n      {children}\n    </BaseMenu.CheckboxItem>\n  );\n}\n\n/** Groups radio items so exactly one is chosen. Pass `value`/`onValueChange` to control it. */\nexport const ContextMenuRadioGroup = BaseMenu.RadioGroup;\n\nexport interface ContextMenuRadioItemProps extends BaseMenu.RadioItem.Props {}\n\n/** One choice in a ContextMenuRadioGroup, with a filled dot in the leading slot when chosen. */\nexport function ContextMenuRadioItem({ className, children, ...props }: ContextMenuRadioItemProps) {\n  return (\n    <BaseMenu.RadioItem className={withBase(row, className)} {...props}>\n      <span className={indicatorSlot}>\n        <BaseMenu.RadioItemIndicator className=\"size-1.5 rounded-full bg-current\" />\n      </span>\n      {children}\n    </BaseMenu.RadioItem>\n  );\n}\n\n/** Groups a submenu trigger with its panel. */\nexport const ContextMenuSub = BaseMenu.SubmenuRoot;\n\nexport interface ContextMenuSubTriggerProps extends BaseMenu.SubmenuTrigger.Props {\n  /** Optional icon before the label. */\n  icon?: ReactNode;\n}\n\n/** An item that opens a submenu: on hover, on click, or with the right arrow key. */\nexport function ContextMenuSubTrigger({ className, icon, children, ...props }: ContextMenuSubTriggerProps) {\n  return (\n    <BaseMenu.SubmenuTrigger\n      className={withBase(\n        cx(\n          row,\n          \"data-[popup-open]:bg-zinc-950/[0.05] data-[popup-open]:text-zinc-950 dark:data-[popup-open]:bg-white/[0.08] dark:data-[popup-open]:text-white\",\n        ),\n        className,\n      )}\n      {...props}\n    >\n      {icon}\n      {children}\n      <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"-mr-0.5 ml-auto\">\n        <path d=\"m6.25 4.5 3.5 3.5-3.5 3.5\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n      </svg>\n    </BaseMenu.SubmenuTrigger>\n  );\n}\n\nexport interface ContextMenuSubContentProps extends Omit<DropdownMenuContentProps, \"side\" | \"align\"> {}\n\n/** The submenu panel. Opens beside its trigger with its first item level with the trigger row. */\nexport function ContextMenuSubContent({ sideOffset = 2, alignOffset = -7, ...props }: ContextMenuSubContentProps) {\n  return <DropdownMenuContent side=\"inline-end\" align=\"start\" sideOffset={sideOffset} alignOffset={alignOffset} {...props} />;\n}\n"
    }
  ],
  "example": {
    "content": "\"use client\";\n\nimport { useState } from \"react\";\nimport {\n  ContextMenu,\n  ContextMenuCheckboxItem,\n  ContextMenuContent,\n  ContextMenuGroup,\n  ContextMenuItem,\n  ContextMenuLabel,\n  ContextMenuRadioGroup,\n  ContextMenuRadioItem,\n  ContextMenuSeparator,\n  ContextMenuShortcut,\n  ContextMenuSub,\n  ContextMenuSubContent,\n  ContextMenuSubTrigger,\n  ContextMenuTrigger,\n} from \"@/components/shaken/ui/context-menu\";\n\nconst icon = { \"aria-hidden\": true, viewBox: \"0 0 16 16\", fill: \"none\" } as const;\nconst stroke = { stroke: \"currentColor\", strokeWidth: 1.5, strokeLinecap: \"round\", strokeLinejoin: \"round\" } as const;\n\nconst files = [\n  { name: \"src/limits.ts\", size: \"2.1 KB\", modified: \"4 min ago\" },\n  { name: \"src/handler.ts\", size: \"5.8 KB\", modified: \"4 min ago\" },\n  { name: \"docs/rate-limits.md\", size: \"1.3 KB\", modified: \"Yesterday\" },\n  { name: \"tests/limits.test.ts\", size: \"3.4 KB\", modified: \"Yesterday\" },\n];\n\nfunction FileRow({ file }: { file: (typeof files)[number] }) {\n  const [inContext, setInContext] = useState(true);\n  const [access, setAccess] = useState(\"write\");\n\n  return (\n    <ContextMenu>\n      <ContextMenuTrigger\n        tabIndex={0}\n        aria-label={`${file.name}. Press Shift F10 for actions.`}\n        className={\n          \"flex cursor-default items-center gap-3 px-3 py-2.5 text-sm outline-none select-none \" +\n          \"transition-colors duration-150 ease-out motion-reduce:transition-none \" +\n          \"hover:bg-zinc-950/[0.03] data-[popup-open]:bg-zinc-950/[0.05] dark:hover:bg-white/[0.04] dark:data-[popup-open]:bg-white/[0.08] \" +\n          \"focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-sky-500\"\n        }\n      >\n        <svg {...icon} className=\"size-4 shrink-0 text-zinc-500\">\n          <path d=\"M4 2.5h5l3 3v8H4v-11Z\" {...stroke} />\n          <path d=\"M9 2.5v3h3\" {...stroke} />\n        </svg>\n        <span className=\"min-w-0 flex-1 truncate font-mono text-xs text-zinc-950 dark:text-white\">{file.name}</span>\n        {access !== \"write\" || !inContext ? (\n          <span className=\"text-xs text-zinc-500\">{!inContext ? \"Hidden from agent\" : \"Read only\"}</span>\n        ) : null}\n        <span className=\"w-16 text-right font-mono text-xs text-zinc-500 tabular-nums max-sm:hidden\">{file.size}</span>\n      </ContextMenuTrigger>\n      <ContextMenuContent>\n        <ContextMenuItem>\n          <svg {...icon}>\n            <path d=\"M9.5 2.5h4v4M13.5 2.5 7.5 8.5M11.5 9.5v3a1 1 0 0 1-1 1h-7a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1h3\" {...stroke} />\n          </svg>\n          Open\n          <ContextMenuShortcut>↵</ContextMenuShortcut>\n        </ContextMenuItem>\n        <ContextMenuItem>\n          <svg {...icon}>\n            <path d=\"M9.5 3.5l3 3-7 7h-3v-3l7-7z\" {...stroke} />\n          </svg>\n          Rename\n          <ContextMenuShortcut>F2</ContextMenuShortcut>\n        </ContextMenuItem>\n        <ContextMenuItem>\n          <svg {...icon}>\n            <rect x=\"5.5\" y=\"5.5\" width=\"8\" height=\"8\" rx=\"1.5\" {...stroke} />\n            <path d=\"M10.5 3.5v-.25A.75.75 0 0 0 9.75 2.5h-6.5a.75.75 0 0 0-.75.75v6.5c0 .41.34.75.75.75h.25\" {...stroke} />\n          </svg>\n          Copy path\n          <ContextMenuShortcut>⌥⌘C</ContextMenuShortcut>\n        </ContextMenuItem>\n        <ContextMenuSub>\n          <ContextMenuSubTrigger\n            icon={\n              <svg {...icon}>\n                <path d=\"M2.5 4.5a1 1 0 0 1 1-1h3l1.5 1.5h4.5a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1h-9a1 1 0 0 1-1-1v-7.5Z\" {...stroke} />\n              </svg>\n            }\n          >\n            Move to\n          </ContextMenuSubTrigger>\n          <ContextMenuSubContent>\n            <ContextMenuItem>src</ContextMenuItem>\n            <ContextMenuItem>src/middleware</ContextMenuItem>\n            <ContextMenuItem>docs</ContextMenuItem>\n            <ContextMenuItem>tests</ContextMenuItem>\n            <ContextMenuSeparator />\n            <ContextMenuItem>New folder…</ContextMenuItem>\n          </ContextMenuSubContent>\n        </ContextMenuSub>\n        <ContextMenuSeparator />\n        <ContextMenuCheckboxItem checked={inContext} onCheckedChange={setInContext}>\n          Include in agent context\n        </ContextMenuCheckboxItem>\n        <ContextMenuRadioGroup value={access} onValueChange={setAccess}>\n          <ContextMenuLabel>Agent access</ContextMenuLabel>\n          <ContextMenuRadioItem value=\"write\">Read and write</ContextMenuRadioItem>\n          <ContextMenuRadioItem value=\"read\">Read only</ContextMenuRadioItem>\n        </ContextMenuRadioGroup>\n        <ContextMenuSeparator />\n        <ContextMenuGroup>\n          <ContextMenuItem destructive>\n            <svg {...icon}>\n              <path d=\"M3 4.5h10M6.5 4.5V3a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 .5.5v1.5M4.5 4.5l.6 8.1a1 1 0 0 0 1 .9h3.8a1 1 0 0 0 1-.9l.6-8.1\" {...stroke} />\n            </svg>\n            Delete file\n            <ContextMenuShortcut>⌘⌫</ContextMenuShortcut>\n          </ContextMenuItem>\n        </ContextMenuGroup>\n      </ContextMenuContent>\n    </ContextMenu>\n  );\n}\n\nexport default function ContextMenuExample() {\n  return (\n    <div className=\"w-full max-w-md\">\n      <div className=\"overflow-hidden rounded-xl border border-zinc-950/10 bg-white dark:border-white/10 dark:bg-black\">\n        <div className=\"flex items-center justify-between border-b border-zinc-950/[0.07] px-3 py-2 dark:border-white/[0.08]\">\n          <span className=\"text-xs font-medium text-zinc-500\">Changed files</span>\n          <span className=\"text-xs text-zinc-500\">Right click a file</span>\n        </div>\n        <div className=\"divide-y divide-zinc-950/[0.07] dark:divide-white/[0.08]\">\n          {files.map((file) => (\n            <FileRow key={file.name} file={file} />\n          ))}\n        </div>\n      </div>\n    </div>\n  );\n}\n"
  }
}
