βK command bar web component
- π Fast, efficient, keyboard-driven UX
- π¦ Vanilla JS, native web component that works everywhere
- π Opinionated: it doesn't do much, but what it does is very easy to use
- π Fully typed and tested
From a CDN:
import { CommandBar } from "https://esm.sh/gh/andreasphil/command-bar@<tag>";With a package manager:
pnpm install github:andreasphil/command-bar#<tag>Note
The component currently relies on styles from my CSS framework.
Import the component and define it:
import { CommandBar } from "@andreasphil/command-bar";
CommandBar.define();After that, the component is available in HTML:
<command-bar></command-bar>If a command bar is present in the DOM, you can access it globally via CommandBar.instance. This gives you methods for registering and removing commands, as well as opening the bar manually:
import { CommandBar } from "@andreasphil/command-bar";
// The method for registering commands returns a cleanup function. Use it to
// remove commands that only specific components or views need when the user
// navigates away from them.
let cleanup;
cleanup = CommandBar.instance.registerCommand({
id: "a_command",
name: "A command",
// See the Command type for all available options
});You can also open the command bar via Invoker Commands:
<command-bar id="cmd"></command-bar>
<button commandfor="cmd" command="--open">Open</button>See commandBar.d.ts.
Tools: Node β pnpm β Node's test runner β Vite
node --run dev # start the dev server
node --run test # run tests
node --run test:watch # run tests in watch mode
node --run build # typecheck, emit declarations, and bundle- Open source packages listed in package.json
- Icons by Lucide
Thanks π