Skip to content

Commit 7294574

Browse files
committed
style: Remove redundant handleCopy function and improve button handling
1 parent 52ee98c commit 7294574

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

app/pages/[...package].vue

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,6 @@ function handleClick(event: MouseEvent) {
386386
router.push(route)
387387
}
388388
}
389-
390-
function handleCopy() {
391-
const selection = window.getSelection()
392-
if (selection && selection.toString().length > 0) {
393-
return
394-
}
395-
copyPkgName()
396-
}
397389
</script>
398390

399391
<template>
@@ -406,7 +398,7 @@ function handleCopy() {
406398
<div class="mb-4">
407399
<div class="flex items-baseline gap-2 mb-1.5 sm:gap-3 sm:mb-2 flex-wrap min-w-0">
408400
<h1
409-
class="font-mono text-2xl sm:text-3xl font-medium min-w-0 break-words"
401+
class="group font-mono text-2xl sm:text-3xl font-medium min-w-0 break-words"
410402
:title="pkg.name"
411403
>
412404
<NuxtLink
@@ -415,18 +407,20 @@ function handleCopy() {
415407
class="text-fg-muted hover:text-fg transition-colors duration-200"
416408
>@{{ orgName }}</NuxtLink
417409
><span v-if="orgName">/</span>
410+
<span :class="{ 'text-fg-muted': orgName }">
411+
{{ orgName ? pkg.name.replace(`@${orgName}/`, '') : pkg.name }}
412+
</span>
418413
<AnnounceTooltip :text="$t('common.copied')" :isVisible="copiedPkgName">
419-
<span
420-
@click="handleCopy"
421-
class="cursor-copy hover:text-fg transition-colors duration-200"
422-
:class="{ 'text-fg-muted': orgName }"
414+
<button
415+
type="button"
416+
@click="() => copyPkgName()"
417+
class="opacity-0 group-hover:opacity-100 focus:opacity-100 transition-opacity p-1 rounded text-fg-muted hover:text-fg hover:bg-bg-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50 align-middle ms-1"
418+
:aria-label="$t('package.copy_name')"
423419
>
424-
{{ orgName ? pkg.name.replace(`@${orgName}/`, '') : pkg.name }}
425-
</span>
420+
<span class="i-carbon:copy w-5 h-5 block" aria-hidden="true" />
421+
</button>
426422
</AnnounceTooltip>
427423
</h1>
428-
429-
<span id="copy-pkg-name" class="sr-only">{{ $t('package.copy_name') }}</span>
430424
<span
431425
v-if="displayVersion"
432426
class="inline-flex items-baseline gap-1.5 font-mono text-base sm:text-lg text-fg-muted shrink-0"

0 commit comments

Comments
 (0)