Open History to see the last commit
1import { ArrowDownIcon, ArrowUpIcon } from "lucide-react";
2import type { ComponentProps, ReactNode } from "react";
3
4import { Command, CommandFooter, CommandInput, CommandPanel } from "./ui/command";
5import { Kbd, KbdGroup } from "./ui/kbd";
6
7type CommandPaletteContentProps = Omit<ComponentProps<typeof Command>, "children"> & {
8 readonly children: ReactNode;
9 readonly escapeLabel?: ReactNode;
10 readonly footerActionLabel?: ReactNode;
11 readonly footerTrailing?: ReactNode;
12 readonly inputAccessory?: ReactNode;
13 readonly inputProps: ComponentProps<typeof CommandInput>;
14 readonly panelClassName?: string;
15 readonly showBackHint?: boolean;
16 readonly testId?: string;
17};
18
19/**
20 * Shared command palette chrome. Palette modes provide their query behavior,
21 * results, and optional input accessory while retaining one input, panel, and
22 * keyboard-hint gutter.
23 */
24export function CommandPaletteContent({
25 children,
26 escapeLabel = "Close",
27 footerActionLabel,
28 footerTrailing,
29 inputAccessory,
30 inputProps,
31 panelClassName,
32 showBackHint,
33 testId,
34 ...commandProps
35}: CommandPaletteContentProps) {
36 return (
37 <div className="contents" data-testid={testId}>
38 <Command {...commandProps}>
39 <div className="relative">
40 <CommandInput {...inputProps} />
41 {inputAccessory}
42 </div>
43 <CommandPanel className={panelClassName}>{children}</CommandPanel>
44 <CommandFooter className="gap-3 max-sm:flex-col max-sm:items-start">
45 <div className="flex items-center gap-3">
46 <KbdGroup className="items-center gap-1.5">
47 <Kbd>
48 <ArrowUpIcon />
49 </Kbd>
50 <Kbd>
51 <ArrowDownIcon />
52 </Kbd>
53 <span>Navigate</span>
54 </KbdGroup>
55 {footerActionLabel !== undefined ? (
56 <KbdGroup className="items-center gap-1.5">
57 <Kbd>Enter</Kbd>
58 <span>{footerActionLabel}</span>
59 </KbdGroup>
60 ) : null}
61 {showBackHint ? (
62 <KbdGroup className="items-center gap-1.5">
63 <Kbd>Backspace</Kbd>
64 <span>Back</span>
65 </KbdGroup>
66 ) : null}
67 <KbdGroup className="items-center gap-1.5">
68 <Kbd>Esc</Kbd>
69 <span>{escapeLabel}</span>
70 </KbdGroup>
71 </div>
72 {footerTrailing}
73 </CommandFooter>
74 </Command>
75 </div>
76 );
77}