plugins

CommandPalette

Cmd+K-style fuzzy-search launcher.


@plyxui/plugins/command-palette exports CommandPalette — a keyboard-driven launcher you can wire to any action set.

Install

npm install @plyxui/plugins

Usage

import { CommandPalette } from "@plyxui/plugins";
import { useDisclosure } from "@plyxui/hooks";

function App() {
  const { isOpen, open, close } = useDisclosure();

  // Wire your trigger -- Cmd+K is the obvious choice
  useEffect(() => {
    const onKey = (e: KeyboardEvent) => {
      if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k") {
        e.preventDefault();
        open();
      }
    };
    window.addEventListener("keydown", onKey);
    return () => window.removeEventListener("keydown", onKey);
  }, [open]);

  return (
    <>
      <YourApp />
      <CommandPalette
        open={isOpen}
        onClose={close}
        items={[
          { id: "home",     label: "Go home",      group: "Navigate", icon: "home",     onSelect: () => navigate("/") },
          { id: "settings", label: "Open settings", group: "Navigate", icon: "settings", onSelect: () => navigate("/settings") },
          { id: "logout",   label: "Sign out",     group: "Account",  onSelect: signOut },
        ]}
      />
    </>
  );
}

Item shape

FieldRequiredWhat
idyesStable identifier (used as React key).
labelyesWhat the user sees in the list.
onSelectyesCalled when the user picks this item. The palette closes after.
groupnoLogical group header (e.g. "Navigate", "Account"). Ungrouped items appear at top.
iconnoIcon name from the @plyxui/icons registry.
keywordsnoExtra strings included in substring matching. Useful for aliases ("logout", "signout", "log out").
disablednoGreys out the item; Enter / click are ignored.

Matching

Items are ranked by:

  • Prefix match on label or any keyword: highest.
  • Substring match on label or any keyword: middle.
  • No match: filtered out.

This is deliberately simple. Sub-200-item lists feel snappy. If you have thousands of items and need fzf-style fuzzy matching, file an issue.

Keyboard

KeyAction
/ Move selection
EnterRun the selected item
EscClose the palette
Click outsideClose the palette