Command Palette
spectrumui/command-paletteFreeComponent
A fully customizable, smooth-animated Command Palette (Cmd+K) component
Install it
npx shadcn@latest add https://ui.spectrumhq.in/r/command-palette.jsonSource
1/**2 * Spectrum UI — CommandPalette3 *4 * Dependencies: framer-motion, lucide-react, next-themes, @/lib/utils5 *6 * @example7 * <CommandPalette isOpen={isOpen} onClose={() => setIsOpen(false)} />8 */910"use client"1112import React, { useState, useEffect, useRef, useCallback, useMemo } from "react"13import { useRouter } from "next/navigation"14import { useTheme } from "next-themes"15import { motion, AnimatePresence, useReducedMotion } from "framer-motion"16import { Search, Home, Code, HelpCircle, Laptop, Sun, Moon, Copy, Github, CornerDownLeft } from "lucide-react"17import { cn } from "@/lib/utils"1819// ─── Types ───────────────────────────────────────────────────────────────────2021export interface CommandItem {22 id: string23 title: string24 description: string25 category: "Navigation" | "Theme" | "Repository"26 shortcut?: string[]27 icon: React.ReactNode28 action: () => void29}3031export interface CommandPaletteProps {32 isOpen: boolean33 onClose: () => void34 className?: string35}3637// ─── Animation Springs ────────────────────────────────────────────────────────3839const SPRING_FLUID = {40 type: "spring",41 stiffness: 300,42 damping: 30,43} as const4445const SPRING_ENTRANCE = {46 type: "spring",47 stiffness: 260,48 damping: 20,49} as const5051// ─── Component ───────────────────────────────────────────────────────────────5253export function CommandPalette({ isOpen, onClose, className }: CommandPaletteProps) {54 const router = useRouter()55 const { theme, setTheme } = useTheme()56 const shouldReduceMotion = useReducedMotion()57 const [query, setQuery] = useState("")58 const [activeIndex, setActiveIndex] = useState(0)59 const [isCopied, setIsCopied] = useState(false)60 const inputRef = useRef<HTMLInputElement>(null)61 const itemsContainerRef = useRef<HTMLDivElement>(null)6263 // Auto-focus input when opened64 useEffect(() => {65 if (isOpen) {66 setTimeout(() => {67 inputRef.current?.focus()68 }, 50)69 setQuery("")70 setActiveIndex(0)71 }72 }, [isOpen])7374 // Copy CLI command action75 const handleCopyCommand = useCallback(() => {76// … truncated
What it pulls in
npm packages
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 |
