CommandPalette
Search everything and go there from the keyboard. It filters as the person types, groups the results and says when nothing matches.
import { CommandPalette, useHotkey } from '@sypnia/ui/react'
Jump to a table or a setting
Press the button or Ctrl K, then type «ord».
CtrlK
Code
import { useState } from 'react';
import { Button, CommandPalette, Shortcut, toast, Toaster, useHotkey, type Command } from '@sypnia/ui/react';
// Press the button, or Ctrl K / ⌘ K. Type «ord» or «key»; arrows move, Enter chooses, Escape closes.
const go = (where: string) => () => toast(`Going to ${where}`);
const commands: Command[] = [
{ id: 'orders', label: 'orders', hint: 'Table', icon: 'table', group: 'Tables', onSelect: go('orders') },
{ id: 'customers', label: 'customers', hint: 'Table', icon: 'table', group: 'Tables', onSelect: go('customers') },
{ id: 'new-table', label: 'Create a table', icon: 'plus', group: 'Actions', keywords: 'new add', onSelect: go('a new table') },
{ id: 'keys', label: 'API keys', icon: 'key', group: 'Settings', keywords: 'token secret', onSelect: go('API keys') },
{ id: 'theme', label: 'Switch to paper', icon: 'sun', group: 'Settings', keywords: 'light theme', onSelect: go('paper') },
];
export default function Jump() {
const [open, setOpen] = useState(false);
useHotkey('k', () => setOpen(true));
return (
<>
<div className="sy-row">
<Button icon="search" onClick={() => setOpen(true)}>Search or jump to…</Button>
<Shortcut keys={['mod', 'K']} />
<CommandPalette open={open} onClose={() => setOpen(false)} commands={commands} />
</div>
<Toaster />
</>
);
} When to use it
Use it when
- Consoles with many places and actions.
- Open it with
useHotkey('k', …)and a visible search button in the top bar.
Do not use it when
- The only way to reach a place: everything must also be in the navigation.
- Searching data inside a table: use the table's own search.
For everyone
- It is a combobox with a list: the arrows move, Enter chooses and Escape closes.
- The search button says its shortcut the way the person will press it.
Props
| CommandPalette | Type | Default |
|---|---|---|
commandsrequired | Command[] | |
onCloserequired | () => void | |
openrequired | boolean | |
placeholder | string |