-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy.tsx
39 lines (34 loc) · 997 Bytes
/
copy.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
"use client";
import { useState } from "react";
import { cn } from "@/lib/utils";
const CopyUrlButton = () => {
const [isCopied, setIsCopied] = useState(false);
const copyUrl = async () => {
try {
await navigator.clipboard.writeText(window.location.href);
setIsCopied(true);
setTimeout(() => setIsCopied(false), 2000); // Reset the state after 2 seconds
} catch (err) {
console.error("Failed to copy URL: ", err);
}
};
return (
<button
onClick={copyUrl}
className={cn(
"rounded-md gap-2 px-3 py-2 text-sm font-medium cursor-pointer border border-slate-800 transition z-100 ",
isCopied
? "border-green-500 text-white hover:border-green-500"
: "bg-dark-1 text-gray-100 hover:border-slate-700 ",
)}
>
{isCopied ? "Link Copied!" : "Copy Call Link"}
{isCopied ? (
<i className='fa-solid fa-check text-green-500 ml-2'></i>
) : (
<i className='fa-regular fa-copy ml-2'></i>
)}
</button>
);
};
export default CopyUrlButton;