Skip to content

Commit 327db44

Browse files
committed
feat: add useCopyText composable
1 parent 180262e commit 327db44

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/runtime/composables/util.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { useToast } from '#imports'
2+
3+
export const useCopyText = async (text: string, label = 'Text') => {
4+
// STATE - GLOBAL
5+
const toast = useToast()
6+
7+
if (!navigator.clipboard) {
8+
// Clipboard API not available
9+
toast.value.message = 'Error: Clipboard access is not available.'
10+
toast.value.show = true
11+
return
12+
}
13+
14+
// Copy logic
15+
await navigator.clipboard.writeText(text)
16+
17+
// Show success toast
18+
toast.value.message = `${label} copied!`
19+
toast.value.show = true
20+
}

0 commit comments

Comments
 (0)