-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathCommandPopoverButton.tsx
95 lines (88 loc) · 2.48 KB
/
CommandPopoverButton.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
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
import {
Popover,
PopoverContent,
PopoverTrigger
} from '@radix-ui/react-popover';
import { useRecoilValue } from 'recoil';
import { ICommand, commandsState } from '@chainlit/react-client';
import Icon from '@/components/Icon';
import { ToolBox } from '@/components/icons/ToolBox';
import { Button } from '@/components/ui/button';
import {
Command,
CommandGroup,
CommandItem,
CommandList
} from '@/components/ui/command';
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger
} from '@/components/ui/tooltip';
interface Props {
disabled?: boolean;
onCommandSelect: (command: ICommand) => void;
}
export const CommandPopoverButton = ({
disabled = false,
onCommandSelect
}: Props) => {
const commands = useRecoilValue(commandsState);
if (!commands.length) return null;
return (
<Popover>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<PopoverTrigger asChild>
<Button
id="command-button"
variant="ghost"
size="icon"
className="hover:bg-muted"
disabled={disabled}
>
<ToolBox className="!size-6" />
</Button>
</PopoverTrigger>
</TooltipTrigger>
<TooltipContent>
<p>Commands</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
<PopoverContent
align="start"
sideOffset={12}
className="focus:outline-none"
>
<Command className="rounded-lg border shadow-md">
<CommandList>
<CommandGroup>
{commands.map((command) => (
<CommandItem
key={command.id}
onSelect={() => onCommandSelect(command)}
className="command-item cursor-pointer flex items-center space-x-2 p-2"
>
<Icon
name={command.icon}
className="!size-5 text-muted-foreground"
/>
<div>
<div className="font-medium">{command.id}</div>
<div className="text-sm text-muted-foreground">
{command.description}
</div>
</div>
</CommandItem>
))}
</CommandGroup>
</CommandList>
</Command>
</PopoverContent>
</Popover>
);
};
export default CommandPopoverButton;