docs(examples): use useClipboard instead of navigator.clipboard

This commit is contained in:
Benjamin Canac
2025-06-18 14:16:54 +02:00
parent abfd0ede03
commit 04f12adc5b
5 changed files with 17 additions and 14 deletions

View File

@@ -1,15 +1,9 @@
<script setup lang="ts">
import { useClipboard } from '@vueuse/core'
const value = ref('npx nuxt module add ui')
const copied = ref(false)
function copy() {
navigator.clipboard.writeText(value.value)
copied.value = true
setTimeout(() => {
copied.value = false
}, 2000)
}
const { copy, copied } = useClipboard()
</script>
<template>
@@ -25,7 +19,7 @@ function copy() {
size="sm"
:icon="copied ? 'i-lucide-copy-check' : 'i-lucide-copy'"
aria-label="Copy to clipboard"
@click="copy"
@click="copy(value)"
/>
</UTooltip>
</template>

View File

@@ -2,6 +2,7 @@
import { h, resolveComponent } from 'vue'
import { upperFirst } from 'scule'
import type { TableColumn } from '@nuxt/ui'
import { useClipboard } from '@vueuse/core'
const UButton = resolveComponent('UButton')
const UCheckbox = resolveComponent('UCheckbox')
@@ -9,6 +10,7 @@ const UBadge = resolveComponent('UBadge')
const UDropdownMenu = resolveComponent('UDropdownMenu')
const toast = useToast()
const { copy } = useClipboard()
type Payment = {
id: string
@@ -220,7 +222,7 @@ const columns: TableColumn<Payment>[] = [{
}, {
label: 'Copy payment ID',
onSelect() {
navigator.clipboard.writeText(row.original.id)
copy(row.original.id)
toast.add({
title: 'Payment ID copied to clipboard!',

View File

@@ -2,12 +2,14 @@
import { h, resolveComponent } from 'vue'
import type { TableColumn } from '@nuxt/ui'
import type { Row } from '@tanstack/vue-table'
import { useClipboard } from '@vueuse/core'
const UButton = resolveComponent('UButton')
const UBadge = resolveComponent('UBadge')
const UDropdownMenu = resolveComponent('UDropdownMenu')
const toast = useToast()
const { copy } = useClipboard()
type Payment = {
id: string
@@ -119,7 +121,7 @@ function getRowItems(row: Row<Payment>) {
}, {
label: 'Copy payment ID',
onSelect() {
navigator.clipboard.writeText(row.original.id)
copy(row.original.id)
toast.add({
title: 'Payment ID copied to clipboard!',

View File

@@ -1,5 +1,6 @@
<script setup lang="ts">
import type { TableColumn, DropdownMenuItem } from '@nuxt/ui'
import { useClipboard } from '@vueuse/core'
interface User {
id: number
@@ -10,6 +11,7 @@ interface User {
}
const toast = useToast()
const { copy } = useClipboard()
const data = ref<User[]>([{
id: 1,
@@ -71,7 +73,8 @@ function getDropdownActions(user: User): DropdownMenuItem[][] {
label: 'Copy user Id',
icon: 'i-lucide-copy',
onSelect: () => {
navigator.clipboard.writeText(user.id.toString())
copy(user.id.toString())
toast.add({
title: 'User ID copied to clipboard!',
color: 'success',