-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathCommandButtons.tsx
67 lines (60 loc) · 1.94 KB
/
CommandButtons.tsx
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
import { cn } from '@/lib/utils';
import { useRecoilValue } from 'recoil';
import { ICommand, commandsState } from '@chainlit/react-client';
import Icon from '@/components/Icon';
import { Button } from '@/components/ui/button';
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger
} from '@/components/ui/tooltip';
interface Props {
disabled?: boolean;
selectedCommandId?: string;
onCommandSelect: (command?: ICommand) => void;
}
export const CommandButtons = ({
disabled = false,
selectedCommandId,
onCommandSelect
}: Props) => {
const commands = useRecoilValue(commandsState);
const commandButtons = commands.filter((c) => !!c.button);
if (!commandButtons.length) return null;
return (
<div className="flex gap-2 ml-1 flex-wrap">
<TooltipProvider>
{commandButtons.map((command) => (
<Tooltip>
<TooltipTrigger asChild>
<Button
key={command.id}
id={`command-${command.id}`}
variant="ghost"
disabled={disabled}
className={cn(
'p-2 h-9 text-[13px] font-medium rounded-full',
selectedCommandId === command.id &&
'border-transparent text-[#08f] hover:text-[#08f] bg-[#DAEEFF] hover:bg-[#BDDCF4] dark:bg-[#2A4A6D] dark:text-[#48AAFF] dark:hover:bg-[#1A416A]'
)}
onClick={() =>
selectedCommandId === command.id
? onCommandSelect(undefined)
: onCommandSelect(command)
}
>
<Icon name={command.icon} className="!h-5 !w-5" />
{command.id}
</Button>
</TooltipTrigger>
<TooltipContent>
<p>{command.description}</p>
</TooltipContent>
</Tooltip>
))}
</TooltipProvider>
</div>
);
};
export default CommandButtons;