Open History to see the last commit
1import { type ResolvedKeybindingsConfig } from "@t3tools/contracts";
2import { ChevronRightIcon } from "lucide-react";
3import { shortcutLabelForCommand } from "../keybindings";
4import {
5 type CommandPaletteActionItem,
6 type CommandPaletteGroup,
7 type CommandPaletteSubmenuItem,
8} from "./CommandPalette.logic";
9import {
10 CommandCollection,
11 CommandGroup,
12 CommandGroupLabel,
13 CommandItem,
14 CommandList,
15 CommandShortcut,
16} from "./ui/command";
17
18interface CommandPaletteResultsProps {
19 emptyStateMessage?: string;
20 groups: ReadonlyArray<CommandPaletteGroup>;
21 isActionsOnly: boolean;
22 keybindings: ResolvedKeybindingsConfig;
23 onExecuteItem: (item: CommandPaletteActionItem | CommandPaletteSubmenuItem) => void;
24}
25
26export function CommandPaletteResults(props: CommandPaletteResultsProps) {
27 if (props.groups.length === 0) {
28 return (
29 <div className="py-10 text-center text-sm text-muted-foreground">
30 {props.emptyStateMessage ??
31 (props.isActionsOnly
32 ? "No matching actions."
33 : "No matching commands, projects, or threads.")}
34 </div>
35 );
36 }
37
38 return (
39 <CommandList>
40 {props.groups.map((group) => (
41 <CommandGroup items={group.items} key={group.value}>
42 <CommandGroupLabel>{group.label}</CommandGroupLabel>
43 <CommandCollection>
44 {(item) => (
45 <CommandPaletteResultRow
46 item={item}
47 key={item.value}
48 keybindings={props.keybindings}
49 onExecuteItem={props.onExecuteItem}
50 />
51 )}
52 </CommandCollection>
53 </CommandGroup>
54 ))}
55 </CommandList>
56 );
57}
58
59function CommandPaletteResultRow(props: {
60 item: CommandPaletteActionItem | CommandPaletteSubmenuItem;
61 keybindings: ResolvedKeybindingsConfig;
62 onExecuteItem: (item: CommandPaletteActionItem | CommandPaletteSubmenuItem) => void;
63}) {
64 const shortcutLabel = props.item.shortcutCommand
65 ? shortcutLabelForCommand(props.keybindings, props.item.shortcutCommand)
66 : null;
67
68 return (
69 <CommandItem
70 value={props.item.value}
71 className="cursor-pointer gap-2"
72 onMouseDown={(event) => {
73 event.preventDefault();
74 }}
75 onClick={() => {
76 props.onExecuteItem(props.item);
77 }}
78 >
79 {props.item.icon}
80 {props.item.description ? (
81 <span className="flex min-w-0 flex-1 flex-col">
82 <span className="truncate text-sm text-foreground">{props.item.title}</span>
83 <span className="truncate text-muted-foreground/70 text-xs">
84 {props.item.description}
85 </span>
86 </span>
87 ) : (
88 <span className="flex min-w-0 items-center gap-1.5 truncate text-sm text-foreground">
89 <span className="truncate">{props.item.title}</span>
90 </span>
91 )}
92 {props.item.timestamp ? (
93 <span className="min-w-12 shrink-0 text-right text-[10px] tabular-nums text-muted-foreground/70">
94 {props.item.timestamp}
95 </span>
96 ) : null}
97 {shortcutLabel ? <CommandShortcut>{shortcutLabel}</CommandShortcut> : null}
98 {props.item.kind === "submenu" ? (
99 <ChevronRightIcon className="ml-auto size-4 shrink-0 text-muted-foreground/50" />
100 ) : null}
101 </CommandItem>
102 );
103}