feat: handle and display clipboard error in useCopyable
This commit is contained in:
@@ -8,12 +8,23 @@ export const useCopyable = (
|
||||
const icon = ref("i-heroicons-clipboard-document");
|
||||
const label = ref("Copy");
|
||||
|
||||
const toast = useToast();
|
||||
|
||||
const copy = async () => {
|
||||
if (typeof valueOrCallback === "function") {
|
||||
await valueOrCallback();
|
||||
} else {
|
||||
const value = unref(valueOrCallback);
|
||||
await navigator.clipboard.writeText(value);
|
||||
try {
|
||||
if (typeof valueOrCallback === "function") {
|
||||
await valueOrCallback();
|
||||
} else {
|
||||
const value = unref(valueOrCallback);
|
||||
await navigator.clipboard.writeText(value);
|
||||
}
|
||||
} catch {
|
||||
toast.add({
|
||||
title: "Failed to copy to clipboard",
|
||||
color: "error",
|
||||
icon: "i-lucide-circle-x",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
icon.value = "i-heroicons-clipboard-document-check";
|
||||
|
||||
Reference in New Issue
Block a user