mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-20 23:11:43 +01:00
feat(clipboard): replace navigator.clipboard with vueuse useClipboard (#33)
This commit is contained in:
committed by
GitHub
parent
e1d79d7fe7
commit
4532e09ac0
@@ -1,13 +1,16 @@
|
||||
import { defineNuxtPlugin } from '#app'
|
||||
import { useClipboard } from '@vueuse/core'
|
||||
import { ClipboardPlugin } from '../types'
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
const { copy: copyToClipboard, isSupported } = useClipboard()
|
||||
|
||||
function copy (text: string, success: { title?: string, description?: string } = {}, failure: { title?: string, description?: string } = {}) {
|
||||
if (!navigator?.clipboard) {
|
||||
if (!isSupported) {
|
||||
return
|
||||
}
|
||||
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
copyToClipboard(text).then(() => {
|
||||
if (!success.title && !success.description) {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user