refactor: Update utils.tsx to include handleCopy function and dependencies

This commit is contained in:
Bram Suurd
2024-08-07 16:21:04 +02:00
parent da89f8b13c
commit c1ad36ef2a
2 changed files with 30 additions and 6 deletions

View File

@@ -1,6 +0,0 @@
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

30
src/lib/utils.tsx Normal file
View File

@@ -0,0 +1,30 @@
import { type ClassValue, clsx } from "clsx";
import { toast } from "sonner";
import { twMerge } from "tailwind-merge";
import { ClipboardCheck } from "lucide-react";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export const handleCopy = (type: string, value: any) => {
navigator.clipboard.writeText(value);
let warning = localStorage.getItem("warning");
if (warning === null) {
localStorage.setItem("warning", "1");
setTimeout(() => {
toast.error(
"be careful when copying scripts from the internet. Always remember check the source!",
{ duration: 8000 },
);
}, 500);
}
toast.success(
`copied ${type} to clipboard`, {
icon: <ClipboardCheck className="h-4 w-4" />,
}
);
};