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