Command palette
CommandPalette. It is copied into your app’s ui/ by qatjs add command: the code is yours to edit.
Example
Ran: nothing
import Button from './ui/button/button.qx'
import CommandPalette from './ui/command/command.qx'
export default function Example() {
let open = state(false)
let ran = state('')
return (
<Button on:click={() => (open = true)}>
Open the palette
</Button>
<p>Ran: {ran || 'nothing'}</p>
<CommandPalette
bind:open={open}
hotkey={false}
commands={[
{ id: 'orders', label: 'Open orders', group: 'Recent', hint: 'G O', run: () => (ran = 'orders') },
{ id: 'new', label: 'New order', group: 'Recent', hint: 'N', run: () => (ran = 'new') },
{
id: 'numbering',
label: 'Order numbering',
group: 'Settings',
keywords: 'invoice prefix',
run: () => (ran = 'numbering'),
},
]}
/>
)
}open stateran stateAdd it
npx qatjs add commandCommandPalette
As a custom element: <ui-command-palette>.
| Prop | Type | Attribute |
|---|---|---|
commands | Command[] | property only |
filter | (query: string) => Command[] | property only |
open | boolean | yes |
label | string | yes |
placeholder | string | yes |
empty | string | yes |
hotkey | boolean | yes |
| Event | Detail |
|---|---|
on:update:open | CustomEvent<boolean> |
Keys
| Key | Does |
|---|---|
| ⌘K, Ctrl+K | open, close |
| ↓ ↑ | move |
| Enter | run |
| Esc | close, focus back |