← Back to Home

Command Palette

A Notion-style command palette with fuzzy search, keyboard navigation, nested commands, and recent items. Supports global keyboard shortcuts and command grouping.

Installation

npm install @thomarket/command-palette

Usage Example

import { 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..."
      />
    </>
  );
}

Live Demo

Or press Cmd+K (Mac) / Ctrl+K (Windows)
Features:
  • Fuzzy search across labels, descriptions, keywords
  • Nested commands with breadcrumb navigation
  • Recent items persisted to localStorage
  • Keyboard navigation (↑↓ Enter Esc Backspace)
  • Command grouping by category
  • Platform-aware keyboard shortcuts

Try nested commands: select 'Settings' then 'Appearance' to see theme options. Recent items appear at the top when no search query is entered.