npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zacaw99/cmdbar

v1.0.1-b

Published

A lightweight, customizable command palette component for React & Next.js

Downloads

442

Readme

CmdBar

A lightweight, customizable command palette component for React & Next.js.

Provides a beautiful, accessible command palette with full theming support, custom keybinds, and smart search filtering.

✨ Features

  • 🎯 Simple API - Pass items directly without wrapper components
  • 🎨 Full Customization - Control colors, fonts, radius, spacing
  • 🌓 Dark & Light Mode - Built-in theme presets with overrides
  • ⌨️ Custom Keybinds - Define your own keyboard shortcuts
  • 🎭 Link & Action Items - Support navigation links and callbacks
  • 🔍 Smart Search - Filter by label, group, or keywords
  • Accessible - ARIA labels, keyboard navigation
  • 🪶 No Dependencies - Only requires React 18+
  • Lightweight - ~14KB unminified, ~3.5KB gzipped

📦 Installation

npm install @zacaw99/cmdbar

🚀 Quick Start

Option 1: Next.js SSR Setup (Recommended)

For Next.js with Server and Client Components, create a Client Component wrapper:

// app/components/CommandPalette.tsx
"use client";

import { CmdBar, type CmdBarItem } from "@zacaw99/cmdbar";

const items: CmdBarItem[] = [
	{
		id: "home",
		label: "Home",
		group: "Navigation",
		href: "/",
	},
	{
		id: "logout",
		label: "Logout",
		group: "Account",
		onSelect: () => {
			// Handle logout
		},
	},
];

export function CommandPalette() {
	return <CmdBar items={items} />;
}

Then use in your Server Component layout:

// app/layout.tsx
import { CommandPalette } from "./components/CommandPalette";

export default function RootLayout({ children }) {
	return (
		<html>
			<body>
				<CommandPalette />
				{children}
			</body>
		</html>
	);
}

Benefits:

  • 🖥️ Server Component layout stays on the server
  • ⚡ Minimal client JavaScript
  • 🔒 Keep sensitive logic server-side
  • ✨ Best performance

Option 2: React Setup

For standalone React applications (Vite, Create React App, etc.):

// src/App.tsx
import { CmdBar, type CmdBarItem } from "@zacaw99/cmdbar";

const items: CmdBarItem[] = [
	{
		id: "home",
		label: "Home",
		group: "Navigation",
		href: "/",
	},
	{
		id: "settings",
		label: "Settings",
		group: "Account",
		onSelect: () => {
			// Handle settings
		},
	},
	{
		id: "logout",
		label: "Logout",
		group: "Account",
		onSelect: () => {
			// Handle logout
		},
	},
];

export default function App() {
	return (
		<div>
			<CmdBar items={items} />
			{/* Your app content */}
		</div>
	);
}

Usage with Vite:

npm install @zacaw99/cmdbar

Import in your component and pass items directly. Works everywhere React runs!


📖 API Reference

CmdBar Props

| Prop | Type | Default | Description | | --------------- | ------------------------ | -------------------------------------------- | -------------------------- | | items | CmdBarItem[] | Placeholder | Array of command items | | placeholder | string | "Type a command..." | Input placeholder text | | emptyText | string | "No commands found." | Empty state text | | closeOnSelect | boolean | true | Close after selecting item | | keybind | KeyBindConfig \| false | { key: "k", ctrlKey: true, metaKey: true } | Keyboard shortcut config | | theme | CmdBarTheme | dark | Theme configuration |

CmdBarItem

type CmdBarActionItem = {
	id: string;
	label: string;
	group?: string;
	keywords?: string[];
	icon?: ReactNode;
	disabled?: boolean;
	onSelect: () => void;
};

type CmdBarLinkItem = {
	id: string;
	label: string;
	group?: string;
	keywords?: string[];
	icon?: ReactNode;
	disabled?: boolean;
	href: string;
};

type CmdBarItem = CmdBarActionItem | CmdBarLinkItem;

🎨 Customization

Custom Keybinds

<CmdBar
	items={items}
	keybind={{
		key: "p",
		ctrlKey: true,
		shiftKey: true,
	}}
/>

Disable keybind:

<CmdBar
	items={items}
	keybind={false}
/>

Themes

Dark mode (default):

<CmdBar
	items={items}
	theme={{ mode: "dark" }}
/>

Light mode:

<CmdBar
	items={items}
	theme={{ mode: "light" }}
/>

Custom colors:

<CmdBar
	items={items}
	theme={{
		colors: {
			background: "#1e1e1e",
			text: "#ffffff",
			itemSelected: "rgba(255, 255, 255, 0.12)",
			border: "rgba(255, 255, 255, 0.1)",
		},
	}}
/>

Full theme configuration:

type CmdBarTheme = {
	mode?: "light" | "dark";
	colors?: {
		overlay?: string;
		background?: string;
		border?: string;
		text?: string;
		textSecondary?: string;
		itemHover?: string;
		itemSelected?: string;
	};
	radius?: {
		panel?: number | string;
		item?: number | string;
	};
	fonts?: {
		family?: string;
		size?: {
			input?: number | string;
			label?: number | string;
			groupLabel?: number | string;
			meta?: number | string;
		};
		weight?: { normal?: number; bold?: number };
	};
	spacing?: {
		padding?: number | string;
		gap?: number | string;
	};
};

🪝 Hooks

useCmdBar()

Access state and controls from any Client Component:

"use client";

import { useCmdBar } from "@zacaw99/cmdbar";

export function MyComponent() {
	const { isOpen, query, toggle, setQuery } = useCmdBar();

	return <button onClick={toggle}>Toggle CmdBar</button>;
}

Programmatic Control

import { cmdbar } from "@zacaw99/cmdbar";

cmdbar.open();
cmdbar.close();
cmdbar.toggle();
cmdbar.setQuery("search");
cmdbar.clearQuery();

⌨️ Keyboard Shortcuts

  • Cmd+K (Mac) / Ctrl+K (Windows/Linux) - Toggle palette
  • ↑/↓ - Navigate items
  • Enter - Select item
  • Escape - Close palette

🏗️ Architecture

CmdBar uses a store-based state management approach with a minimal client footprint. Always wrap interactive items in a Client Component wrapper to keep your layout as a Server Component.

Why?

  • Preserves server-side capabilities (metadata, database queries)
  • Minimal client JavaScript
  • Better performance
  • Clear separation of concerns

📋 Examples

With Icons

import { Home, Settings, LogOut } from "lucide-react";

const items: CmdBarItem[] = [
	{
		id: "home",
		label: "Home",
		icon: <Home size={16} />,
		href: "/",
	},
	{
		id: "settings",
		label: "Settings",
		icon: <Settings size={16} />,
		href: "/settings",
	},
];

Grouped Items

const items: CmdBarItem[] = [
	{ id: "home", label: "Home", group: "Navigation", href: "/" },
	{ id: "about", label: "About", group: "Navigation", href: "/about" },
	{ id: "new", label: "Create", group: "Actions", onSelect: () => {} },
	{ id: "settings", label: "Settings", group: "Settings", onSelect: () => {} },
];

Conditional Items

const items: CmdBarItem[] = [
	{
		id: "admin",
		label: "Admin Panel",
		href: "/admin",
		disabled: !isAdmin,
	},
];

🌐 Browser Support

  • Chrome/Edge: Latest
  • Firefox: Latest
  • Safari: Latest (14+)
  • Mobile browsers: Full support

📝 License

MIT


👤 Author

Created by zacaw99