@@ -3,41 +3,13 @@ import { CopyIcon, CheckIcon } from "lucide-react";
33import { Button } from "../ui/button" ;
44import { useCopyToClipboard } from "~/hooks/useCopyToClipboard" ;
55import { cn } from "~/lib/utils" ;
6- import { anchoredToastManager } from "../ui/toast" ;
6+ import {
7+ ANCHORED_COPY_TOAST_TIMEOUT_MS ,
8+ showAnchoredCopyErrorToast ,
9+ showAnchoredCopySuccessToast ,
10+ } from "../ui/anchoredCopyToast" ;
711import { Tooltip , TooltipPopup , TooltipTrigger } from "../ui/tooltip" ;
812
9- const ANCHORED_TOAST_TIMEOUT_MS = 1000 ;
10- const onCopy = ( ref : React . RefObject < HTMLButtonElement | null > ) => {
11- if ( ref . current ) {
12- anchoredToastManager . add ( {
13- data : {
14- tooltipStyle : true ,
15- } ,
16- positionerProps : {
17- anchor : ref . current ,
18- } ,
19- timeout : ANCHORED_TOAST_TIMEOUT_MS ,
20- title : "Copied!" ,
21- } ) ;
22- }
23- } ;
24-
25- const onCopyError = ( ref : React . RefObject < HTMLButtonElement | null > , error : Error ) => {
26- if ( ref . current ) {
27- anchoredToastManager . add ( {
28- data : {
29- tooltipStyle : true ,
30- } ,
31- positionerProps : {
32- anchor : ref . current ,
33- } ,
34- timeout : ANCHORED_TOAST_TIMEOUT_MS ,
35- title : "Failed to copy" ,
36- description : error . message ,
37- } ) ;
38- }
39- } ;
40-
4113export const MessageCopyButton = memo ( function MessageCopyButton ( {
4214 text,
4315 size = "xs" ,
@@ -51,9 +23,9 @@ export const MessageCopyButton = memo(function MessageCopyButton({
5123} ) {
5224 const ref = useRef < HTMLButtonElement > ( null ) ;
5325 const { copyToClipboard, isCopied } = useCopyToClipboard < void > ( {
54- onCopy : ( ) => onCopy ( ref ) ,
55- onError : ( error : Error ) => onCopyError ( ref , error ) ,
56- timeout : ANCHORED_TOAST_TIMEOUT_MS ,
26+ onCopy : ( ) => showAnchoredCopySuccessToast ( ref ) ,
27+ onError : ( error : Error ) => showAnchoredCopyErrorToast ( ref , error ) ,
28+ timeout : ANCHORED_COPY_TOAST_TIMEOUT_MS ,
5729 } ) ;
5830
5931 return (
0 commit comments