1
1
# Svelte Command Palette
2
2
3
- ### Increase your productivity exponentially. 🚀🚀
3
+ #### Increase your productivity exponentially. 🚀🚀
4
4
5
5
#### Get started with command-palette with 2.1Kb Minified and ~ 700B Gzipped + Minified
6
6
7
7
## Demo
8
8
9
- ![ svelte-command-palette] ( https://rohit-misc.s3.ap-south-1.amazonaws.com/svelte-command-palette.gif )
9
+ 
10
10
11
11
## Features
12
12
@@ -31,17 +31,19 @@ Install svelte-command-palette with npm
31
31
32
32
``` javascript
33
33
< script>
34
- import CommandPalette , { defineActions } from ' svelte-command-palette'
34
+ import CommandPalette , { defineActions , createStoreMethods } from ' svelte-command-palette'
35
35
36
36
// define actions using the defineActions API
37
37
38
+ const paletteMethods = createStoreMethods ();
39
+
38
40
const actions = defineActions ([
39
41
{
40
- actionId : 1 ,
42
+ id : 1 ,
41
43
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!",
43
45
onRun: ({ action, storeProps, storeMethods }) => {
44
- window .open (" https://github.com/rohitpotato/svelte-command-palette" )
46
+ window.open("https://github.com/rohitpotato/svelte-command-palette"),
45
47
},
46
48
shortcut: "Space k"
47
49
}
@@ -50,6 +52,78 @@ Install svelte-command-palette with npm
50
52
51
53
// render your command palette at the root of your application, say _layout.svelte
52
54
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();
54
114
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;
55
129
` ` `
0 commit comments