Command

⌘K palette and filterable command lists.

Installation

npm install @aspyn-io/kit @aspyn-io/tokens
import {
  Command,
  CommandDialog,
  CommandInput,
  CommandList,
  CommandEmpty,
  CommandGroup,
  CommandItem,
  CommandShortcut,
  CommandSeparator,
} from "@aspyn-io/kit";

⌘K palette

Global search-and-act. Try the button or press ⌘K / Ctrl+K right now.

const [open, setOpen] = React.useState(false);

React.useEffect(() => {
  const down = (e: KeyboardEvent) => {
    if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
      e.preventDefault();
      setOpen((o) => !o);
    }
  };
  document.addEventListener("keydown", down);
  return () => document.removeEventListener("keydown", down);
}, []);

<CommandDialog open={open} onOpenChange={setOpen}>
  <CommandInput placeholder="Search…" />
  <CommandList>
    <CommandEmpty>No results found.</CommandEmpty>
    <CommandGroup heading="Navigate">
      <CommandItem onSelect={goToDashboard}>Dashboard</CommandItem>
    </CommandGroup>
  </CommandList>
</CommandDialog>

Inline command list

<Command className="rounded-lg border shadow-sm">
  <CommandInput placeholder="Filter technicians…" />
  <CommandList>…</CommandList>
</Command>

Notes

  • Fuzzy filtering, keyboard navigation, and grouping come from cmdk.
  • CommandDialog includes a visually-hidden title for screen readers — pass title to customize.