DEVELOPMENT PREVIEWIn development

Command Palette

A searchable command interface for quick access to actions and navigation.

Examples

Basic Usage

Open the command palette to search and execute commands. Try typing "file", "copy", or "theme".

Or press⌘K
Snippet
import { useState } from 'react'
import { Button, CommandPalette } from '@creo-team/buzz-ui/client'

const commands = [
	{
		id: 'new-file',
		label: 'New File',
		description: 'Create a new file',
		group: 'File',
		icon: <FileIcon className="h-4 w-4" />,
		keywords: ['create', 'document'],
		onSelect: () => console.log('Creating new file...'),
	},
	{
		id: 'open-settings',
		label: 'Open Settings',
		description: 'Configure application preferences',
		group: 'View',
		icon: <SettingsIcon className="h-4 w-4" />,
		keywords: ['preferences', 'config'],
		onSelect: () => console.log('Opening settings...'),
	},
]

export default function Example() {
	const [open, setOpen] = useState(false)

	// Open with Cmd+K
	useEffect(() => {
		const handleKeyDown = (e: KeyboardEvent) => {
			if ((e.metaKey || e.ctrlKey) && e.key === 'k') {
				e.preventDefault()
				setOpen(true)
			}
		}
		document.addEventListener('keydown', handleKeyDown)
		return () => document.removeEventListener('keydown', handleKeyDown)
	}, [])

	return (
		<>
			<Button onClick={() => setOpen(true)}>
				Open Command Palette
			</Button>
			
			<CommandPalette
				open={open}
				onOpenChange={setOpen}
				items={commands}
				placeholder="Type a command or search..."
			/>
		</>
	)

Features

  • • Fuzzy search across command labels, descriptions, and keywords
  • • Keyboard navigation with arrow keys
  • • Grouped commands for better organization
  • • Icons and descriptions for visual clarity
  • • ESC to close, Enter to execute
  • • Automatic result counting

API Reference

PropTypeDefaultDescription
open*
booleanWhether the command palette is open
onOpenChange*
(open: boolean) => voidCallback when open state changes
items*
CommandItem[]Array of command items
placeholder
string"Type a command or search..."Placeholder text for search input
emptyMessage
string"No results found."Message shown when no results match