solid-command-palette
Version:
Add a command palette to your Solid.js App
98 lines (75 loc) • 2.87 kB
Markdown
<p align="center">
<br />
<img src="./public/images/branding/logo-light-horizontal-large.png" width="650" alt="Command Palette for Solid.js" />
<br />
<br />
</p>
<h1 align="center">Boost your users productivity by 10x 🚀</h1>
<br />
1. Define actions with a simple config.
1. Full keyboard support like open with <kbd>CMD</kbd> + <kbd>K</kbd>, navigate between actions using arrow keys.
1. Fuzzy search between your actions on title, subtile, keywords.
1. Bind custom keyboard shortcuts to your actions. They can be single letter, modifier combinations <kbd>Shift</kbd> + <kbd>l</kbd> or sequences <kbd>g</kbd> <kbd>p</kbd>.
1. Enable actions based on dynamic conditions.
1. Share your app state and methods to run any kind of functionality from actions.
1. Full static type safety across the board.

Try the full demo on [our documentation site](https://solid-command-palette.vercel.app/demo).
```sh
npm install solid-command-palette
npm install solid-transition-group tinykeys fuse.js
```
- [solid-transition-group](https://github.com/solidjs/solid-transition-group) (1.6KB): provides advanced animation support. It's the official recommendation from SolidJS team so you might be using it already.
- [tinykeys](https://github.com/jamiebuilds/tinykeys) (700B): provides keyboard shortcut support. You can use this in your app for all kinds of keybindings.
- [fuse.js](https://github.com/krisk/fuse) (5KB): provides fuzzy search support to find relevant actions.
```jsx
// define actions in one module say `actions.ts`
import { defineAction } from 'solid-command-palette';
const minimalAction = defineAction({
id: 'minimal',
title: 'Minimal Action',
run: () => {
console.log('ran minimal action');
},
});
const incrementCounterAction = defineAction({
id: 'increment-counter',
title: 'Increment Counter by 1',
subtitle: 'Press CMD + E to trigger this.',
shortcut: '$mod+e', // $mod = Command on Mac & Control on Windows.
run: ({ rootContext }) => {
rootContext.increment();
},
});
export const actions = {
[]: minimalAction,
[]: incrementCounterAction,
};
```
```jsx
// render inside top level Solid component
import { Root, CommandPalette } from 'solid-command-palette';
import { actions } from './actions';
import 'solid-command-palette/pkg-dist/style.css';
const App = () => {
const actionsContext = {
increment() {
console.log('increment count state by 1');
},
};
return (
<div class="my-app">
<Root actions={actions} actionsContext={actionsContext}>
<CommandPalette />
</Root>
</div>
);
};
```