import { createSignal, onMount, type ParentProps } from "solid-js"
import { Icon } from "@opencode/ui/icon"
import { ContextMenu } from "./context-menu"
const docs = `### Overview
Context menu for right-click interactions with composable items and submenus.
Use \`ItemLabel\` and \`ItemDescription\` for rich items.
### API
- The trigger opens the menu at the pointer; the root reports changes through \`onOpenChange\`.
- Compose \`Trigger\`, \`Content\`, \`Item\`, \`Separator\`, and optional \`Sub\` sections.
### Variants and states
- Supports grouped sections and nested submenus.
### Behavior
- Opens on context menu gesture over the trigger element.
### Accessibility
- TODO: confirm keyboard and focus behavior from Kobalte.
### Theming/tokens
- Uses \`data-component="context-menu"\` and slot attributes for styling.
`
export default {
title: "UI/ContextMenu",
id: "components-context-menu",
component: ContextMenu,
tags: ["autodocs"],
parameters: {
docs: {
description: {
component: docs,
},
},
},
}
function MenuArea(props: ParentProps<{ initiallyOpen?: boolean }>) {
let trigger!: HTMLDivElement
// Kobalte takes the anchor from a contextmenu event; its context menu has no defaultOpen prop.
onMount(() => {
if (!props.initiallyOpen) return
const box = trigger.getBoundingClientRect()
trigger.dispatchEvent(
new MouseEvent("contextmenu", {
bubbles: true,
cancelable: true,
clientX: box.left + box.width / 2,
clientY: box.top + box.height / 2,
}),
)
})
return (