command-palette
jolyui-ui/command-paletteFreeComponent
jolyui/ui publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by jolyui/ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://jolyui.dev/r/command-palette.jsonSource
1"use client";23import {4 ChevronRight,5 Clock,6 CornerDownLeft,7 Loader2,8 type LucideIcon,9 Search,10 X,11} from "lucide-react";12import { AnimatePresence, LayoutGroup, motion } from "motion/react";13import type React from "react";14import { useCallback, useEffect, useMemo, useRef, useState } from "react";15import { cn } from "@/lib/utils";1617export interface CommandItem {18 id: string;19 label: string;20 description?: string;21 icon?: LucideIcon;22 shortcut?: string[];23 keywords?: string[];24 onSelect?: () => void;25 children?: CommandGroup[]; // Support for sub-menus26 disabled?: boolean;27}2829export interface CommandGroup {30 id: string;31 heading: string;32 items: CommandItem[];33}3435export interface CommandPaletteProps {36 open?: boolean;37 onOpenChange?: (open: boolean) => void;38 groups: CommandGroup[];39 placeholder?: string;40 emptyMessage?: string;41 shortcut?: string[];42 loading?: boolean;43 showRecent?: boolean;44 maxRecent?: number;45}4647interface FlattenedItem {48 type: "group" | "item";49 groupId: string;50 groupHeading?: string;51 item?: CommandItem;52 score?: number;53 matches?: [number, number][];54}5556interface PageState {57 id: string;58 title: string;59 groups: CommandGroup[];60}6162export function CommandPalette({63 open: controlledOpen,64 onOpenChange,65 groups: initialGroups,66 placeholder = "Type a command or search...",67 emptyMessage = "No results found.",68 shortcut = ["⌘", "K"],69 loading = false,70 showRecent = true,71 maxRecent = 5,72}: CommandPaletteProps) {73 const [internalOpen, setInternalOpen] = useState(false);74 const [query, setQuery] = useState("");75 const [selectedIndex, setSelectedIndex] = useState(0);76 const [pages, setPages] = useState<PageState[]>([77 { id: "root", title: "Root", groups: initialGroups },78 ]);79 const [recentItems, setRecentItems] = useState<CommandItem[]>([]);8081 const inputRef = useRef<HTMLInputElement>(null);82 const listRef = useRef<HTMLDivElement>(null);83 const itemRefs = useRef<Map<number, HTMLDivElement>>(new Map());8485 const isOpen = controlledOpen ?? internalOpen;86 const setOpen = onOpenChange ?? setInternalOpen;87 const currentPage = pages[pages.length - 1] || pages[0];8889 // Load recent items from localStorage90 useEffect(() => {91 if (typeof window !== "undefined") {92 const saved = localStorage.getItem("jolyui-command-recent");93 if (saved) {94 try {95 setRecentItems(JSON.parse(saved));96 } catch (e) {97// … truncated
What it pulls in
npm packages
Files it writes
More from jolyui/ui
All 199 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-prompt-boxai-prompt-box | jolyui/ui | Components | Free | 4 deps | |
| animated-beamanimated-beam | jolyui/ui | Components | Free | 1 dep | |
| animated-tableanimated-table | jolyui/ui | Components | Free | 2 deps | |
| animated-theme-toggleanimated-theme-toggle | jolyui/ui | Components | Free | 2 deps | |
| animated-toastanimated-toast | jolyui/ui | Components | Free | 2 deps | |
| animated-tooltipanimated-tooltip | jolyui/ui | Components | Free | 1 dep | |
| bento-gridbento-grid | jolyui/ui | Components | Free | no deps | |
| buttonbutton | jolyui/ui | Components | Free | 3 deps |
