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 (
Right click (or open) here
{props.children}
) } export const Basic = { render: () => ( Actions Copy Paste More Duplicate Move ), } function CheckedIndicator() { return ( ) } function OptionsMenu(props: { initiallyOpen?: boolean }) { const [numbers, setNumbers] = createSignal(true) const [wrap, setWrap] = createSignal(false) const [density, setDensity] = createSignal("compact") return ( Show line numbers Wrap lines Compact Comfortable ) } export const CheckboxRadio = { render: () => } export const OpenWithDisabledItem = { render: () => }