refactor: split into component and use global app store

This commit is contained in:
Pihkaal
2024-10-16 02:01:39 +02:00
parent 2cd8512149
commit 80a63a320c
14 changed files with 474 additions and 386 deletions

View File

@@ -0,0 +1,25 @@
export const useCopyable = (
valueOrCallback: string | Ref<string> | (() => PromiseLike<string>),
) => {
const icon = ref("i-heroicons-clipboard-document");
const label = ref("Copy");
const copy = async () => {
if (typeof valueOrCallback === "function") {
await valueOrCallback();
} else {
const value = unref(valueOrCallback);
await navigator.clipboard.writeText(value);
}
icon.value = "i-heroicons-clipboard-document-check";
label.value = "Copied!";
setTimeout(() => {
icon.value = "i-heroicons-clipboard-document";
label.value = "Copy";
}, 3000);
};
return { icon, copy, label };
};