11# Svelte Command Palette
22
3- ### Increase your productivity exponentially. 🚀🚀
3+ #### Increase your productivity exponentially. 🚀🚀
44
55#### Get started with command-palette with 2.1Kb Minified and ~ 700B Gzipped + Minified
66
77## Demo
88
9- ![ svelte-command-palette] ( https://rohit-misc.s3.ap-south-1.amazonaws.com/svelte-command-palette.gif )
9+ 
1010
1111## Features
1212
@@ -31,17 +31,19 @@ Install svelte-command-palette with npm
3131
3232``` javascript
3333< script>
34- import CommandPalette , { defineActions } from ' svelte-command-palette'
34+ import CommandPalette , { defineActions , createStoreMethods } from ' svelte-command-palette'
3535
3636 // define actions using the defineActions API
3737
38+ const paletteMethods = createStoreMethods ();
39+
3840 const actions = defineActions ([
3941 {
40- actionId : 1 ,
42+ id : 1 ,
4143 title: " Open Svelte Command Palette on github" ,
42- subTitle: " This opens github in a new tab!" ,
44+ subTitle: ' This opens github in a new tab!",
4345 onRun: ({ action, storeProps, storeMethods }) => {
44- window .open (" https://github.com/rohitpotato/svelte-command-palette" )
46+ window.open("https://github.com/rohitpotato/svelte-command-palette"),
4547 },
4648 shortcut: "Space k"
4749 }
@@ -50,6 +52,78 @@ Install svelte-command-palette with npm
5052
5153// render your command palette at the root of your application, say _layout.svelte
5254
53- < CommandPalette {actions} / >
55+ <button on:click={() => paletteMethods.openPalette()}>Open Command Palette</button>
56+
57+ <CommandPalette {actions}>
58+
59+
60+ ```
61+
62+ ## API
63+
64+ ### Component Styling API
65+
66+ The `<CommandPalette />` component accepts the following optional properties for styling:
67+
68+ | Property | Type | Default | Description |
69+ | ---------------------------- | -------------------------------- | ---------------------- | ---------------------------------------------------------------------- |
70+ | **unstyled** | boolean | `false` | When `true`, the default styles are not applied to the modal elements. |
71+ | **placeholder** | string | `"Search for actions"` | Placeholder for the command palette input |
72+ | **overlayClass** | string \| null | `null` | Class name for the palette overlay. |
73+ | **paletteWrapperInnerClass** | string \| null | `null` | Class name for the cmd palette wrapper element. |
74+ | **inputClass** | string \| null | `null` | Class name for the cmd palette input. |
75+ | **resultsContainerClass** | string \| null | `null` | Class name for the results container. |
76+ | **resultContainerClass** | string \| null | `null` | Class name for the result item container. |
77+ | **optionSelectedClass** | string \| null | `null` | Class name for the currently selected result item. |
78+ | **titleClass** | string \| null | `null` | Class name for the result title. |
79+ | **subtitleClass** | string \| null | `null` | Class name for the result subtitle. |
80+ | **descriptionClass** | string \| null | `null` | Class name for the result description. |
81+ | **keyboardButtonClass** | string \| null | `null` | Class name for the keyboard shortcuts. |
82+ | **overlayStyle** | Record<string, string \| number> | `{}` | Style properties of the overlay. |
83+ | **paletteWrapperInnerStyle** | Record<string, string \| number> | `{}` | Style properties of the command palette wrapper element. |
84+ | **inputStyle** | Record<string, string \| number> | `{}` | Style properties of cmd palette input. |
85+ | **resultsContainerStyle** | Record<string, string \| number> | `{}` | Style properties of results container. |
86+ | **resultContainerStyle** | Record<string, string \| number> | `{}` | Style properties result item container. |
87+ | **titleStyle** | Record<string, string \| number> | `{}` | Style properties for result item title. |
88+ | **subtitleStyle** | Record<string, string \| number> | `{}` | Style properties for result item subtitle. |
89+ | **descriptionStyle** | Record<string, string \| number> | `{}` | Style properties for result item description. |
90+ | **optionSelectedStyle** | Record<string, string \| number> | `{}` | Style properties selected result item. |
91+ | **keyboardButtonStyle** | Record<string, string \| number> | `{}` | Style properties for the keyboard shortcut. |
92+
93+ ## Action API
94+
95+ ```
96+ actionId?: ActionId;
97+ canActionRun?: (args: onRunParams) => boolean;
98+ title: string;
99+ description?: string;
100+ subTitle?: string;
101+ onRun?: (args: onRunParams) => void;
102+ keywords?: Array<string>;
103+ shortcut?: string;
104+ ```
105+
106+ ## Store Methods
107+
108+ Get palette methods from `createStoreMethods`.
109+
110+ ```
111+ import { createStoreMethods } from ' svelte- command- palette`
112+
113+ const methods = createStoreMethods();
54114
115+ method.openPalette();
116+ ` ` `
117+
118+ ### API
119+
120+ ` ` `
121+ togglePalette: () => void;
122+ getAllCalledActions: () => ActionId[];
123+ storeCalledAction: (id: ActionId) => void;
124+ revertLastAction: (id: ActionId) => void;
125+ resetActionLog: () => void;
126+ openPalette: () => void;
127+ closePalette: () => void;
128+ resetPaletteStore: () => void;
55129` ` `
0 commit comments