Home

Awesome

Svelte Command Palette

Increase your productivity exponentially. 🚀🚀

Get started with command-palette with 2.1Kb Minified and ~700B Gzipped + Minified

Demo

svelte-command-palette

Features

and more

Installation

Install svelte-command-palette with npm

  npm install svelte-command-palette

Usage/Examples

<script>
    import CommandPalette, { defineActions, createStoreMethods } from 'svelte-command-palette'

    // define actions using the defineActions API

    const paletteMethods = createStoreMethods();

    const actions = defineActions([
        {
            title: "Open Svelte Command Palette on github",
            subTitle: "This opens github in a new tab!",
            onRun: ({ action, storeProps, storeMethods }) => {
                window.open("https://github.com/rohitpotato/svelte-command-palette")
            },
            shortcut: "Space k"
        }
    ])
</script>

// render your command palette at the root of your application, say _layout.svelte

<button on:click={() => paletteMethods.openPalette()}>Open Command Palette</button>

<CommandPalette commands={actions}>


API

Component Styling API

The <CommandPalette /> component accepts the following optional properties for styling:

PropertyTypeDefaultDescription
unstyledbooleanfalseWhen true, the default styles are not applied to the modal elements.
placeholderstring"Search for actions"Placeholder for the command palette input
overlayClassstring | nullnullClass name for the palette overlay.
paletteWrapperInnerClassstring | nullnullClass name for the cmd palette wrapper element.
inputClassstring | nullnullClass name for the cmd palette input.
resultsContainerClassstring | nullnullClass name for the results container.
resultContainerClassstring | nullnullClass name for the result item container.
optionSelectedClassstring | nullnullClass name for the currently selected result item.
titleClassstring | nullnullClass name for the result title.
subtitleClassstring | nullnullClass name for the result subtitle.
descriptionClassstring | nullnullClass name for the result description.
keyboardButtonClassstring | nullnullClass name for the keyboard shortcuts.
overlayStyleRecord<string, string | number>{}Style properties of the overlay.
paletteWrapperInnerStyleRecord<string, string | number>{}Style properties of the command palette wrapper element.
inputStyleRecord<string, string | number>{}Style properties of cmd palette input.
resultsContainerStyleRecord<string, string | number>{}Style properties of results container.
resultContainerStyleRecord<string, string | number>{}Style properties result item container.
titleStyleRecord<string, string | number>{}Style properties for result item title.
subtitleStyleRecord<string, string | number>{}Style properties for result item subtitle.
descriptionStyleRecord<string, string | number>{}Style properties for result item description.
optionSelectedStyleRecord<string, string | number>{}Style properties selected result item.
keyboardButtonStyleRecord<string, string | number>{}Style properties for the keyboard shortcut.

Action API

	actionId?: ActionId;
	canActionRun?: (args: onRunParams) => boolean;
	title: string;
	description?: string;
	subTitle?: string;
	onRun?: (args: onRunParams) => void;
	keywords?: Array<string>;
	shortcut?: string;

Store Methods

Get palette methods from createStoreMethods.

import { createStoreMethods } from 'svelte-command-palette`

const methods = createStoreMethods();

method.openPalette();

API

    togglePalette: () => void;
    getAllCalledActions: () => ActionId[];
    storeCalledAction: (id: ActionId) => void;
    revertLastAction: (id: ActionId) => void;
    resetActionLog: () => void;
    openPalette: () => void;
    closePalette: () => void;
    resetPaletteStore: () => void;