# ContextMenu Show actions for a specific item or surface at the pointer position. [Interactive guide](/docs/components/context-menu) · Forge 3.2.0 Use the API for your installed version. Run `npx --no-install wss3-forge api --json` inside the project. ## Implementation guidance ### When to use it Use ContextMenu for commands tied to the selected item or target surface and opened at the pointer. ### How to compose it Bind useContextMenu to a focusable target for data-driven commands and render ContextMenuComponent nearby. Expose a visible button when discovery matters. ### What to verify Test right-click, touch long press and Shift+F10. Confirm commands affect the resolved target and Escape restores focus. ## Usage ```tsx import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from 'wss3-forge/base-ui' ``` - Place a Base UI ContextMenuTrigger inside ContextMenu for right-click and long-press actions. For a separate button, share a Menu.createHandle() between a Base UI Menu.Trigger and the Forge ContextMenu. A children callback receives the active trigger payload. - Right-click with a mouse, long-press on touch, or focus the target and press Shift+F10. Use arrow keys to move, Enter to choose and Escape to dismiss. - Use checkbox items for independent settings and a radio group for mutually exclusive choices. Use descriptive labels and assign destructive treatment to actions that remove data. - Browser actions binds Alt+1 through Alt+5 to navigation and page tools while the target or its menu has focus. Shortcuts uses Alt+1 and Alt+2 for zoom. Browser actions navigate a local history, and checkbox and radio settings persist when the menu reopens. - Data-driven menu uses the shared Forge hook across all library selections. For the data-driven Forge menu, spread getTriggerProps(items) from useContextMenu onto a focusable target and render ContextMenuComponent next to it. For an ellipsis button, pass { openOnClick: true, label: "Actions" } as the second argument. The Data Table guide shows this pattern on each payment row. Direct ContextMenu accepts items, x, y, onClose and an optional returnFocusTo. ## Guide ### Open actions from a separate button Use a shared Base UI menu handle when the file button and its actions live in different parts of the page. The selected trigger supplies the file name to the menu. ```tsx import { useState } from 'react' import { Menu } from '@base-ui/react/menu' import { Button } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem } from 'wss3-forge/base-ui' export default function FileActions({ onArchive }: { onArchive: (file: string) => void }) { const [handle] = useState(() => Menu.createHandle()) return <> }>File actions {({ payload }) => payload && onArchive(payload)}> Archive {payload} } } ``` ## Runnable examples ### Browser actions ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular, Wrench16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } function useDisplay(rtl = false) { const [bookmarks, setBookmarks] = useState(true) const [urls, setUrls] = useState(false) return setBookmarks(value === true)}>{rtl ? 'عرض الإشارات المرجعية' : 'Show Bookmarks'} setUrls(value === true)}>{rtl ? 'عرض العناوين الكاملة' : 'Show Full URLs'} } function useProfiles(rtl = false) { const [owner, setOwner] = useState('mina') return {rtl ? 'الملف الشخصي' : 'Profile'} setOwner(String(value))}> {rtl ? 'مينا' : 'Mina Park'} {rtl ? 'جو' : 'Jo Bell'} } function BrowserActions({ rtl = false }: { rtl?: boolean }) { const history = useHistory(rtl) const display = useDisplay(rtl) const profiles = useProfiles(rtl) function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const command = [...history.navigation, ...history.tools].find(item => event.code === 'Digit' + item.key) if (!command) return event.preventDefault() if ('disabled' in command && command.disabled) return command.run() } return {browserRows(history.navigation, true)} {browserRows(history.tools, true)} {display} {profiles} {history.result === (rtl ? 'أدوات المطور' : 'Developer Tools') && {rtl ? 'مسار الصفحة' : 'Current route'} · {history.path}} } export default function Example() { return () } ``` ### Basic ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuShortcut, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } function Basic() { const history = useHistory() return {browserRows(history.navigation)} } export default function Example() { return () } ``` ### Submenu ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } function Submenu() { const history = useHistory() return {browserRows(history.navigation)} More Tools {browserRows(history.tools)} } export default function Example() { return () } ``` ### Shortcuts ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuShortcut, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function Shortcuts() { const [level, setLevel] = useState(100) const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat) return if (event.code === 'Digit1') { event.preventDefault(); setLevel(value => Math.max(50, value - 10)) } if (event.code === 'Digit2') { event.preventDefault(); setLevel(value => Math.min(150, value + 10)) } } return setLevel(value => value - 10)}>Zoom out{modifier}1 setLevel(value => value + 10)}>Zoom in{modifier}2 } export default function Example() { return () } ``` ### Groups ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function Groups() { const [copies, setCopies] = useState(1) const [archived, setArchived] = useState(false) return Document setCopies(value => value + 1)}>Duplicate Workspace setArchived(value => !value)}>{archived ? 'Restore' : 'Archive'} } export default function Example() { return () } ``` ### Icons ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowUndo16Regular, Copy16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function Icons() { const [copies, setCopies] = useState(1) return setCopies(value => value + 1)}> setCopies(value => value - 1)}> } export default function Example() { return () } ``` ### Checkboxes ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function useDisplay(rtl = false) { const [bookmarks, setBookmarks] = useState(true) const [urls, setUrls] = useState(false) return setBookmarks(value === true)}>{rtl ? 'عرض الإشارات المرجعية' : 'Show Bookmarks'} setUrls(value === true)}>{rtl ? 'عرض العناوين الكاملة' : 'Show Full URLs'} } function Checkboxes() { const display = useDisplay() return {display} } export default function Example() { return () } ``` ### Radio ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuGroup, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function useProfiles(rtl = false) { const [owner, setOwner] = useState('mina') return {rtl ? 'الملف الشخصي' : 'Profile'} setOwner(String(value))}> {rtl ? 'مينا' : 'Mina Park'} {rtl ? 'جو' : 'Jo Bell'} } function Radio() { const [theme, setTheme] = useState('Light') const profiles = useProfiles() return {profiles} Theme setTheme(String(value))}> {['Light', 'Dark', 'System'].map(label => {label})} } export default function Example() { return () } ``` ### Destructive ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { Archive16Regular, ArrowUndo16Regular, Delete16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function Destructive() { const [status, setStatus] = useState('Draft') return setStatus('Archived')}> setStatus('Draft')}> setStatus('Deleted')}> } export default function Example() { return () } ``` ### Sides ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { Box, ContextMenuTarget, Grid, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function Sides() { const [selected, setSelected] = useState('') return {(['top', 'right', 'bottom', 'left'] as const).map(side => setSelected(side)}>Select this edge )} {selected && Selected edge: {selected}} } export default function Example() { return () } ``` ### RTL ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular, Wrench16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } function useDisplay(rtl = false) { const [bookmarks, setBookmarks] = useState(true) const [urls, setUrls] = useState(false) return setBookmarks(value === true)}>{rtl ? 'عرض الإشارات المرجعية' : 'Show Bookmarks'} setUrls(value === true)}>{rtl ? 'عرض العناوين الكاملة' : 'Show Full URLs'} } function useProfiles(rtl = false) { const [owner, setOwner] = useState('mina') return {rtl ? 'الملف الشخصي' : 'Profile'} setOwner(String(value))}> {rtl ? 'مينا' : 'Mina Park'} {rtl ? 'جو' : 'Jo Bell'} } function BrowserActions({ rtl = false }: { rtl?: boolean }) { const history = useHistory(rtl) const display = useDisplay(rtl) const profiles = useProfiles(rtl) function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const command = [...history.navigation, ...history.tools].find(item => event.code === 'Digit' + item.key) if (!command) return event.preventDefault() if ('disabled' in command && command.disabled) return command.run() } return {browserRows(history.navigation, true)} {browserRows(history.tools, true)} {display} {profiles} {history.result === (rtl ? 'أدوات المطور' : 'Developer Tools') && {rtl ? 'مسار الصفحة' : 'Current route'} · {history.path}} } function Rtl() { return } export default function Example() { return () } ``` ### Data-driven menu ```tsx import { useState } from 'react' import { ContextMenuTarget, Text, VStack, useContextMenu } from 'wss3-forge' function CompactMenu() { const { getTriggerProps, ContextMenuComponent } = useContextMenu() const [action, setAction] = useState('') const [archived, setArchived] = useState(false) return setAction('report.pdf') }, { id: 'file-location', label: 'Show location', onClick: () => setAction(archived ? 'Archive / report.pdf' : 'Proofs / report.pdf') }, { id: 'organize', label: '', divider: true }, { id: 'archive', label: archived ? 'Restore file' : 'Archive file', onClick: () => { setArchived(!archived) setAction(archived ? 'File restored.' : 'File archived.') } }, ])} /> {ContextMenuComponent}{action && {action}} } export default function Example() { return () } ``` ## Primitive libraries ### Base UI Compose the trigger using render. Use onClick, onCheckedChange and onValueChange for commands and settings. ```sh npm install wss3-forge @base-ui/react ``` ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuShortcut, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } export default function Basic() { const history = useHistory() return {browserRows(history.navigation)} } ``` #### Preview ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular, Wrench16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } function useDisplay(rtl = false) { const [bookmarks, setBookmarks] = useState(true) const [urls, setUrls] = useState(false) return setBookmarks(value === true)}>{rtl ? 'عرض الإشارات المرجعية' : 'Show Bookmarks'} setUrls(value === true)}>{rtl ? 'عرض العناوين الكاملة' : 'Show Full URLs'} } function useProfiles(rtl = false) { const [owner, setOwner] = useState('mina') return {rtl ? 'الملف الشخصي' : 'Profile'} setOwner(String(value))}> {rtl ? 'مينا' : 'Mina Park'} {rtl ? 'جو' : 'Jo Bell'} } export default function BrowserActions({ rtl = false }: { rtl?: boolean }) { const history = useHistory(rtl) const display = useDisplay(rtl) const profiles = useProfiles(rtl) function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const command = [...history.navigation, ...history.tools].find(item => event.code === 'Digit' + item.key) if (!command) return event.preventDefault() if ('disabled' in command && command.disabled) return command.run() } return {browserRows(history.navigation, true)} {browserRows(history.tools, true)} {display} {profiles} {history.result === (rtl ? 'أدوات المطور' : 'Developer Tools') && {rtl ? 'مسار الصفحة' : 'Current route'} · {history.path}} } ``` #### Submenu ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } export default function Submenu() { const history = useHistory() return {browserRows(history.navigation)} More Tools {browserRows(history.tools)} } ``` #### Shortcuts ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuShortcut, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} export default function Shortcuts() { const [level, setLevel] = useState(100) const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat) return if (event.code === 'Digit1') { event.preventDefault(); setLevel(value => Math.max(50, value - 10)) } if (event.code === 'Digit2') { event.preventDefault(); setLevel(value => Math.min(150, value + 10)) } } return setLevel(value => value - 10)}>Zoom out{modifier}1 setLevel(value => value + 10)}>Zoom in{modifier}2 } ``` #### Groups ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} export default function Groups() { const [copies, setCopies] = useState(1) const [archived, setArchived] = useState(false) return Document setCopies(value => value + 1)}>Duplicate Workspace setArchived(value => !value)}>{archived ? 'Restore' : 'Archive'} } ``` #### Icons ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowUndo16Regular, Copy16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} export default function Icons() { const [copies, setCopies] = useState(1) return setCopies(value => value + 1)}> setCopies(value => value - 1)}> } ``` #### Checkboxes ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function useDisplay(rtl = false) { const [bookmarks, setBookmarks] = useState(true) const [urls, setUrls] = useState(false) return setBookmarks(value === true)}>{rtl ? 'عرض الإشارات المرجعية' : 'Show Bookmarks'} setUrls(value === true)}>{rtl ? 'عرض العناوين الكاملة' : 'Show Full URLs'} } export default function Checkboxes() { const display = useDisplay() return {display} } ``` #### Radio ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuGroup, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function useProfiles(rtl = false) { const [owner, setOwner] = useState('mina') return {rtl ? 'الملف الشخصي' : 'Profile'} setOwner(String(value))}> {rtl ? 'مينا' : 'Mina Park'} {rtl ? 'جو' : 'Jo Bell'} } export default function Radio() { const [theme, setTheme] = useState('Light') const profiles = useProfiles() return {profiles} Theme setTheme(String(value))}> {['Light', 'Dark', 'System'].map(label => {label})} } ``` #### Destructive ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { Archive16Regular, ArrowUndo16Regular, Delete16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} export default function Destructive() { const [status, setStatus] = useState('Draft') return setStatus('Archived')}> setStatus('Draft')}> setStatus('Deleted')}> } ``` #### Sides ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { Box, ContextMenuTarget, Grid, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} export default function Sides() { const [selected, setSelected] = useState('') return {(['top', 'right', 'bottom', 'left'] as const).map(side => setSelected(side)}>Select this edge )} {selected && Selected edge: {selected}} } ``` #### RTL ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular, Wrench16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger } from 'wss3-forge/base-ui' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
} /> {children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } function useDisplay(rtl = false) { const [bookmarks, setBookmarks] = useState(true) const [urls, setUrls] = useState(false) return setBookmarks(value === true)}>{rtl ? 'عرض الإشارات المرجعية' : 'Show Bookmarks'} setUrls(value === true)}>{rtl ? 'عرض العناوين الكاملة' : 'Show Full URLs'} } function useProfiles(rtl = false) { const [owner, setOwner] = useState('mina') return {rtl ? 'الملف الشخصي' : 'Profile'} setOwner(String(value))}> {rtl ? 'مينا' : 'Mina Park'} {rtl ? 'جو' : 'Jo Bell'} } function BrowserActions({ rtl = false }: { rtl?: boolean }) { const history = useHistory(rtl) const display = useDisplay(rtl) const profiles = useProfiles(rtl) function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const command = [...history.navigation, ...history.tools].find(item => event.code === 'Digit' + item.key) if (!command) return event.preventDefault() if ('disabled' in command && command.disabled) return command.run() } return {browserRows(history.navigation, true)} {browserRows(history.tools, true)} {display} {profiles} {history.result === (rtl ? 'أدوات المطور' : 'Developer Tools') && {rtl ? 'مسار الصفحة' : 'Current route'} · {history.path}} } export default function Rtl() { return } ``` ### Radix Compose the trigger using asChild. Use onSelect for commands and dir on the root for right-to-left menus. ```sh npm install wss3-forge radix-ui ``` ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuShortcut, ContextMenuTrigger } from 'wss3-forge/radix' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } export default function Basic() { const history = useHistory() return {browserRows(history.navigation)} } ``` #### Preview ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular, Wrench16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger } from 'wss3-forge/radix' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } function useDisplay(rtl = false) { const [bookmarks, setBookmarks] = useState(true) const [urls, setUrls] = useState(false) return setBookmarks(value === true)}>{rtl ? 'عرض الإشارات المرجعية' : 'Show Bookmarks'} setUrls(value === true)}>{rtl ? 'عرض العناوين الكاملة' : 'Show Full URLs'} } function useProfiles(rtl = false) { const [owner, setOwner] = useState('mina') return {rtl ? 'الملف الشخصي' : 'Profile'} setOwner(String(value))}> {rtl ? 'مينا' : 'Mina Park'} {rtl ? 'جو' : 'Jo Bell'} } export default function BrowserActions({ rtl = false }: { rtl?: boolean }) { const history = useHistory(rtl) const display = useDisplay(rtl) const profiles = useProfiles(rtl) function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const command = [...history.navigation, ...history.tools].find(item => event.code === 'Digit' + item.key) if (!command) return event.preventDefault() if ('disabled' in command && command.disabled) return command.run() } return {browserRows(history.navigation, true)} {browserRows(history.tools, true)} {display} {profiles} {history.result === (rtl ? 'أدوات المطور' : 'Developer Tools') && {rtl ? 'مسار الصفحة' : 'Current route'} · {history.path}} } ``` #### Submenu ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger } from 'wss3-forge/radix' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } export default function Submenu() { const history = useHistory() return {browserRows(history.navigation)} More Tools {browserRows(history.tools)} } ``` #### Shortcuts ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuShortcut, ContextMenuTrigger } from 'wss3-forge/radix' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} export default function Shortcuts() { const [level, setLevel] = useState(100) const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat) return if (event.code === 'Digit1') { event.preventDefault(); setLevel(value => Math.max(50, value - 10)) } if (event.code === 'Digit2') { event.preventDefault(); setLevel(value => Math.min(150, value + 10)) } } return setLevel(value => value - 10)}>Zoom out{modifier}1 setLevel(value => value + 10)}>Zoom in{modifier}2 } ``` #### Groups ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuTrigger } from 'wss3-forge/radix' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} export default function Groups() { const [copies, setCopies] = useState(1) const [archived, setArchived] = useState(false) return Document setCopies(value => value + 1)}>Duplicate Workspace setArchived(value => !value)}>{archived ? 'Restore' : 'Archive'} } ``` #### Icons ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowUndo16Regular, Copy16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from 'wss3-forge/radix' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} export default function Icons() { const [copies, setCopies] = useState(1) return setCopies(value => value + 1)}> setCopies(value => value - 1)}> } ``` #### Checkboxes ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuTrigger } from 'wss3-forge/radix' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} function useDisplay(rtl = false) { const [bookmarks, setBookmarks] = useState(true) const [urls, setUrls] = useState(false) return setBookmarks(value === true)}>{rtl ? 'عرض الإشارات المرجعية' : 'Show Bookmarks'} setUrls(value === true)}>{rtl ? 'عرض العناوين الكاملة' : 'Show Full URLs'} } export default function Checkboxes() { const display = useDisplay() return {display} } ``` #### Radio ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuGroup, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuTrigger } from 'wss3-forge/radix' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} function useProfiles(rtl = false) { const [owner, setOwner] = useState('mina') return {rtl ? 'الملف الشخصي' : 'Profile'} setOwner(String(value))}> {rtl ? 'مينا' : 'Mina Park'} {rtl ? 'جو' : 'Jo Bell'} } export default function Radio() { const [theme, setTheme] = useState('Light') const profiles = useProfiles() return {profiles} Theme setTheme(String(value))}> {['Light', 'Dark', 'System'].map(label => {label})} } ``` #### Destructive ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { Archive16Regular, ArrowUndo16Regular, Delete16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuTrigger } from 'wss3-forge/radix' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} export default function Destructive() { const [status, setStatus] = useState('Draft') return setStatus('Archived')}> setStatus('Draft')}> setStatus('Deleted')}> } ``` #### Sides ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { Box, ContextMenuTarget, Grid, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from 'wss3-forge/radix' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} export default function Sides() { const [selected, setSelected] = useState('') return {(['top', 'right', 'bottom', 'left'] as const).map(side => setSelected(side)}>Select this edge )} {selected && Selected edge: {selected}} } ``` #### RTL ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular, Wrench16Regular } from '@fluentui/react-icons' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger } from 'wss3-forge/radix' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } function useDisplay(rtl = false) { const [bookmarks, setBookmarks] = useState(true) const [urls, setUrls] = useState(false) return setBookmarks(value === true)}>{rtl ? 'عرض الإشارات المرجعية' : 'Show Bookmarks'} setUrls(value === true)}>{rtl ? 'عرض العناوين الكاملة' : 'Show Full URLs'} } function useProfiles(rtl = false) { const [owner, setOwner] = useState('mina') return {rtl ? 'الملف الشخصي' : 'Profile'} setOwner(String(value))}> {rtl ? 'مينا' : 'Mina Park'} {rtl ? 'جو' : 'Jo Bell'} } function BrowserActions({ rtl = false }: { rtl?: boolean }) { const history = useHistory(rtl) const display = useDisplay(rtl) const profiles = useProfiles(rtl) function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const command = [...history.navigation, ...history.tools].find(item => event.code === 'Digit' + item.key) if (!command) return event.preventDefault() if ('disabled' in command && command.disabled) return command.run() } return {browserRows(history.navigation, true)} {browserRows(history.tools, true)} {display} {profiles} {history.result === (rtl ? 'أدوات المطور' : 'Developer Tools') && {rtl ? 'مسار الصفحة' : 'Current route'} · {history.path}} } export default function Rtl() { return } ``` ### React Aria Use Pressable inside ContextMenuTrigger. onAction runs a command. Configure selectedKeys and selectionMode on each MenuSection. ```sh npm install wss3-forge react-aria-components ``` ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular } from '@fluentui/react-icons' import { I18nProvider, Pressable } from 'react-aria-components' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuItem, ContextMenuShortcut, ContextMenuTrigger } from 'wss3-forge/react-aria' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } export default function Basic() { const history = useHistory() return {browserRows(history.navigation)} } ``` #### Preview ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular, Wrench16Regular } from '@fluentui/react-icons' import { I18nProvider, Pressable } from 'react-aria-components' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger } from 'wss3-forge/react-aria' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } function useDisplay(rtl = false) { const [checked, setChecked] = useState>(new Set(['bookmarks'])) return setChecked(new Set(keys === 'all' ? ['bookmarks', 'urls'] : keys))}> {rtl ? 'عرض الإشارات المرجعية' : 'Show Bookmarks'} {rtl ? 'عرض العناوين الكاملة' : 'Show Full URLs'} } function useProfiles(rtl = false) { const [owner, setOwner] = useState>(new Set(['mina'])) return { if (keys !== 'all') setOwner(new Set(keys)) }}> {rtl ? 'الملف الشخصي' : 'Profile'} {rtl ? 'مينا' : 'Mina Park'} {rtl ? 'جو' : 'Jo Bell'} } export default function BrowserActions({ rtl = false }: { rtl?: boolean }) { const history = useHistory(rtl) const display = useDisplay(rtl) const profiles = useProfiles(rtl) function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const command = [...history.navigation, ...history.tools].find(item => event.code === 'Digit' + item.key) if (!command) return event.preventDefault() if ('disabled' in command && command.disabled) return command.run() } return {browserRows(history.navigation, true)} {browserRows(history.tools, true)} {display} {profiles} {history.result === (rtl ? 'أدوات المطور' : 'Developer Tools') && {rtl ? 'مسار الصفحة' : 'Current route'} · {history.path}} } ``` #### Submenu ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular } from '@fluentui/react-icons' import { I18nProvider, Pressable } from 'react-aria-components' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuItem, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger } from 'wss3-forge/react-aria' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } export default function Submenu() { const history = useHistory() return {browserRows(history.navigation)} More Tools {browserRows(history.tools)} } ``` #### Shortcuts ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { I18nProvider, Pressable } from 'react-aria-components' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuItem, ContextMenuShortcut, ContextMenuTrigger } from 'wss3-forge/react-aria' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} export default function Shortcuts() { const [level, setLevel] = useState(100) const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat) return if (event.code === 'Digit1') { event.preventDefault(); setLevel(value => Math.max(50, value - 10)) } if (event.code === 'Digit2') { event.preventDefault(); setLevel(value => Math.min(150, value + 10)) } } return setLevel(value => value - 10)}>Zoom out{modifier}1 setLevel(value => value + 10)}>Zoom in{modifier}2 } ``` #### Groups ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { I18nProvider, Pressable } from 'react-aria-components' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuTrigger } from 'wss3-forge/react-aria' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} export default function Groups() { const [copies, setCopies] = useState(1) const [archived, setArchived] = useState(false) return Document setCopies(value => value + 1)}>Duplicate Workspace setArchived(value => !value)}>{archived ? 'Restore' : 'Archive'} } ``` #### Icons ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowUndo16Regular, Copy16Regular } from '@fluentui/react-icons' import { I18nProvider, Pressable } from 'react-aria-components' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuItem, ContextMenuTrigger } from 'wss3-forge/react-aria' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} export default function Icons() { const [copies, setCopies] = useState(1) return setCopies(value => value + 1)}> setCopies(value => value - 1)}> } ``` #### Checkboxes ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { I18nProvider, Pressable } from 'react-aria-components' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuGroup, ContextMenuItem, ContextMenuTrigger } from 'wss3-forge/react-aria' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} function useDisplay(rtl = false) { const [checked, setChecked] = useState>(new Set(['bookmarks'])) return setChecked(new Set(keys === 'all' ? ['bookmarks', 'urls'] : keys))}> {rtl ? 'عرض الإشارات المرجعية' : 'Show Bookmarks'} {rtl ? 'عرض العناوين الكاملة' : 'Show Full URLs'} } export default function Checkboxes() { const display = useDisplay() return {display} } ``` #### Radio ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { I18nProvider, Pressable } from 'react-aria-components' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuTrigger } from 'wss3-forge/react-aria' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} function useProfiles(rtl = false) { const [owner, setOwner] = useState>(new Set(['mina'])) return { if (keys !== 'all') setOwner(new Set(keys)) }}> {rtl ? 'الملف الشخصي' : 'Profile'} {rtl ? 'مينا' : 'Mina Park'} {rtl ? 'جو' : 'Jo Bell'} } export default function Radio() { const [theme, setTheme] = useState>(new Set(['Light'])) const profiles = useProfiles() return {profiles} { if (keys !== 'all') setTheme(new Set(keys)) }}> Theme {['Light', 'Dark', 'System'].map(label => {label})} } ``` #### Destructive ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { Archive16Regular, ArrowUndo16Regular, Delete16Regular } from '@fluentui/react-icons' import { I18nProvider, Pressable } from 'react-aria-components' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuItem, ContextMenuSeparator, ContextMenuTrigger } from 'wss3-forge/react-aria' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} export default function Destructive() { const [status, setStatus] = useState('Draft') return setStatus('Archived')}> setStatus('Draft')}> setStatus('Deleted')}> } ``` #### Sides ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { I18nProvider, Pressable } from 'react-aria-components' import { Box, ContextMenuTarget, Grid, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuItem, ContextMenuTrigger } from 'wss3-forge/react-aria' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} export default function Sides() { const [selected, setSelected] = useState('') return {(['top', 'right', 'bottom', 'left'] as const).map(side => setSelected(side)}>Select this edge )} {selected && Selected edge: {selected}} } ``` #### RTL ```tsx import { useState, type ReactNode, type KeyboardEvent } from 'react' import { ArrowClockwise16Regular, ArrowLeft16Regular, ArrowRight16Regular, Code16Regular, Link16Regular, Wrench16Regular } from '@fluentui/react-icons' import { I18nProvider, Pressable } from 'react-aria-components' import { ContextMenuTarget, Text, VStack } from 'wss3-forge' import { ContextMenu, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger } from 'wss3-forge/react-aria' function Surface({ children, result, rtl = false, side, onShortcut, width = '12rem' }: { children: ReactNode width?: string result?: string rtl?: boolean side?: 'top' | 'right' | 'bottom' | 'left' onShortcut?: (event: KeyboardEvent) => void }) { const direction = rtl ? 'rtl' : 'ltr' const mouse = rtl ? 'انقر بزر الماوس الأيمن هنا' : side ? 'Right click (' + side + ')' : 'Right click here' const touch = rtl ? 'اضغط مطولاً هنا' : side ? 'Long press (' + side + ')' : 'Long press here' return
{children} {result && {result}}
} function useHistory(rtl = false) { const pages = rtl ? ['الأرشيف', 'الدليل', 'المعرض'] : ['Archive', 'Field guide', 'Gallery'] const [index, setIndex] = useState(2) const [result, setResult] = useState('') function move(delta: number) { const next = index + delta setIndex(next) setResult(pages[next]) } const path = ['/archive', '/guide', '/gallery'][index] const navigation = [ { label: rtl ? 'رجوع' : 'Back', icon: ArrowLeft16Regular, key: '1', disabled: index === 0, run: () => move(-1) }, { label: rtl ? 'تقدم' : 'Forward', icon: ArrowRight16Regular, key: '2', disabled: index === pages.length - 1, run: () => move(1) }, { label: rtl ? 'إعادة تحميل' : 'Reload', icon: ArrowClockwise16Regular, key: '3', run: () => setResult((rtl ? 'تم التحديث · ' : 'Reloaded · ') + pages[index]) }, ] const tools = [ { label: rtl ? 'عرض العنوان' : 'Show address', icon: Link16Regular, key: '4', run: () => setResult((rtl ? 'عنوان الصفحة · ' : 'Page address · ') + path) }, { label: rtl ? 'أدوات المطور' : 'Developer Tools', icon: Code16Regular, key: '5', run: () => setResult(rtl ? 'أدوات المطور' : 'Developer Tools') }, ] return { result, path, navigation, tools } } function browserRows(commands: { label: string; icon: typeof Link16Regular; key: string; run: () => void; disabled?: boolean }[], hints = false) { const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' return commands.map(command => {hints && ) } function useDisplay(rtl = false) { const [checked, setChecked] = useState>(new Set(['bookmarks'])) return setChecked(new Set(keys === 'all' ? ['bookmarks', 'urls'] : keys))}> {rtl ? 'عرض الإشارات المرجعية' : 'Show Bookmarks'} {rtl ? 'عرض العناوين الكاملة' : 'Show Full URLs'} } function useProfiles(rtl = false) { const [owner, setOwner] = useState>(new Set(['mina'])) return { if (keys !== 'all') setOwner(new Set(keys)) }}> {rtl ? 'الملف الشخصي' : 'Profile'} {rtl ? 'مينا' : 'Mina Park'} {rtl ? 'جو' : 'Jo Bell'} } function BrowserActions({ rtl = false }: { rtl?: boolean }) { const history = useHistory(rtl) const display = useDisplay(rtl) const profiles = useProfiles(rtl) function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const command = [...history.navigation, ...history.tools].find(item => event.code === 'Digit' + item.key) if (!command) return event.preventDefault() if ('disabled' in command && command.disabled) return command.run() } return {browserRows(history.navigation, true)} {browserRows(history.tools, true)} {display} {profiles} {history.result === (rtl ? 'أدوات المطور' : 'Developer Tools') && {rtl ? 'مسار الصفحة' : 'Current route'} · {history.path}} } export default function Rtl() { return } ``` ## Root package API ### ContextMenu Show actions for a specific item or surface at the pointer position. Props type: `ContextMenuProps` - `items` — `DropdownItem[]` - `x` — `number` - `y` — `number` - `onClose` — `() => void` - `returnFocusTo?` — `HTMLElement | null` - `anchor?` — `HTMLElement | null` Place the menu next to a trigger and render it outside the scrolling content. - `side?` — `'top' | 'bottom' | 'left' | 'right'` Default `'bottom'`. Options `"top"`, `"bottom"`, `"left"`, `"right"`. - `align?` — `'start' | 'center' | 'end'` Default `'end'`. Options `"start"`, `"end"`, `"center"`. - `label?` — `string` Optional visible group title and accessible menu name. - `initialFocus?` — `MenuEdge` Default `'first'`. Options `"first"`, `"last"`. ## Related types ```ts export interface DropdownItem { id: string label: string /** A boolean makes the item a checked menu choice. Update it in onClick. */ checked?: boolean /** Navigational entries render native links, including modifier-click and context menu support. */ href?: string icon?: ReactNode shortcut?: string // Raccourci clavier (ex: "Ctrl+K") onClick?: () => void disabled?: boolean destructive?: boolean divider?: boolean } type MenuEdge = 'first' | 'last' export interface ContextMenuProps { items: DropdownItem[] x: number y: number onClose: () => void returnFocusTo?: HTMLElement | null /** Place the menu next to a trigger and render it outside the scrolling content. */ anchor?: HTMLElement | null side?: 'top' | 'bottom' | 'left' | 'right' align?: 'start' | 'center' | 'end' /** Optional visible group title and accessible menu name. */ label?: string initialFocus?: MenuEdge } ``` ## Optional primitive contracts - [wss3-forge/base-ui · ContextMenu contract](/ai/skill/primitive-api/ContextMenu.json) - [wss3-forge/radix · ContextMenu contract](/ai/skill/primitive-api/ContextMenu.json) - [wss3-forge/react-aria · ContextMenu contract](/ai/skill/primitive-api/ContextMenu.json)