A Notion-style command palette with fuzzy search, keyboard navigation, nested commands, and recent items. Supports global keyboard shortcuts and command grouping.
npm install @thomarket/command-paletteimport { useRef } from 'react';
import {
CommandPalette,
CommandPaletteRef,
Command
} from '@thomarket/command-palette';
function App() {
const paletteRef = useRef<CommandPaletteRef>(null);
const commands: Command[] = [
{
id: 'search',
label: 'Search',
description: 'Search across all content',
shortcut: 'Cmd+F',
category: 'navigation',
onSelect: () => console.log('Search triggered'),
},
{
id: 'settings',
label: 'Settings',
children: [
{
id: 'theme',
label: 'Theme',
children: [
{ id: 'light', label: 'Light', onSelect: () => {} },
{ id: 'dark', label: 'Dark', onSelect: () => {} },
],
},
],
},
];
const groups = [
{ id: 'navigation', label: 'Navigation' },
{ id: 'settings', label: 'Settings' },
];
return (
<>
<button onClick={() => paletteRef.current?.open()}>
Open Command Palette
</button>
<CommandPalette
ref={paletteRef}
commands={commands}
groups={groups}
globalShortcut="Cmd+K"
enableRecentItems={true}
maxRecentItems={5}
placeholder="Type a command..."
/>
</>
);
}Features:Try nested commands: select 'Settings' then 'Appearance' to see theme options. Recent items appear at the top when no search query is entered.