Files
kandev/apps/web/components/task/chat/slash-command-menu.tsx
T
João Salavisa d3058276d7 feat(i18n): localize task chat surface (#2303)
Co-authored-by: Kandev Agent <agent@kandev.dev>
2026-08-06 03:01:51 +02:00

60 lines
1.5 KiB
TypeScript

"use client";
import { IconRobot } from "@tabler/icons-react";
import type { SlashCommand } from "./slash-command-types";
import { PopupMenu, PopupMenuItem, useMenuItemRefs } from "./popup-menu";
import { useTranslation } from "react-i18next";
type SlashCommandMenuProps = {
isOpen: boolean;
position?: { x: number; y: number } | null;
clientRect?: (() => DOMRect | null) | null;
commands: SlashCommand[];
selectedIndex: number;
onSelect: (command: SlashCommand) => void;
onClose: () => void;
setSelectedIndex: (index: number) => void;
};
export function SlashCommandMenu({
isOpen,
position,
clientRect,
commands,
selectedIndex,
onSelect,
onClose,
setSelectedIndex,
}: SlashCommandMenuProps) {
const { t } = useTranslation();
const { setItemRef } = useMenuItemRefs(selectedIndex);
if (commands.length === 0) {
return null;
}
return (
<PopupMenu
isOpen={isOpen}
position={position ?? null}
clientRect={clientRect}
title={t("common:commandGroupCommands")}
selectedIndex={selectedIndex}
onClose={onClose}
>
{commands.map((command, index) => (
<PopupMenuItem
key={command.id}
icon={<IconRobot className="h-4 w-4" />}
label={command.label}
description={command.description}
isSelected={selectedIndex === index}
onClick={() => onSelect(command)}
onMouseEnter={() => setSelectedIndex(index)}
itemRef={setItemRef(index)}
/>
))}
</PopupMenu>
);
}