Quick Start

Get a fully functional command palette running in under 5 minutes.

Step 1: Basic Setup

Import the component and define your actions:

+page.svelte
<script lang="ts">
  import CommandPalette, { defineActions, createStoreMethods } from '$lib';
  // Use 'svelte-command-palette' in your project

  // Define your actions
  const actions = defineActions([
    {
      title: 'Go to Home',
      subTitle: 'Navigate to homepage',
      icon: '🏠',
      onRun: () => window.location.href = '/',
      shortcut: 'G H'
    },
    {
      title: 'Toggle Dark Mode',
      subTitle: 'Switch theme',
      icon: '🌙',
      onRun: () => document.body.classList.toggle('dark'),
      shortcut: 'T D'
    }
  ]);

  // Optional: Get store methods to control palette programmatically
  const { openPalette } = createStoreMethods();
</script>

<!-- Render CommandPalette at the root of your app -->
<CommandPalette
  commands={actions}
  placeholder="What do you want to do?"
/>

<!-- Optional: Button to open palette -->
<button on:click={openPalette}>
  Open Command Palette
</button>

Step 2: Add to Layout (Recommended)

For app-wide access, add CommandPalette to your root layout:

+layout.svelte
<!-- src/routes/+layout.svelte -->
<script>
  import CommandPalette, { defineActions } from '$lib';
  import '../app.css';

  const actions = defineActions([
    // Your global actions here
  ]);
</script>

<CommandPalette commands={actions} />
<slot />

Step 3: Try It Out

Press + K (or Ctrl + K on Windows/Linux) to open the command palette!