Skip to content

Commit 595f947

Browse files
committed
feat(docs): add copy to clipboard functionality for bgcolor token btns
1 parent 068ac30 commit 595f947

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

docs/components/tokens/BgColor.vue

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
<script setup>
1+
<script setup lang="ts">
2+
import LucideCopy from '~icons/lucide/copy'
3+
import { Button } from 'frappe-ui'
4+
25
defineProps({
36
data: {
47
type: Array,
@@ -10,6 +13,10 @@ const formatColor = (color) => {
1013
const arr = color.split('-')
1114
return arr.slice(2).join('-')
1215
}
16+
17+
const copyToClipboard = (txt: string) => {
18+
navigator.clipboard.writeText(txt)
19+
}
1320
</script>
1421

1522
<template>
@@ -32,11 +39,18 @@ const formatColor = (color) => {
3239
class="rounded size-20"
3340
:style="{ backgroundColor: color.value }"
3441
></div>
35-
<span
36-
class="whitespace-nowrap bg-surface-gray-2 p-1 py-1.5 text-sm rounded-sm text-center w-20"
37-
>
38-
{{ formatColor(color.name) }}
39-
</span>
42+
43+
<Button class="group relative" @click="copyToClipboard(color.name)">
44+
<span
45+
class="absolute flex items-center inset-0 justify-center gap-1 opacity-0 transition-opacity duration-150 group-hover:opacity-100"
46+
>
47+
<LucideCopy class="size-4" /> Copy
48+
</span>
49+
50+
<span class="transition-opacity duration-150 group-hover:opacity-0">
51+
{{ formatColor(color.name) }}
52+
</span>
53+
</Button>
4054
</div>
4155
</template>
4256
</div>

0 commit comments

Comments
 (0)