Skip to content

Commit 4cf2843

Browse files
committed
revert: re-add copy button functionalit
Ooopsie daisy
1 parent e30cb04 commit 4cf2843

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

app/components/Readme.vue

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,43 @@
22
defineProps<{
33
html: string
44
}>()
5+
6+
const { copy } = useClipboard()
7+
8+
// Combined click handler for:
9+
// 1. Intercepting npmjs.com links to route internally
10+
// 2. Copy button functionality for code blocks
11+
function handleClick(event: MouseEvent) {
12+
const target = event.target as HTMLElement | undefined
13+
if (!target) return
14+
15+
// Handle copy button clicks
16+
const copyTarget = target.closest('[data-copy]')
17+
if (copyTarget) {
18+
const wrapper = copyTarget.closest('.readme-code-block')
19+
if (!wrapper) return
20+
21+
const pre = wrapper.querySelector('pre')
22+
if (!pre?.textContent) return
23+
24+
copy(pre.textContent)
25+
26+
const icon = copyTarget.querySelector('span')
27+
if (!icon) return
28+
29+
const originalIcon = 'i-carbon:copy'
30+
const successIcon = 'i-carbon:checkmark'
31+
32+
icon.classList.remove(originalIcon)
33+
icon.classList.add(successIcon)
34+
35+
setTimeout(() => {
36+
icon.classList.remove(successIcon)
37+
icon.classList.add(originalIcon)
38+
}, 2000)
39+
return
40+
}
41+
}
542
</script>
643

744
<template>
@@ -16,6 +53,7 @@ defineProps<{
1653
'--i18n-warning': '\'' + $t('package.readme.callout.warning') + '\'',
1754
'--i18n-caution': '\'' + $t('package.readme.callout.caution') + '\'',
1855
}"
56+
@click="handleClick"
1957
/>
2058
</template>
2159

0 commit comments

Comments
 (0)