mhsf-dev/src/components/misc/TextCopyComp.tsx

35 lines
886 B
TypeScript
Raw Normal View History

2024-08-07 16:37:54 -05:00
"use client";
import { useState } from "react";
import { Button } from "../ui/button";
import toast from "react-hot-toast";
import { Check } from "lucide-react";
2024-08-22 23:44:00 -05:00
import useClipboard from "@/lib/useClipboard";
2024-08-07 16:37:54 -05:00
export function TextCopyComp() {
"use client";
2024-08-22 23:44:00 -05:00
const clipboard = useClipboard();
2024-08-07 16:37:54 -05:00
const [textCopied, setTextCopied] = useState(false);
return (
2024-08-08 18:02:46 -05:00
<code className="border p-3 rounded">
2024-08-07 16:37:54 -05:00
MHSFPV.minehut.gg{" "}
<Button
size="icon"
2024-08-08 18:02:46 -05:00
className="ml-1 h-[20px]"
2024-08-07 16:37:54 -05:00
onClick={() => {
setTextCopied(true);
2024-08-22 23:44:00 -05:00
clipboard.writeText("MHSFPV.minehut.gg");
2024-08-07 16:37:54 -05:00
toast.success("Copied!");
setTimeout(() => setTextCopied(false), 1000);
}}
>
{textCopied ? (
2024-08-08 18:02:46 -05:00
<Check size={16} className="flex items-center" />
2024-08-07 16:37:54 -05:00
) : (
<p>Copy</p>
)}
</Button>
</code>
);
}