Command Palette Demo
spectrumui/command-palette-demoFreeComponent
Demo usage for the Command Palette component
Install it
npx shadcn@latest add https://ui.spectrumhq.in/r/command-palette-demo.jsonSource
1"use client"23import React, { useState, useEffect, useCallback } from "react"4import { CommandPalette } from "./command-palette"5import { Button } from "@/components/ui/button"67export default function CommandPaletteDemo() {8 const [isOpen, setIsOpen] = useState(false)910 const handleClose = useCallback(() => {11 setIsOpen(false)12 }, [])1314 // Listen for global command/control key trigger15 useEffect(() => {16 const handleKeyDown = (e: KeyboardEvent) => {17 if ((e.metaKey || e.ctrlKey) && e.key === "k") {18 e.preventDefault()19 setIsOpen((open) => !open)20 }21 }22 window.addEventListener("keydown", handleKeyDown)23 return () => window.removeEventListener("keydown", handleKeyDown)24 }, [])2526 return (27 <div className="flex flex-col items-center justify-center gap-4 py-8 text-center select-none">28 <p className="text-sm text-neutral-500 dark:text-neutral-400">29 Press <kbd className="bg-neutral-100 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 px-1.5 py-0.5 rounded text-xs font-mono font-medium text-neutral-800 dark:text-neutral-200">⌘K</kbd> or <kbd className="bg-neutral-100 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 px-1.5 py-0.5 rounded text-xs font-mono font-medium text-neutral-800 dark:text-neutral-200">Ctrl+K</kbd> to open the palette30 </p>3132 <Button33 variant="outline"34 onClick={() => setIsOpen(true)}35 className="rounded-xl px-5 py-2 hover:bg-neutral-50 dark:hover:bg-neutral-900 border border-neutral-200 dark:border-neutral-800 font-medium text-sm transition-colors cursor-pointer"36 >37 Open Command Palette38 </Button>3940 <CommandPalette isOpen={isOpen} onClose={handleClose} />41 </div>42 )43}
What it pulls in
Other registry items
Files it writes
More from spectrumui
All 182 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | spectrumui | Components | Free | no deps | |
| Alert demoalert-1 | spectrumui | Components | Free | 1 dep | |
| Alert 2alert-2 | spectrumui | Components | Free | no deps | |
| Alert 3alert-3 | spectrumui | Components | Free | 1 dep | |
| Alert 4alert-4 | spectrumui | Components | Free | 1 dep | |
| Animated Cardanimated-card | spectrumui | Components | Free | 1 dep · 2 files | |
| Animated Draweranimated-drawer | spectrumui | Components | Free | 4 deps | |
| Animated SVG Chartanimated-SVG-chart | spectrumui | Components | Free | 1 dep |
