Command

A component that displays a command palette.

Installation

pnpm add @wandercom/design-system-web

Usage

37 lines
import { CommandModal } from '@wandercom/design-system-web/blocks/command';

const APP_PAGES = [
  "Home",
  "Calendar",
  "Reservations",
  "Guests",
  "Listings",
  "Invoices",
  "Earnings",
];

export function Example() {
  const [open, setOpen] = useState(false);

  return (
    <>
      <Button onClick={() => setOpen(true)}>Open Command</Button>

      <CommandModal onOpenChange={setOpen} open={open}>
        <CommandInput placeholder="Search for a page..." />

        <CommandList>
          <CommandEmpty>No results found.</CommandEmpty>

          <CommandGroup heading="App">
            {APP_PAGES.map((page) => (
              <CommandItem key={page} onSelect={() => setOpen(false)}>
                {page}
              </CommandItem>
            ))}
          </CommandGroup>
        </CommandList>
      </CommandModal>
    </>
  );
}

Examples

The default example shows a basic command dialog with a search input and a list of items.

Loading example...

Props

CommandModal

open

boolean
Controlled open state of the command dialog.

onOpenChange?

(open: boolean) => void
Callback when the open state changes.

title?

string
Title for the command dialog. Defaults to "Command Palette".

description?

string
Description for the command dialog. Defaults to "Search for a command to run".

className?

string
Additional CSS classes applied to the modal content.

enableGlobalShortcut?

boolean
Whether to enable the global shortcut to open the command dialog. Defaults to true.

shortcutKey?

string
The key to use for the global shortcut. Defaults to "k".
Command