-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathatMentionButton.tsx
More file actions
38 lines (34 loc) · 1.28 KB
/
atMentionButton.tsx
File metadata and controls
38 lines (34 loc) · 1.28 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
'use client';
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { AtSignIcon } from "lucide-react";
import { useCallback } from "react";
import { ReactEditor, useSlate } from "slate-react";
import { AtMentionInfoCard } from "./atMentionInfoCard";
// @note: we have this as a separate component to avoid having to re-render the
// entire toolbar whenever the user types (since we are using the useSlate hook
// here).
export const AtMentionButton = () => {
const editor = useSlate();
const onAddContext = useCallback(() => {
editor.insertText("@");
ReactEditor.focus(editor);
}, [editor]);
return (
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
className="w-6 h-6 text-muted-foreground hover:text-primary"
onClick={onAddContext}
>
<AtSignIcon className="w-4 h-4" />
</Button>
</TooltipTrigger>
<TooltipContent side="bottom" className="p-0 border-0 bg-transparent shadow-none">
<AtMentionInfoCard />
</TooltipContent>
</Tooltip>
);
}