import { useState } from "react" import type { Meta, StoryObj } from "@storybook/react-vite" import { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, } from "@hm-design/ui" import { STORY_KICKER, StoryPage, StoryPageHeader, StorySection } from "@/components/story-page" // Context Menu opens from pointer context (right click, the context-menu key / Shift+F10, long press) on its trigger area. // The representative Story is a target area: right click it. Radix owns keyboard navigation, focus return and Escape. function Full() { const [showStatus, setShowStatus] = useState(true) const [showPanel, setShowPanel] = useState(false) const [position, setPosition] = useState("bottom") return ( {/* tabIndex lets keyboard users focus the area and open the menu with Shift+F10 / the context-menu key; Radix Trigger is a plain span. */} 이 영역에서 오른쪽 클릭 파일 열기 ⌘O 이름 바꾸기 F2 붙여넣기 (사용 불가) 보기 상태 표시줄 패널 위치 상단 하단 오른쪽 더 보기 이메일로 공유 링크 복사 삭제 ) } const meta = { title: "Components/Overlay/Context Menu", component: ContextMenu, parameters: { layout: "centered" } } satisfies Meta export default meta type Story = StoryObj // Representative Story: right click the area to open the full menu (item, disabled, separator, shortcut, checkbox, radio group, sub menu, destructive). export const All: Story = { name: "Context Menu", parameters: { layout: "fullscreen", controls: { disable: true } }, render: () => ( ), } // Verification Story: opens the menu at the area center on load (synthetic contextmenu event), hidden from the sidebar (tag `verification`). export const Open: Story = { tags: ["verification"], parameters: { layout: "fullscreen" }, render: () => (
), play: async ({ canvasElement }) => { const area = canvasElement.querySelector("[data-slot='context-menu-trigger']") if (!area) return const r = area.getBoundingClientRect() area.dispatchEvent( new MouseEvent("contextmenu", { bubbles: true, cancelable: true, clientX: r.left + r.width / 2, clientY: r.top + r.height / 2, button: 2 }), ) }, }