# Command Search for actions, run a shortcut or open a command palette. [Interactive guide](/docs/components/command) · 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 Command for searching and running a set of actions or navigating project destinations through a command palette. ### How to compose it Choose the matching backend's item identifiers and activation callbacks. Group items, add searchable aliases where supported and connect each displayed shortcut to an actual handler. ### What to verify Try filtering, arrow navigation, activation and Escape. Verify the command runs once and the palette closes only when the workflow calls for it. ## Usage ```tsx import { Command, CommandEmpty, CommandInput, CommandItem, CommandList } from 'wss3-forge' ``` - Type to filter actions. Use the arrow keys to navigate, Enter to run a command and Escape to close the dialog. - Use a stable value for each cmdk item and keywords for additional search terms. React Aria uses id, textValue and onAction. - CommandShortcut displays the key combination. The examples handle shortcuts while focus is inside the command menu, including its search field. - Use headings and separators to organize related commands. Cap the height of long results so the search field stays visible while the list scrolls. - Command size controls density. Set width to sm, md, lg or a CSS width such as 22rem. Use attribution for a source label such as AI or By Webba. - CommandDialog size sets the outer panel width. Its width prop overrides size and leaves at least 1rem on each side of the viewport. Enable showCloseButton for a visible Esc control. - CommandDialog accepts open and onOpenChange. Close it once the action has run. Base UI accepts popupProps, Radix accepts contentProps and React Aria accepts dialogProps. ```tsx export function PrintActions() { return No commands found. window.print()}>Print document } ``` ## Runnable examples ### Workspace commands ```tsx import { Fragment, createContext, useContext, useState, type JSXElementConstructor, type KeyboardEvent, type ReactNode } from 'react' import { Archive16Regular, ArrowUndo16Regular, Checkmark16Regular, Copy16Regular, Document16Regular, DocumentAdd16Regular, Print16Regular } from '@fluentui/react-icons' import { Button, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, Text, VStack } from 'wss3-forge' type Action = { id: string; label: string; icon: typeof Document16Regular; keywords?: string[]; shortcut?: string; disabled?: boolean } type Section = { heading: string; items: Action[] } type Density = 'sm' | 'md' | 'lg' type MenuProps = { size?: Density; width?: string; attribution?: string; sections: Section[]; rtl: boolean; icons: boolean; modifier: string; run: (item: Action) => void } const cmdkParts = { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandSeparator, CommandShortcut } const CmdkContext = createContext(cmdkParts) function Commands({ sections, rtl, icons, modifier, run, size, width, attribution }: MenuProps) { const { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandSeparator, CommandShortcut } = useContext(CmdkContext) return {rtl ? 'لم يتم العثور على نتائج.' : 'No commands found.'} {sections.map((group, i) => {i > 0 && } {group.items.map(item => run(item)}> {icons && )} )} } type PaletteParts = { Menu: JSXElementConstructor; Dialog: JSXElementConstructor<{ open: boolean; onOpenChange: (open: boolean) => void; showCloseButton: boolean; children: ReactNode }> } const PaletteContext = createContext({ Menu: Commands, Dialog: CommandDialog }) function proofActions(rtl = false): Section { return { heading: rtl ? 'إجراءات الطباعة' : 'Proof actions', items: [ { id: 'new', label: rtl ? 'إنشاء بروفة' : 'New proof', icon: DocumentAdd16Regular }, { id: 'duplicate', label: rtl ? 'نسخ البروفة' : 'Duplicate proof', keywords: rtl ? ['نسخة'] : ['copy'], icon: Copy16Regular }, { id: 'print', label: rtl ? 'طباعة البروفة' : 'Print proof', icon: Print16Regular, disabled: true }, ] } } function reviewActions(rtl = false): Section { return { heading: rtl ? 'المراجعة' : 'Review', items: [ { id: 'ready', label: rtl ? 'تعيين كجاهزة' : 'Mark as ready', icon: Checkmark16Regular, shortcut: '1' }, { id: 'draft', label: rtl ? 'إعادة إلى المسودة' : 'Return to draft', icon: ArrowUndo16Regular, shortcut: '2' }, { id: 'archived', label: rtl ? 'أرشفة البروفة' : 'Archive proof', icon: Archive16Regular, shortcut: '3' }, ] } } function ProofCommands({ sections, inline = false, rtl = false, icons = true }: { sections: Section[]; inline?: boolean; rtl?: boolean; icons?: boolean }) { const { Menu, Dialog } = useContext(PaletteContext) const [open, setOpen] = useState(false) const [proof, setProof] = useState({ number: 1, status: 'draft', settings: {} as Record }) const [message, setMessage] = useState('') const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function run(item: Action) { if (item.disabled) return const id = item.id if (id === 'new' || id === 'duplicate') { const number = proof.number + 1 setProof({ number, status: 'draft', settings: id === 'duplicate' ? { ...proof.settings } : {} }) setMessage(rtl ? (id === 'new' ? 'أُنشئت البروفة رقم ' : 'نُسخت البروفة إلى الرقم ') + number : id === 'new' ? 'Created proof #' + number + '.' : 'Duplicated proof #' + proof.number + ' as #' + number + '.') } else if (id.includes('/')) { const [setting, value] = id.split('/') setProof({ ...proof, settings: { ...proof.settings, [setting]: value } }) setMessage('Proof #' + proof.number + ' · ' + setting + ': ' + value) } else { setProof({ ...proof, status: id }) const translated: Record = { ready: 'جاهزة', draft: 'مسودة', archived: 'مؤرشفة' } const status = rtl ? translated[id] ?? id : id setMessage(rtl ? 'البروفة رقم ' + proof.number + ' ' + status : 'Proof #' + proof.number + ' is ' + status + '.') } setOpen(false) } function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const key = event.code.replace(/^Digit/, '') || event.key const action = sections.flatMap(section => section.items).find(item => item.shortcut === key) if (action) { event.preventDefault(); run(action) } } const menu =
return {inline ? menu : <> {menu} } {message && {message}} } export default function Example() { return () } ``` ### Basic ```tsx import { Fragment, createContext, useContext, useState, type JSXElementConstructor, type KeyboardEvent, type ReactNode } from 'react' import { Copy16Regular, Document16Regular, DocumentAdd16Regular, Print16Regular } from '@fluentui/react-icons' import { Button, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, Text, VStack } from 'wss3-forge' type Action = { id: string; label: string; icon: typeof Document16Regular; keywords?: string[]; shortcut?: string; disabled?: boolean } type Section = { heading: string; items: Action[] } type Density = 'sm' | 'md' | 'lg' type MenuProps = { size?: Density; width?: string; attribution?: string; sections: Section[]; rtl: boolean; icons: boolean; modifier: string; run: (item: Action) => void } const cmdkParts = { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandSeparator, CommandShortcut } const CmdkContext = createContext(cmdkParts) function Commands({ sections, rtl, icons, modifier, run, size, width, attribution }: MenuProps) { const { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandSeparator, CommandShortcut } = useContext(CmdkContext) return {rtl ? 'لم يتم العثور على نتائج.' : 'No commands found.'} {sections.map((group, i) => {i > 0 && } {group.items.map(item => run(item)}> {icons && )} )} } type PaletteParts = { Menu: JSXElementConstructor; Dialog: JSXElementConstructor<{ open: boolean; onOpenChange: (open: boolean) => void; showCloseButton: boolean; children: ReactNode }> } const PaletteContext = createContext({ Menu: Commands, Dialog: CommandDialog }) function proofActions(rtl = false): Section { return { heading: rtl ? 'إجراءات الطباعة' : 'Proof actions', items: [ { id: 'new', label: rtl ? 'إنشاء بروفة' : 'New proof', icon: DocumentAdd16Regular }, { id: 'duplicate', label: rtl ? 'نسخ البروفة' : 'Duplicate proof', keywords: rtl ? ['نسخة'] : ['copy'], icon: Copy16Regular }, { id: 'print', label: rtl ? 'طباعة البروفة' : 'Print proof', icon: Print16Regular, disabled: true }, ] } } function ProofCommands({ sections, inline = false, rtl = false, icons = true }: { sections: Section[]; inline?: boolean; rtl?: boolean; icons?: boolean }) { const { Menu, Dialog } = useContext(PaletteContext) const [open, setOpen] = useState(false) const [proof, setProof] = useState({ number: 1, status: 'draft', settings: {} as Record }) const [message, setMessage] = useState('') const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function run(item: Action) { if (item.disabled) return const id = item.id if (id === 'new' || id === 'duplicate') { const number = proof.number + 1 setProof({ number, status: 'draft', settings: id === 'duplicate' ? { ...proof.settings } : {} }) setMessage(rtl ? (id === 'new' ? 'أُنشئت البروفة رقم ' : 'نُسخت البروفة إلى الرقم ') + number : id === 'new' ? 'Created proof #' + number + '.' : 'Duplicated proof #' + proof.number + ' as #' + number + '.') } else if (id.includes('/')) { const [setting, value] = id.split('/') setProof({ ...proof, settings: { ...proof.settings, [setting]: value } }) setMessage('Proof #' + proof.number + ' · ' + setting + ': ' + value) } else { setProof({ ...proof, status: id }) const translated: Record = { ready: 'جاهزة', draft: 'مسودة', archived: 'مؤرشفة' } const status = rtl ? translated[id] ?? id : id setMessage(rtl ? 'البروفة رقم ' + proof.number + ' ' + status : 'Proof #' + proof.number + ' is ' + status + '.') } setOpen(false) } function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const key = event.code.replace(/^Digit/, '') || event.key const action = sections.flatMap(section => section.items).find(item => item.shortcut === key) if (action) { event.preventDefault(); run(action) } } const menu =
return {inline ? menu : <> {menu} } {message && {message}} } export default function Example() { return () } ``` ### Shortcuts ```tsx import { Fragment, createContext, useContext, useState, type JSXElementConstructor, type KeyboardEvent, type ReactNode } from 'react' import { Archive16Regular, ArrowUndo16Regular, Checkmark16Regular, Document16Regular } from '@fluentui/react-icons' import { Button, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, Text, VStack } from 'wss3-forge' type Action = { id: string; label: string; icon: typeof Document16Regular; keywords?: string[]; shortcut?: string; disabled?: boolean } type Section = { heading: string; items: Action[] } type Density = 'sm' | 'md' | 'lg' type MenuProps = { size?: Density; width?: string; attribution?: string; sections: Section[]; rtl: boolean; icons: boolean; modifier: string; run: (item: Action) => void } const cmdkParts = { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandSeparator, CommandShortcut } const CmdkContext = createContext(cmdkParts) function Commands({ sections, rtl, icons, modifier, run, size, width, attribution }: MenuProps) { const { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandSeparator, CommandShortcut } = useContext(CmdkContext) return {rtl ? 'لم يتم العثور على نتائج.' : 'No commands found.'} {sections.map((group, i) => {i > 0 && } {group.items.map(item => run(item)}> {icons && )} )} } type PaletteParts = { Menu: JSXElementConstructor; Dialog: JSXElementConstructor<{ open: boolean; onOpenChange: (open: boolean) => void; showCloseButton: boolean; children: ReactNode }> } const PaletteContext = createContext({ Menu: Commands, Dialog: CommandDialog }) function reviewActions(rtl = false): Section { return { heading: rtl ? 'المراجعة' : 'Review', items: [ { id: 'ready', label: rtl ? 'تعيين كجاهزة' : 'Mark as ready', icon: Checkmark16Regular, shortcut: '1' }, { id: 'draft', label: rtl ? 'إعادة إلى المسودة' : 'Return to draft', icon: ArrowUndo16Regular, shortcut: '2' }, { id: 'archived', label: rtl ? 'أرشفة البروفة' : 'Archive proof', icon: Archive16Regular, shortcut: '3' }, ] } } function ProofCommands({ sections, inline = false, rtl = false, icons = true }: { sections: Section[]; inline?: boolean; rtl?: boolean; icons?: boolean }) { const { Menu, Dialog } = useContext(PaletteContext) const [open, setOpen] = useState(false) const [proof, setProof] = useState({ number: 1, status: 'draft', settings: {} as Record }) const [message, setMessage] = useState('') const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function run(item: Action) { if (item.disabled) return const id = item.id if (id === 'new' || id === 'duplicate') { const number = proof.number + 1 setProof({ number, status: 'draft', settings: id === 'duplicate' ? { ...proof.settings } : {} }) setMessage(rtl ? (id === 'new' ? 'أُنشئت البروفة رقم ' : 'نُسخت البروفة إلى الرقم ') + number : id === 'new' ? 'Created proof #' + number + '.' : 'Duplicated proof #' + proof.number + ' as #' + number + '.') } else if (id.includes('/')) { const [setting, value] = id.split('/') setProof({ ...proof, settings: { ...proof.settings, [setting]: value } }) setMessage('Proof #' + proof.number + ' · ' + setting + ': ' + value) } else { setProof({ ...proof, status: id }) const translated: Record = { ready: 'جاهزة', draft: 'مسودة', archived: 'مؤرشفة' } const status = rtl ? translated[id] ?? id : id setMessage(rtl ? 'البروفة رقم ' + proof.number + ' ' + status : 'Proof #' + proof.number + ' is ' + status + '.') } setOpen(false) } function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const key = event.code.replace(/^Digit/, '') || event.key const action = sections.flatMap(section => section.items).find(item => item.shortcut === key) if (action) { event.preventDefault(); run(action) } } const menu =
return {inline ? menu : <> {menu} } {message && {message}} } export default function Example() { return () } ``` ### Groups ```tsx import { Fragment, createContext, useContext, useState, type JSXElementConstructor, type KeyboardEvent, type ReactNode } from 'react' import { Archive16Regular, ArrowUndo16Regular, Checkmark16Regular, Copy16Regular, Document16Regular, DocumentAdd16Regular, Print16Regular } from '@fluentui/react-icons' import { Button, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, Text, VStack } from 'wss3-forge' type Action = { id: string; label: string; icon: typeof Document16Regular; keywords?: string[]; shortcut?: string; disabled?: boolean } type Section = { heading: string; items: Action[] } type Density = 'sm' | 'md' | 'lg' type MenuProps = { size?: Density; width?: string; attribution?: string; sections: Section[]; rtl: boolean; icons: boolean; modifier: string; run: (item: Action) => void } const cmdkParts = { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandSeparator, CommandShortcut } const CmdkContext = createContext(cmdkParts) function Commands({ sections, rtl, icons, modifier, run, size, width, attribution }: MenuProps) { const { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandSeparator, CommandShortcut } = useContext(CmdkContext) return {rtl ? 'لم يتم العثور على نتائج.' : 'No commands found.'} {sections.map((group, i) => {i > 0 && } {group.items.map(item => run(item)}> {icons && )} )} } type PaletteParts = { Menu: JSXElementConstructor; Dialog: JSXElementConstructor<{ open: boolean; onOpenChange: (open: boolean) => void; showCloseButton: boolean; children: ReactNode }> } const PaletteContext = createContext({ Menu: Commands, Dialog: CommandDialog }) function proofActions(rtl = false): Section { return { heading: rtl ? 'إجراءات الطباعة' : 'Proof actions', items: [ { id: 'new', label: rtl ? 'إنشاء بروفة' : 'New proof', icon: DocumentAdd16Regular }, { id: 'duplicate', label: rtl ? 'نسخ البروفة' : 'Duplicate proof', keywords: rtl ? ['نسخة'] : ['copy'], icon: Copy16Regular }, { id: 'print', label: rtl ? 'طباعة البروفة' : 'Print proof', icon: Print16Regular, disabled: true }, ] } } function reviewActions(rtl = false): Section { return { heading: rtl ? 'المراجعة' : 'Review', items: [ { id: 'ready', label: rtl ? 'تعيين كجاهزة' : 'Mark as ready', icon: Checkmark16Regular, shortcut: '1' }, { id: 'draft', label: rtl ? 'إعادة إلى المسودة' : 'Return to draft', icon: ArrowUndo16Regular, shortcut: '2' }, { id: 'archived', label: rtl ? 'أرشفة البروفة' : 'Archive proof', icon: Archive16Regular, shortcut: '3' }, ] } } function ProofCommands({ sections, inline = false, rtl = false, icons = true }: { sections: Section[]; inline?: boolean; rtl?: boolean; icons?: boolean }) { const { Menu, Dialog } = useContext(PaletteContext) const [open, setOpen] = useState(false) const [proof, setProof] = useState({ number: 1, status: 'draft', settings: {} as Record }) const [message, setMessage] = useState('') const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function run(item: Action) { if (item.disabled) return const id = item.id if (id === 'new' || id === 'duplicate') { const number = proof.number + 1 setProof({ number, status: 'draft', settings: id === 'duplicate' ? { ...proof.settings } : {} }) setMessage(rtl ? (id === 'new' ? 'أُنشئت البروفة رقم ' : 'نُسخت البروفة إلى الرقم ') + number : id === 'new' ? 'Created proof #' + number + '.' : 'Duplicated proof #' + proof.number + ' as #' + number + '.') } else if (id.includes('/')) { const [setting, value] = id.split('/') setProof({ ...proof, settings: { ...proof.settings, [setting]: value } }) setMessage('Proof #' + proof.number + ' · ' + setting + ': ' + value) } else { setProof({ ...proof, status: id }) const translated: Record = { ready: 'جاهزة', draft: 'مسودة', archived: 'مؤرشفة' } const status = rtl ? translated[id] ?? id : id setMessage(rtl ? 'البروفة رقم ' + proof.number + ' ' + status : 'Proof #' + proof.number + ' is ' + status + '.') } setOpen(false) } function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const key = event.code.replace(/^Digit/, '') || event.key const action = sections.flatMap(section => section.items).find(item => item.shortcut === key) if (action) { event.preventDefault(); run(action) } } const menu =
return {inline ? menu : <> {menu} } {message && {message}} } export default function Example() { return () } ``` ### Scrollable ```tsx import { Fragment, createContext, useContext, useState, type JSXElementConstructor, type KeyboardEvent, type ReactNode } from 'react' import { Archive16Regular, ArrowUndo16Regular, Checkmark16Regular, Copy16Regular, Document16Regular, DocumentAdd16Regular, Print16Regular } from '@fluentui/react-icons' import { Button, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, Text, VStack } from 'wss3-forge' type Action = { id: string; label: string; icon: typeof Document16Regular; keywords?: string[]; shortcut?: string; disabled?: boolean } type Section = { heading: string; items: Action[] } type Density = 'sm' | 'md' | 'lg' type MenuProps = { size?: Density; width?: string; attribution?: string; sections: Section[]; rtl: boolean; icons: boolean; modifier: string; run: (item: Action) => void } const cmdkParts = { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandSeparator, CommandShortcut } const CmdkContext = createContext(cmdkParts) function Commands({ sections, rtl, icons, modifier, run, size, width, attribution }: MenuProps) { const { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandSeparator, CommandShortcut } = useContext(CmdkContext) return {rtl ? 'لم يتم العثور على نتائج.' : 'No commands found.'} {sections.map((group, i) => {i > 0 && } {group.items.map(item => run(item)}> {icons && )} )} } type PaletteParts = { Menu: JSXElementConstructor; Dialog: JSXElementConstructor<{ open: boolean; onOpenChange: (open: boolean) => void; showCloseButton: boolean; children: ReactNode }> } const PaletteContext = createContext({ Menu: Commands, Dialog: CommandDialog }) function proofActions(rtl = false): Section { return { heading: rtl ? 'إجراءات الطباعة' : 'Proof actions', items: [ { id: 'new', label: rtl ? 'إنشاء بروفة' : 'New proof', icon: DocumentAdd16Regular }, { id: 'duplicate', label: rtl ? 'نسخ البروفة' : 'Duplicate proof', keywords: rtl ? ['نسخة'] : ['copy'], icon: Copy16Regular }, { id: 'print', label: rtl ? 'طباعة البروفة' : 'Print proof', icon: Print16Regular, disabled: true }, ] } } function reviewActions(rtl = false): Section { return { heading: rtl ? 'المراجعة' : 'Review', items: [ { id: 'ready', label: rtl ? 'تعيين كجاهزة' : 'Mark as ready', icon: Checkmark16Regular, shortcut: '1' }, { id: 'draft', label: rtl ? 'إعادة إلى المسودة' : 'Return to draft', icon: ArrowUndo16Regular, shortcut: '2' }, { id: 'archived', label: rtl ? 'أرشفة البروفة' : 'Archive proof', icon: Archive16Regular, shortcut: '3' }, ] } } function settingChoices(heading: string, values: string[]): Section { return { heading, items: values.map(label => ({ id: heading + '/' + label, label, icon: Document16Regular })) } } function ProofCommands({ sections, inline = false, rtl = false, icons = true }: { sections: Section[]; inline?: boolean; rtl?: boolean; icons?: boolean }) { const { Menu, Dialog } = useContext(PaletteContext) const [open, setOpen] = useState(false) const [proof, setProof] = useState({ number: 1, status: 'draft', settings: {} as Record }) const [message, setMessage] = useState('') const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function run(item: Action) { if (item.disabled) return const id = item.id if (id === 'new' || id === 'duplicate') { const number = proof.number + 1 setProof({ number, status: 'draft', settings: id === 'duplicate' ? { ...proof.settings } : {} }) setMessage(rtl ? (id === 'new' ? 'أُنشئت البروفة رقم ' : 'نُسخت البروفة إلى الرقم ') + number : id === 'new' ? 'Created proof #' + number + '.' : 'Duplicated proof #' + proof.number + ' as #' + number + '.') } else if (id.includes('/')) { const [setting, value] = id.split('/') setProof({ ...proof, settings: { ...proof.settings, [setting]: value } }) setMessage('Proof #' + proof.number + ' · ' + setting + ': ' + value) } else { setProof({ ...proof, status: id }) const translated: Record = { ready: 'جاهزة', draft: 'مسودة', archived: 'مؤرشفة' } const status = rtl ? translated[id] ?? id : id setMessage(rtl ? 'البروفة رقم ' + proof.number + ' ' + status : 'Proof #' + proof.number + ' is ' + status + '.') } setOpen(false) } function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const key = event.code.replace(/^Digit/, '') || event.key const action = sections.flatMap(section => section.items).find(item => item.shortcut === key) if (action) { event.preventDefault(); run(action) } } const menu =
return {inline ? menu : <> {menu} } {message && {message}} } export default function Example() { return () } ``` ### Size, width and attribution ```tsx import { Fragment, createContext, useContext, useState, type JSXElementConstructor, type ReactNode } from 'react' import { Document16Regular } from '@fluentui/react-icons' import { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, HStack, Select, Text, VStack } from 'wss3-forge' type Action = { id: string; label: string; icon: typeof Document16Regular; keywords?: string[]; shortcut?: string; disabled?: boolean } type Section = { heading: string; items: Action[] } type Density = 'sm' | 'md' | 'lg' type MenuProps = { size?: Density; width?: string; attribution?: string; sections: Section[]; rtl: boolean; icons: boolean; modifier: string; run: (item: Action) => void } const cmdkParts = { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandSeparator, CommandShortcut } const CmdkContext = createContext(cmdkParts) function Commands({ sections, rtl, icons, modifier, run, size, width, attribution }: MenuProps) { const { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandSeparator, CommandShortcut } = useContext(CmdkContext) return {rtl ? 'لم يتم العثور على نتائج.' : 'No commands found.'} {sections.map((group, i) => {i > 0 && } {group.items.map(item => run(item)}> {icons && )} )} } type PaletteParts = { Menu: JSXElementConstructor; Dialog: JSXElementConstructor<{ open: boolean; onOpenChange: (open: boolean) => void; showCloseButton: boolean; children: ReactNode }> } const PaletteContext = createContext({ Menu: Commands, Dialog: CommandDialog }) function settingChoices(heading: string, values: string[]): Section { return { heading, items: values.map(label => ({ id: heading + '/' + label, label, icon: Document16Regular })) } } function PaletteAppearance() { const { Menu } = useContext(PaletteContext) const [size, setSize] = useState('md') const [width, setWidth] = useState('md') const [attribution, setAttribution] = useState('By Webba') const [paper, setPaper] = useState('') return setSize(value as Density)} /> setPaper(item.label)} /> {paper && Selected paper: {paper}} } export default function Example() { return () } ``` #### RTL ```tsx import { Fragment, useState, type KeyboardEvent } from 'react' import { Archive16Regular, ArrowUndo16Regular, Checkmark16Regular, Copy16Regular, Document16Regular, DocumentAdd16Regular, Print16Regular } from '@fluentui/react-icons' import { Button, Text, VStack } from 'wss3-forge' import { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut } from 'wss3-forge/base-ui' type Action = { id: string; label: string; icon: typeof Document16Regular; keywords?: string[]; shortcut?: string; disabled?: boolean } type Section = { heading: string; items: Action[] } type Density = 'sm' | 'md' | 'lg' type MenuProps = { size?: Density; width?: string; attribution?: string; sections: Section[]; rtl: boolean; icons: boolean; modifier: string; run: (item: Action) => void } function Commands({ sections, rtl, icons, modifier, run, size, width, attribution }: MenuProps) { return {rtl ? 'لم يتم العثور على نتائج.' : 'No commands found.'} {sections.map((group, i) => {i > 0 && } {group.items.map(item => run(item)}> {icons && )} )} } function proofActions(rtl = false): Section { return { heading: rtl ? 'إجراءات الطباعة' : 'Proof actions', items: [ { id: 'new', label: rtl ? 'إنشاء بروفة' : 'New proof', icon: DocumentAdd16Regular }, { id: 'duplicate', label: rtl ? 'نسخ البروفة' : 'Duplicate proof', keywords: rtl ? ['نسخة'] : ['copy'], icon: Copy16Regular }, { id: 'print', label: rtl ? 'طباعة البروفة' : 'Print proof', icon: Print16Regular, disabled: true }, ] } } function reviewActions(rtl = false): Section { return { heading: rtl ? 'المراجعة' : 'Review', items: [ { id: 'ready', label: rtl ? 'تعيين كجاهزة' : 'Mark as ready', icon: Checkmark16Regular, shortcut: '1' }, { id: 'draft', label: rtl ? 'إعادة إلى المسودة' : 'Return to draft', icon: ArrowUndo16Regular, shortcut: '2' }, { id: 'archived', label: rtl ? 'أرشفة البروفة' : 'Archive proof', icon: Archive16Regular, shortcut: '3' }, ] } } function ProofCommands({ sections, inline = false, rtl = false, icons = true }: { sections: Section[]; inline?: boolean; rtl?: boolean; icons?: boolean }) { const [open, setOpen] = useState(false) const [proof, setProof] = useState({ number: 1, status: 'draft', settings: {} as Record }) const [message, setMessage] = useState('') const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function run(item: Action) { if (item.disabled) return const id = item.id if (id === 'new' || id === 'duplicate') { const number = proof.number + 1 setProof({ number, status: 'draft', settings: id === 'duplicate' ? { ...proof.settings } : {} }) setMessage(rtl ? (id === 'new' ? 'أُنشئت البروفة رقم ' : 'نُسخت البروفة إلى الرقم ') + number : id === 'new' ? 'Created proof #' + number + '.' : 'Duplicated proof #' + proof.number + ' as #' + number + '.') } else if (id.includes('/')) { const [setting, value] = id.split('/') setProof({ ...proof, settings: { ...proof.settings, [setting]: value } }) setMessage('Proof #' + proof.number + ' · ' + setting + ': ' + value) } else { setProof({ ...proof, status: id }) const translated: Record = { ready: 'جاهزة', draft: 'مسودة', archived: 'مؤرشفة' } const status = rtl ? translated[id] ?? id : id setMessage(rtl ? 'البروفة رقم ' + proof.number + ' ' + status : 'Proof #' + proof.number + ' is ' + status + '.') } setOpen(false) } function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const key = event.code.replace(/^Digit/, '') || event.key const action = sections.flatMap(section => section.items).find(item => item.shortcut === key) if (action) { event.preventDefault(); run(action) } } const menu =
return {inline ? menu : <> {menu} } {message && {message}} } export default function Example() { return () } ``` ### Radix The command menu uses cmdk. Use value, keywords and onSelect for each item. CommandDialog uses Radix Dialog. ```sh npm install wss3-forge radix-ui ``` ```tsx import { Fragment, useState, type KeyboardEvent } from 'react' import { Archive16Regular, ArrowUndo16Regular, Checkmark16Regular, Copy16Regular, Document16Regular, DocumentAdd16Regular, Print16Regular } from '@fluentui/react-icons' import { Button, Text, VStack } from 'wss3-forge' import { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut } from 'wss3-forge/radix' type Action = { id: string; label: string; icon: typeof Document16Regular; keywords?: string[]; shortcut?: string; disabled?: boolean } type Section = { heading: string; items: Action[] } type Density = 'sm' | 'md' | 'lg' type MenuProps = { size?: Density; width?: string; attribution?: string; sections: Section[]; rtl: boolean; icons: boolean; modifier: string; run: (item: Action) => void } function Commands({ sections, rtl, icons, modifier, run, size, width, attribution }: MenuProps) { return {rtl ? 'لم يتم العثور على نتائج.' : 'No commands found.'} {sections.map((group, i) => {i > 0 && } {group.items.map(item => run(item)}> {icons && )} )} } function proofActions(rtl = false): Section { return { heading: rtl ? 'إجراءات الطباعة' : 'Proof actions', items: [ { id: 'new', label: rtl ? 'إنشاء بروفة' : 'New proof', icon: DocumentAdd16Regular }, { id: 'duplicate', label: rtl ? 'نسخ البروفة' : 'Duplicate proof', keywords: rtl ? ['نسخة'] : ['copy'], icon: Copy16Regular }, { id: 'print', label: rtl ? 'طباعة البروفة' : 'Print proof', icon: Print16Regular, disabled: true }, ] } } function reviewActions(rtl = false): Section { return { heading: rtl ? 'المراجعة' : 'Review', items: [ { id: 'ready', label: rtl ? 'تعيين كجاهزة' : 'Mark as ready', icon: Checkmark16Regular, shortcut: '1' }, { id: 'draft', label: rtl ? 'إعادة إلى المسودة' : 'Return to draft', icon: ArrowUndo16Regular, shortcut: '2' }, { id: 'archived', label: rtl ? 'أرشفة البروفة' : 'Archive proof', icon: Archive16Regular, shortcut: '3' }, ] } } function ProofCommands({ sections, inline = false, rtl = false, icons = true }: { sections: Section[]; inline?: boolean; rtl?: boolean; icons?: boolean }) { const [open, setOpen] = useState(false) const [proof, setProof] = useState({ number: 1, status: 'draft', settings: {} as Record }) const [message, setMessage] = useState('') const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function run(item: Action) { if (item.disabled) return const id = item.id if (id === 'new' || id === 'duplicate') { const number = proof.number + 1 setProof({ number, status: 'draft', settings: id === 'duplicate' ? { ...proof.settings } : {} }) setMessage(rtl ? (id === 'new' ? 'أُنشئت البروفة رقم ' : 'نُسخت البروفة إلى الرقم ') + number : id === 'new' ? 'Created proof #' + number + '.' : 'Duplicated proof #' + proof.number + ' as #' + number + '.') } else if (id.includes('/')) { const [setting, value] = id.split('/') setProof({ ...proof, settings: { ...proof.settings, [setting]: value } }) setMessage('Proof #' + proof.number + ' · ' + setting + ': ' + value) } else { setProof({ ...proof, status: id }) const translated: Record = { ready: 'جاهزة', draft: 'مسودة', archived: 'مؤرشفة' } const status = rtl ? translated[id] ?? id : id setMessage(rtl ? 'البروفة رقم ' + proof.number + ' ' + status : 'Proof #' + proof.number + ' is ' + status + '.') } setOpen(false) } function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const key = event.code.replace(/^Digit/, '') || event.key const action = sections.flatMap(section => section.items).find(item => item.shortcut === key) if (action) { event.preventDefault(); run(action) } } const menu =
return {inline ? menu : <> {menu} } {message && {message}} } export default function Example() { return () } ``` #### Basic ```tsx import { Fragment, useState, type KeyboardEvent } from 'react' import { Copy16Regular, Document16Regular, DocumentAdd16Regular, Print16Regular } from '@fluentui/react-icons' import { Button, Text, VStack } from 'wss3-forge' import { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut } from 'wss3-forge/radix' type Action = { id: string; label: string; icon: typeof Document16Regular; keywords?: string[]; shortcut?: string; disabled?: boolean } type Section = { heading: string; items: Action[] } type Density = 'sm' | 'md' | 'lg' type MenuProps = { size?: Density; width?: string; attribution?: string; sections: Section[]; rtl: boolean; icons: boolean; modifier: string; run: (item: Action) => void } function Commands({ sections, rtl, icons, modifier, run, size, width, attribution }: MenuProps) { return {rtl ? 'لم يتم العثور على نتائج.' : 'No commands found.'} {sections.map((group, i) => {i > 0 && } {group.items.map(item => run(item)}> {icons && )} )} } function proofActions(rtl = false): Section { return { heading: rtl ? 'إجراءات الطباعة' : 'Proof actions', items: [ { id: 'new', label: rtl ? 'إنشاء بروفة' : 'New proof', icon: DocumentAdd16Regular }, { id: 'duplicate', label: rtl ? 'نسخ البروفة' : 'Duplicate proof', keywords: rtl ? ['نسخة'] : ['copy'], icon: Copy16Regular }, { id: 'print', label: rtl ? 'طباعة البروفة' : 'Print proof', icon: Print16Regular, disabled: true }, ] } } function ProofCommands({ sections, inline = false, rtl = false, icons = true }: { sections: Section[]; inline?: boolean; rtl?: boolean; icons?: boolean }) { const [open, setOpen] = useState(false) const [proof, setProof] = useState({ number: 1, status: 'draft', settings: {} as Record }) const [message, setMessage] = useState('') const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function run(item: Action) { if (item.disabled) return const id = item.id if (id === 'new' || id === 'duplicate') { const number = proof.number + 1 setProof({ number, status: 'draft', settings: id === 'duplicate' ? { ...proof.settings } : {} }) setMessage(rtl ? (id === 'new' ? 'أُنشئت البروفة رقم ' : 'نُسخت البروفة إلى الرقم ') + number : id === 'new' ? 'Created proof #' + number + '.' : 'Duplicated proof #' + proof.number + ' as #' + number + '.') } else if (id.includes('/')) { const [setting, value] = id.split('/') setProof({ ...proof, settings: { ...proof.settings, [setting]: value } }) setMessage('Proof #' + proof.number + ' · ' + setting + ': ' + value) } else { setProof({ ...proof, status: id }) const translated: Record = { ready: 'جاهزة', draft: 'مسودة', archived: 'مؤرشفة' } const status = rtl ? translated[id] ?? id : id setMessage(rtl ? 'البروفة رقم ' + proof.number + ' ' + status : 'Proof #' + proof.number + ' is ' + status + '.') } setOpen(false) } function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const key = event.code.replace(/^Digit/, '') || event.key const action = sections.flatMap(section => section.items).find(item => item.shortcut === key) if (action) { event.preventDefault(); run(action) } } const menu =
return {inline ? menu : <> {menu} } {message && {message}} } export default function Example() { return () } ``` #### Shortcuts ```tsx import { Fragment, useState, type KeyboardEvent } from 'react' import { Archive16Regular, ArrowUndo16Regular, Checkmark16Regular, Document16Regular } from '@fluentui/react-icons' import { Button, Text, VStack } from 'wss3-forge' import { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut } from 'wss3-forge/radix' type Action = { id: string; label: string; icon: typeof Document16Regular; keywords?: string[]; shortcut?: string; disabled?: boolean } type Section = { heading: string; items: Action[] } type Density = 'sm' | 'md' | 'lg' type MenuProps = { size?: Density; width?: string; attribution?: string; sections: Section[]; rtl: boolean; icons: boolean; modifier: string; run: (item: Action) => void } function Commands({ sections, rtl, icons, modifier, run, size, width, attribution }: MenuProps) { return {rtl ? 'لم يتم العثور على نتائج.' : 'No commands found.'} {sections.map((group, i) => {i > 0 && } {group.items.map(item => run(item)}> {icons && )} )} } function reviewActions(rtl = false): Section { return { heading: rtl ? 'المراجعة' : 'Review', items: [ { id: 'ready', label: rtl ? 'تعيين كجاهزة' : 'Mark as ready', icon: Checkmark16Regular, shortcut: '1' }, { id: 'draft', label: rtl ? 'إعادة إلى المسودة' : 'Return to draft', icon: ArrowUndo16Regular, shortcut: '2' }, { id: 'archived', label: rtl ? 'أرشفة البروفة' : 'Archive proof', icon: Archive16Regular, shortcut: '3' }, ] } } function ProofCommands({ sections, inline = false, rtl = false, icons = true }: { sections: Section[]; inline?: boolean; rtl?: boolean; icons?: boolean }) { const [open, setOpen] = useState(false) const [proof, setProof] = useState({ number: 1, status: 'draft', settings: {} as Record }) const [message, setMessage] = useState('') const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function run(item: Action) { if (item.disabled) return const id = item.id if (id === 'new' || id === 'duplicate') { const number = proof.number + 1 setProof({ number, status: 'draft', settings: id === 'duplicate' ? { ...proof.settings } : {} }) setMessage(rtl ? (id === 'new' ? 'أُنشئت البروفة رقم ' : 'نُسخت البروفة إلى الرقم ') + number : id === 'new' ? 'Created proof #' + number + '.' : 'Duplicated proof #' + proof.number + ' as #' + number + '.') } else if (id.includes('/')) { const [setting, value] = id.split('/') setProof({ ...proof, settings: { ...proof.settings, [setting]: value } }) setMessage('Proof #' + proof.number + ' · ' + setting + ': ' + value) } else { setProof({ ...proof, status: id }) const translated: Record = { ready: 'جاهزة', draft: 'مسودة', archived: 'مؤرشفة' } const status = rtl ? translated[id] ?? id : id setMessage(rtl ? 'البروفة رقم ' + proof.number + ' ' + status : 'Proof #' + proof.number + ' is ' + status + '.') } setOpen(false) } function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const key = event.code.replace(/^Digit/, '') || event.key const action = sections.flatMap(section => section.items).find(item => item.shortcut === key) if (action) { event.preventDefault(); run(action) } } const menu =
return {inline ? menu : <> {menu} } {message && {message}} } export default function Example() { return () } ``` #### Groups ```tsx import { Fragment, useState, type KeyboardEvent } from 'react' import { Archive16Regular, ArrowUndo16Regular, Checkmark16Regular, Copy16Regular, Document16Regular, DocumentAdd16Regular, Print16Regular } from '@fluentui/react-icons' import { Button, Text, VStack } from 'wss3-forge' import { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut } from 'wss3-forge/radix' type Action = { id: string; label: string; icon: typeof Document16Regular; keywords?: string[]; shortcut?: string; disabled?: boolean } type Section = { heading: string; items: Action[] } type Density = 'sm' | 'md' | 'lg' type MenuProps = { size?: Density; width?: string; attribution?: string; sections: Section[]; rtl: boolean; icons: boolean; modifier: string; run: (item: Action) => void } function Commands({ sections, rtl, icons, modifier, run, size, width, attribution }: MenuProps) { return {rtl ? 'لم يتم العثور على نتائج.' : 'No commands found.'} {sections.map((group, i) => {i > 0 && } {group.items.map(item => run(item)}> {icons && )} )} } function proofActions(rtl = false): Section { return { heading: rtl ? 'إجراءات الطباعة' : 'Proof actions', items: [ { id: 'new', label: rtl ? 'إنشاء بروفة' : 'New proof', icon: DocumentAdd16Regular }, { id: 'duplicate', label: rtl ? 'نسخ البروفة' : 'Duplicate proof', keywords: rtl ? ['نسخة'] : ['copy'], icon: Copy16Regular }, { id: 'print', label: rtl ? 'طباعة البروفة' : 'Print proof', icon: Print16Regular, disabled: true }, ] } } function reviewActions(rtl = false): Section { return { heading: rtl ? 'المراجعة' : 'Review', items: [ { id: 'ready', label: rtl ? 'تعيين كجاهزة' : 'Mark as ready', icon: Checkmark16Regular, shortcut: '1' }, { id: 'draft', label: rtl ? 'إعادة إلى المسودة' : 'Return to draft', icon: ArrowUndo16Regular, shortcut: '2' }, { id: 'archived', label: rtl ? 'أرشفة البروفة' : 'Archive proof', icon: Archive16Regular, shortcut: '3' }, ] } } function ProofCommands({ sections, inline = false, rtl = false, icons = true }: { sections: Section[]; inline?: boolean; rtl?: boolean; icons?: boolean }) { const [open, setOpen] = useState(false) const [proof, setProof] = useState({ number: 1, status: 'draft', settings: {} as Record }) const [message, setMessage] = useState('') const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function run(item: Action) { if (item.disabled) return const id = item.id if (id === 'new' || id === 'duplicate') { const number = proof.number + 1 setProof({ number, status: 'draft', settings: id === 'duplicate' ? { ...proof.settings } : {} }) setMessage(rtl ? (id === 'new' ? 'أُنشئت البروفة رقم ' : 'نُسخت البروفة إلى الرقم ') + number : id === 'new' ? 'Created proof #' + number + '.' : 'Duplicated proof #' + proof.number + ' as #' + number + '.') } else if (id.includes('/')) { const [setting, value] = id.split('/') setProof({ ...proof, settings: { ...proof.settings, [setting]: value } }) setMessage('Proof #' + proof.number + ' · ' + setting + ': ' + value) } else { setProof({ ...proof, status: id }) const translated: Record = { ready: 'جاهزة', draft: 'مسودة', archived: 'مؤرشفة' } const status = rtl ? translated[id] ?? id : id setMessage(rtl ? 'البروفة رقم ' + proof.number + ' ' + status : 'Proof #' + proof.number + ' is ' + status + '.') } setOpen(false) } function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const key = event.code.replace(/^Digit/, '') || event.key const action = sections.flatMap(section => section.items).find(item => item.shortcut === key) if (action) { event.preventDefault(); run(action) } } const menu =
return {inline ? menu : <> {menu} } {message && {message}} } export default function Example() { return () } ``` #### Scrollable ```tsx import { Fragment, useState, type KeyboardEvent } from 'react' import { Archive16Regular, ArrowUndo16Regular, Checkmark16Regular, Copy16Regular, Document16Regular, DocumentAdd16Regular, Print16Regular } from '@fluentui/react-icons' import { Button, Text, VStack } from 'wss3-forge' import { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut } from 'wss3-forge/radix' type Action = { id: string; label: string; icon: typeof Document16Regular; keywords?: string[]; shortcut?: string; disabled?: boolean } type Section = { heading: string; items: Action[] } type Density = 'sm' | 'md' | 'lg' type MenuProps = { size?: Density; width?: string; attribution?: string; sections: Section[]; rtl: boolean; icons: boolean; modifier: string; run: (item: Action) => void } function Commands({ sections, rtl, icons, modifier, run, size, width, attribution }: MenuProps) { return {rtl ? 'لم يتم العثور على نتائج.' : 'No commands found.'} {sections.map((group, i) => {i > 0 && } {group.items.map(item => run(item)}> {icons && )} )} } function proofActions(rtl = false): Section { return { heading: rtl ? 'إجراءات الطباعة' : 'Proof actions', items: [ { id: 'new', label: rtl ? 'إنشاء بروفة' : 'New proof', icon: DocumentAdd16Regular }, { id: 'duplicate', label: rtl ? 'نسخ البروفة' : 'Duplicate proof', keywords: rtl ? ['نسخة'] : ['copy'], icon: Copy16Regular }, { id: 'print', label: rtl ? 'طباعة البروفة' : 'Print proof', icon: Print16Regular, disabled: true }, ] } } function reviewActions(rtl = false): Section { return { heading: rtl ? 'المراجعة' : 'Review', items: [ { id: 'ready', label: rtl ? 'تعيين كجاهزة' : 'Mark as ready', icon: Checkmark16Regular, shortcut: '1' }, { id: 'draft', label: rtl ? 'إعادة إلى المسودة' : 'Return to draft', icon: ArrowUndo16Regular, shortcut: '2' }, { id: 'archived', label: rtl ? 'أرشفة البروفة' : 'Archive proof', icon: Archive16Regular, shortcut: '3' }, ] } } function settingChoices(heading: string, values: string[]): Section { return { heading, items: values.map(label => ({ id: heading + '/' + label, label, icon: Document16Regular })) } } function ProofCommands({ sections, inline = false, rtl = false, icons = true }: { sections: Section[]; inline?: boolean; rtl?: boolean; icons?: boolean }) { const [open, setOpen] = useState(false) const [proof, setProof] = useState({ number: 1, status: 'draft', settings: {} as Record }) const [message, setMessage] = useState('') const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function run(item: Action) { if (item.disabled) return const id = item.id if (id === 'new' || id === 'duplicate') { const number = proof.number + 1 setProof({ number, status: 'draft', settings: id === 'duplicate' ? { ...proof.settings } : {} }) setMessage(rtl ? (id === 'new' ? 'أُنشئت البروفة رقم ' : 'نُسخت البروفة إلى الرقم ') + number : id === 'new' ? 'Created proof #' + number + '.' : 'Duplicated proof #' + proof.number + ' as #' + number + '.') } else if (id.includes('/')) { const [setting, value] = id.split('/') setProof({ ...proof, settings: { ...proof.settings, [setting]: value } }) setMessage('Proof #' + proof.number + ' · ' + setting + ': ' + value) } else { setProof({ ...proof, status: id }) const translated: Record = { ready: 'جاهزة', draft: 'مسودة', archived: 'مؤرشفة' } const status = rtl ? translated[id] ?? id : id setMessage(rtl ? 'البروفة رقم ' + proof.number + ' ' + status : 'Proof #' + proof.number + ' is ' + status + '.') } setOpen(false) } function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const key = event.code.replace(/^Digit/, '') || event.key const action = sections.flatMap(section => section.items).find(item => item.shortcut === key) if (action) { event.preventDefault(); run(action) } } const menu =
return {inline ? menu : <> {menu} } {message && {message}} } export default function Example() { return () } ``` #### Size, width and attribution ```tsx import { Fragment, useState } from 'react' import { Document16Regular } from '@fluentui/react-icons' import { HStack, Select, Text, VStack } from 'wss3-forge' import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut } from 'wss3-forge/radix' type Action = { id: string; label: string; icon: typeof Document16Regular; keywords?: string[]; shortcut?: string; disabled?: boolean } type Section = { heading: string; items: Action[] } type Density = 'sm' | 'md' | 'lg' type MenuProps = { size?: Density; width?: string; attribution?: string; sections: Section[]; rtl: boolean; icons: boolean; modifier: string; run: (item: Action) => void } function Commands({ sections, rtl, icons, modifier, run, size, width, attribution }: MenuProps) { return {rtl ? 'لم يتم العثور على نتائج.' : 'No commands found.'} {sections.map((group, i) => {i > 0 && } {group.items.map(item => run(item)}> {icons && )} )} } function settingChoices(heading: string, values: string[]): Section { return { heading, items: values.map(label => ({ id: heading + '/' + label, label, icon: Document16Regular })) } } function PaletteAppearance() { const [size, setSize] = useState('md') const [width, setWidth] = useState('md') const [attribution, setAttribution] = useState('By Webba') const [paper, setPaper] = useState('') return setSize(value as Density)} /> setPaper(item.label)} /> {paper && Selected paper: {paper}} } export default function Example() { return () } ``` #### RTL ```tsx import { Fragment, useState, type KeyboardEvent } from 'react' import { Archive16Regular, ArrowUndo16Regular, Checkmark16Regular, Copy16Regular, Document16Regular, DocumentAdd16Regular, Print16Regular } from '@fluentui/react-icons' import { Button, Text, VStack } from 'wss3-forge' import { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut } from 'wss3-forge/react-aria' type Action = { id: string; label: string; icon: typeof Document16Regular; keywords?: string[]; shortcut?: string; disabled?: boolean } type Section = { heading: string; items: Action[] } type Density = 'sm' | 'md' | 'lg' type MenuProps = { size?: Density; width?: string; attribution?: string; sections: Section[]; rtl: boolean; icons: boolean; modifier: string; run: (item: Action) => void } function Commands({ sections, rtl, icons, modifier, run, size, width, attribution }: MenuProps) { const name = rtl ? 'البحث في الأوامر' : 'Search commands' return {rtl ? 'لم يتم العثور على نتائج.' : 'No commands found.'}}> {sections.map((group, i) => {i > 0 && } {group.items.map(item => run(item)}> {icons && )} )} } function proofActions(rtl = false): Section { return { heading: rtl ? 'إجراءات الطباعة' : 'Proof actions', items: [ { id: 'new', label: rtl ? 'إنشاء بروفة' : 'New proof', icon: DocumentAdd16Regular }, { id: 'duplicate', label: rtl ? 'نسخ البروفة' : 'Duplicate proof', keywords: rtl ? ['نسخة'] : ['copy'], icon: Copy16Regular }, { id: 'print', label: rtl ? 'طباعة البروفة' : 'Print proof', icon: Print16Regular, disabled: true }, ] } } function reviewActions(rtl = false): Section { return { heading: rtl ? 'المراجعة' : 'Review', items: [ { id: 'ready', label: rtl ? 'تعيين كجاهزة' : 'Mark as ready', icon: Checkmark16Regular, shortcut: '1' }, { id: 'draft', label: rtl ? 'إعادة إلى المسودة' : 'Return to draft', icon: ArrowUndo16Regular, shortcut: '2' }, { id: 'archived', label: rtl ? 'أرشفة البروفة' : 'Archive proof', icon: Archive16Regular, shortcut: '3' }, ] } } function ProofCommands({ sections, inline = false, rtl = false, icons = true }: { sections: Section[]; inline?: boolean; rtl?: boolean; icons?: boolean }) { const [open, setOpen] = useState(false) const [proof, setProof] = useState({ number: 1, status: 'draft', settings: {} as Record }) const [message, setMessage] = useState('') const modifier = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌥' : 'Alt+' function run(item: Action) { if (item.disabled) return const id = item.id if (id === 'new' || id === 'duplicate') { const number = proof.number + 1 setProof({ number, status: 'draft', settings: id === 'duplicate' ? { ...proof.settings } : {} }) setMessage(rtl ? (id === 'new' ? 'أُنشئت البروفة رقم ' : 'نُسخت البروفة إلى الرقم ') + number : id === 'new' ? 'Created proof #' + number + '.' : 'Duplicated proof #' + proof.number + ' as #' + number + '.') } else if (id.includes('/')) { const [setting, value] = id.split('/') setProof({ ...proof, settings: { ...proof.settings, [setting]: value } }) setMessage('Proof #' + proof.number + ' · ' + setting + ': ' + value) } else { setProof({ ...proof, status: id }) const translated: Record = { ready: 'جاهزة', draft: 'مسودة', archived: 'مؤرشفة' } const status = rtl ? translated[id] ?? id : id setMessage(rtl ? 'البروفة رقم ' + proof.number + ' ' + status : 'Proof #' + proof.number + ' is ' + status + '.') } setOpen(false) } function onShortcut(event: KeyboardEvent) { if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.repeat || event.nativeEvent.isComposing) return const key = event.code.replace(/^Digit/, '') || event.key const action = sections.flatMap(section => section.items).find(item => item.shortcut === key) if (action) { event.preventDefault(); run(action) } } const menu =
return {inline ? menu : <> {menu} } {message && {message}} } export default function Example() { return () } ``` ## Root package API ### Command Search for actions, run a shortcut or open a command palette. Props type: `CommandProps` Native attributes: AriaAttributes, Attributes, DOMAttributes, HTMLAttributes **Composition exports** - `CommandEmpty` (named export) - `CommandInput` (named export) - `CommandItem` (named export) - `CommandList` (named export) - `CommandSeparator` (named export) - `CommandGroup` (named export) - `CommandShortcut` (named export) - `size?` — `'sm' | 'md' | 'lg'` Default `'md'`. Options `"sm"`, `"md"`, `"lg"`. Sets the text size and row spacing. - `width?` — `CSSProperties['width']` A preset, pixel width, or CSS length. Constrained to the available space. - `attribution?` — `string` Optional credit displayed below the results, for example "AI" or "By Webba". - `ref?` — `React.LegacyRef | undefined` ### CommandEmpty Props type: `{ children?: React.ReactNode; } & Pick, HTMLDivElement>, keyof HTMLAttributes | "key"> & { ref?: React.Ref; } & { asChild?: boolean; }, keyof HTMLAttributes | "key" | "asChild"> & React.RefAttributes` Native attributes: AriaAttributes, Attributes, DOMAttributes, HTMLAttributes, RefAttributes - `ref?` — `React.LegacyRef | undefined` Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). ### CommandInput Props type: `ComponentPropsWithoutRef` Native attributes: AriaAttributes, Attributes, DOMAttributes, HTMLAttributes, InputHTMLAttributes - `ref?` — `React.LegacyRef | undefined` ### CommandItem Props type: `{ children?: React.ReactNode; } & Omit, HTMLDivElement>, keyof HTMLAttributes | "key"> & { ref?: React.Ref; } & { asChild?: boolean; }, keyof HTMLAttributes | "key" | "asChild">, "onSelect" | "disabled" | "value"> & { disabled?: boolean; onSelect?: (value: string) => void; value?: string; keywords?: string[]; forceMount?: boolean; } & React.RefAttributes` Native attributes: AriaAttributes, Attributes, DOMAttributes, HTMLAttributes, RefAttributes - `ref?` — `React.LegacyRef | undefined` Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). ### CommandList Props type: `{ children?: React.ReactNode; } & Pick, HTMLDivElement>, keyof HTMLAttributes | "key"> & { ref?: React.Ref; } & { asChild?: boolean; }, keyof HTMLAttributes | "key" | "asChild"> & { label?: string; } & React.RefAttributes` Native attributes: AriaAttributes, Attributes, DOMAttributes, HTMLAttributes, RefAttributes - `ref?` — `React.LegacyRef | undefined` Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). ### CommandSeparator Props type: `Pick, HTMLDivElement>, keyof HTMLAttributes | "key"> & { ref?: React.Ref; } & { asChild?: boolean; }, keyof HTMLAttributes | "key" | "asChild"> & { alwaysRender?: boolean; } & React.RefAttributes` Native attributes: AriaAttributes, Attributes, DOMAttributes, HTMLAttributes, RefAttributes - `ref?` — `React.LegacyRef | undefined` Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). ### CommandGroup Props type: `{ children?: React.ReactNode; } & Omit, HTMLDivElement>, keyof HTMLAttributes | "key"> & { ref?: React.Ref; } & { asChild?: boolean; }, keyof HTMLAttributes | "key" | "asChild">, "value" | "heading"> & { heading?: React.ReactNode; value?: string; forceMount?: boolean; } & React.RefAttributes` Native attributes: AriaAttributes, Attributes, DOMAttributes, HTMLAttributes, RefAttributes - `ref?` — `React.LegacyRef | undefined` Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). ### CommandShortcut Props type: `HTMLAttributes` Native attributes: AriaAttributes, DOMAttributes, HTMLAttributes - `ref?` — `React.LegacyRef | undefined` ## Related types ```ts export interface CommandProps extends ComponentPropsWithoutRef, CommandAppearanceProps {} ``` ## Optional primitive contracts - [wss3-forge/base-ui · Command contract](/ai/skill/primitive-api/Command.json) - [wss3-forge/radix · Command contract](/ai/skill/primitive-api/Command.json) - [wss3-forge/react-aria · Command contract](/ai/skill/primitive-api/Command.json)