import * as React from "react"; import { Command as CommandPrimitive } from "cmdk"; import { cn } from "../../utils/cn"; import { useControllableState } from "../../hooks"; export interface CommandPaletteProps { open?: boolean; defaultOpen?: boolean; onOpenChange?: (open: boolean) => void; /** When set (e.g. "k"), pressing Cmd/Ctrl+ toggles the palette open — the standard "⌘K" pattern. */ shortcut?: string; label?: string; children: React.ReactNode; } /** * CommandPalette — a searchable, keyboard-first command/navigation * overlay, built on `cmdk` (no accessible Radix primitive exists for * this pattern, the same situation as Combobox). The public API is * Labanaat's own — CommandPalette/CommandInput/CommandList/etc. — cmdk * is an internal implementation detail, same as Radix elsewhere in the * library. */ export function CommandPalette({ open, defaultOpen = false, onOpenChange, shortcut, label = "Command palette", children }: CommandPaletteProps) { const [isOpen, setIsOpen] = useControllableState({ value: open, defaultValue: defaultOpen, onChange: onOpenChange }); React.useEffect(() => { if (!shortcut) return; function onKeyDown(e: KeyboardEvent) { if (e.key.toLowerCase() === shortcut!.toLowerCase() && (e.metaKey || e.ctrlKey)) { e.preventDefault(); setIsOpen(!isOpen); } if (e.key === "Escape") setIsOpen(false); } document.addEventListener("keydown", onKeyDown); return () => document.removeEventListener("keydown", onKeyDown); }, [shortcut, isOpen, setIsOpen]); if (!isOpen) return null; return (
); } export const CommandInput = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => (
)); CommandInput.displayName = "CommandInput"; export const CommandList = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )); CommandList.displayName = "CommandList"; export const CommandEmpty = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >((props, ref) => ( )); CommandEmpty.displayName = "CommandEmpty"; export const CommandGroup = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )); CommandGroup.displayName = "CommandGroup"; export const CommandItem = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )); CommandItem.displayName = "CommandItem"; export const CommandSeparator = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )); CommandSeparator.displayName = "CommandSeparator"; export function CommandShortcut({ className, ...props }: React.HTMLAttributes) { return ( ); }