import { Command } from "@smartacteam/ui/command";
<Command.Root> <Command.Input placeholder="Type a command or search..." /> <Command.List> <Command.Empty>No results found.</CommandEmpty> <Command.Group heading="Suggestions"> <Command.Item>Calendar</CommandItem> <Command.Item>Search Emoji</CommandItem> <Command.Item>Calculator</CommandItem> </Command.Group> <Command.Separator /> <Command.Group heading="Settings"> <Command.Item>Profile</CommandItem> <Command.Item>Billing</CommandItem> <Command.Item>Settings</CommandItem> </Command.Group> </Command.List> </Command.Root>
To show the command menu in a dialog, use the <Command.Dialog /> component.
export function CommandMenu() { const [open, setOpen] = React.useState(false) React.useEffect(() => { const down = (e: KeyboardEvent) => { if (e.key === "k" && (e.metaKey || e.ctrlKey)) { e.preventDefault() setOpen((open) => !open) } } document.addEventListener("keydown", down) return () => document.removeEventListener("keydown", down) }, []) return ( <CommandDialog open={open} onOpenChange={setOpen}> <CommandInput placeholder="Type a command or search..." /> <CommandList> <CommandEmpty>No results found.</CommandEmpty> <CommandGroup heading="Suggestions"> <CommandItem>Calendar</CommandItem> <CommandItem>Search Emoji</CommandItem> <CommandItem>Calculator</CommandItem> </CommandGroup> </CommandList> </CommandDialog> ); }