Skip to content

Commit 04f12ad

Browse files
committed
docs(examples): use useClipboard instead of navigator.clipboard
1 parent abfd0ed commit 04f12ad

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

docs/app/components/content/examples/input/InputCopyButtonExample.vue

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
<script setup lang="ts">
2-
const value = ref('npx nuxt module add ui')
3-
const copied = ref(false)
2+
import { useClipboard } from '@vueuse/core'
43
5-
function copy() {
6-
navigator.clipboard.writeText(value.value)
7-
copied.value = true
4+
const value = ref('npx nuxt module add ui')
85
9-
setTimeout(() => {
10-
copied.value = false
11-
}, 2000)
12-
}
6+
const { copy, copied } = useClipboard()
137
</script>
148

159
<template>
@@ -25,7 +19,7 @@ function copy() {
2519
size="sm"
2620
:icon="copied ? 'i-lucide-copy-check' : 'i-lucide-copy'"
2721
aria-label="Copy to clipboard"
28-
@click="copy"
22+
@click="copy(value)"
2923
/>
3024
</UTooltip>
3125
</template>

docs/app/components/content/examples/table/TableExample.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
import { h, resolveComponent } from 'vue'
33
import { upperFirst } from 'scule'
44
import type { TableColumn } from '@nuxt/ui'
5+
import { useClipboard } from '@vueuse/core'
56
67
const UButton = resolveComponent('UButton')
78
const UCheckbox = resolveComponent('UCheckbox')
89
const UBadge = resolveComponent('UBadge')
910
const UDropdownMenu = resolveComponent('UDropdownMenu')
1011
1112
const toast = useToast()
13+
const { copy } = useClipboard()
1214
1315
type Payment = {
1416
id: string
@@ -220,7 +222,7 @@ const columns: TableColumn<Payment>[] = [{
220222
}, {
221223
label: 'Copy payment ID',
222224
onSelect() {
223-
navigator.clipboard.writeText(row.original.id)
225+
copy(row.original.id)
224226
225227
toast.add({
226228
title: 'Payment ID copied to clipboard!',

docs/app/components/content/examples/table/TableRowActionsExample.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
import { h, resolveComponent } from 'vue'
33
import type { TableColumn } from '@nuxt/ui'
44
import type { Row } from '@tanstack/vue-table'
5+
import { useClipboard } from '@vueuse/core'
56
67
const UButton = resolveComponent('UButton')
78
const UBadge = resolveComponent('UBadge')
89
const UDropdownMenu = resolveComponent('UDropdownMenu')
910
1011
const toast = useToast()
12+
const { copy } = useClipboard()
1113
1214
type Payment = {
1315
id: string
@@ -119,7 +121,7 @@ function getRowItems(row: Row<Payment>) {
119121
}, {
120122
label: 'Copy payment ID',
121123
onSelect() {
122-
navigator.clipboard.writeText(row.original.id)
124+
copy(row.original.id)
123125
124126
toast.add({
125127
title: 'Payment ID copied to clipboard!',

docs/app/components/content/examples/table/TableSlotsExample.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
import type { TableColumn, DropdownMenuItem } from '@nuxt/ui'
3+
import { useClipboard } from '@vueuse/core'
34
45
interface User {
56
id: number
@@ -10,6 +11,7 @@ interface User {
1011
}
1112
1213
const toast = useToast()
14+
const { copy } = useClipboard()
1315
1416
const data = ref<User[]>([{
1517
id: 1,
@@ -71,7 +73,8 @@ function getDropdownActions(user: User): DropdownMenuItem[][] {
7173
label: 'Copy user Id',
7274
icon: 'i-lucide-copy',
7375
onSelect: () => {
74-
navigator.clipboard.writeText(user.id.toString())
76+
copy(user.id.toString())
77+
7578
toast.add({
7679
title: 'User ID copied to clipboard!',
7780
color: 'success',

playground/app/pages/components/table.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { h, resolveComponent } from 'vue'
33
import { upperFirst } from 'scule'
44
import type { TableColumn, TableRow } from '@nuxt/ui'
55
import { getPaginationRowModel } from '@tanstack/vue-table'
6+
import { useClipboard } from '@vueuse/core'
67
78
const UButton = resolveComponent('UButton')
89
const UCheckbox = resolveComponent('UCheckbox')
910
const UBadge = resolveComponent('UBadge')
1011
const UDropdownMenu = resolveComponent('UDropdownMenu')
1112
1213
const toast = useToast()
14+
const { copy } = useClipboard()
1315
1416
type Payment = {
1517
id: string
@@ -231,7 +233,7 @@ const columns: TableColumn<Payment>[] = [{
231233
}, {
232234
label: 'Copy payment ID',
233235
onSelect() {
234-
navigator.clipboard.writeText(row.original.id)
236+
copy(row.original.id)
235237
236238
toast.add({
237239
title: 'Payment ID copied to clipboard!',

0 commit comments

Comments
 (0)