import { type ResolvedKeybindingsConfig } from "@t3tools/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"; import { cn } from "~/lib/utils"; interface CommandPaletteResultsProps { emptyStateMessage?: string; groups: ReadonlyArray; highlightedItemValue?: string | null; isActionsOnly: boolean; keybindings: ResolvedKeybindingsConfig; onExecuteItem: (item: CommandPaletteActionItem | CommandPaletteSubmenuItem) => void; } export function CommandPaletteResults(props: CommandPaletteResultsProps) { if (props.groups.length === 0) { return (
{props.emptyStateMessage ?? (props.isActionsOnly ? "No matching actions." : "No matching commands, projects, or threads.")}
); } return ( {props.groups.map((group) => ( {group.label} {(item) => item.disabled ? ( ) : ( ) } ))} ); } function DisabledCommandPaletteResultRow(props: { item: CommandPaletteActionItem | CommandPaletteSubmenuItem; }) { return (
{props.item.icon} {props.item.description ? ( {props.item.titleLeadingContent} {props.item.title} {props.item.description} ) : ( {props.item.titleLeadingContent} {props.item.title} )} {props.item.titleTrailingContent}
); } function CommandPaletteResultRow(props: { item: CommandPaletteActionItem | CommandPaletteSubmenuItem; isActive: boolean; keybindings: ResolvedKeybindingsConfig; onExecuteItem: (item: CommandPaletteActionItem | CommandPaletteSubmenuItem) => void; }) { const shortcutLabel = props.item.shortcutCommand ? shortcutLabelForCommand(props.keybindings, props.item.shortcutCommand) : null; return ( { event.preventDefault(); }} onClick={() => { props.onExecuteItem(props.item); }} > {props.item.icon} {props.item.description ? ( {props.item.titleLeadingContent} {props.item.title} {props.item.description} ) : ( {props.item.titleLeadingContent} {props.item.title} )} {props.item.titleTrailingContent} {props.item.timestamp ? ( {props.item.timestamp} ) : null} {shortcutLabel ? {shortcutLabel} : null} {props.item.kind === "submenu" ? ( ) : null} ); }