Skip to content

Commit f65280b

Browse files
committed
feat: add automatic anchor link design
1 parent 9f8f1b8 commit f65280b

2 files changed

Lines changed: 30 additions & 22 deletions

File tree

app/components/Link/Base.vue

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ const props = withDefaults(
3939
>(),
4040
{ variant: 'link' },
4141
)
42+
43+
const isLinkExternal = computed(
44+
() =>
45+
!!props.href &&
46+
typeof props.href === 'string' &&
47+
!props.href.startsWith('/') &&
48+
!props.href.startsWith('#'),
49+
)
50+
const isLinkAnchor = computed(
51+
() => !!props.href && typeof props.href === 'string' && props.href.startsWith('#'),
52+
)
4253
</script>
4354

4455
<template>
@@ -59,7 +70,9 @@ const props = withDefaults(
5970
v-else
6071
class="group inline-flex gap-x-1 items-center justify-center"
6172
:class="{
62-
'text-fg underline-offset-[0.2rem] underline decoration-1 decoration-fg/50 hover:(no-underline text-accent) focus-visible:(no-underline text-accent) transition-colors duration-200':
73+
'underline-offset-[0.2rem] underline decoration-1 decoration-fg/50':
74+
!isLinkAnchor && variant === 'link',
75+
'text-fg hover:(no-underline text-accent) focus-visible:(no-underline text-accent) transition-colors duration-200':
6376
variant === 'link',
6477
'font-mono border border-border rounded-md transition-all duration-200 aria-current:(bg-fg text-bg border-fg hover:(text-bg/50)) bg-gradient-to-t dark:bg-gradient-to-b':
6578
variant !== 'link',
@@ -73,8 +86,8 @@ const props = withDefaults(
7386
:to="to"
7487
:href="href"
7588
:aria-keyshortcuts="keyshortcut"
76-
:target="href ? '_blank' : undefined"
77-
:rel="href ? 'noopener noreferrer' : undefined"
89+
:target="isLinkExternal ? '_blank' : undefined"
90+
:rel="isLinkExternal ? 'noopener noreferrer' : undefined"
7891
>
7992
<span
8093
v-if="classicon"
@@ -83,7 +96,16 @@ const props = withDefaults(
8396
/>
8497
<slot />
8598
<!-- automatically show icon indicating external link -->
86-
<span v-if="href" class="i-carbon:launch rtl-flip w-3 h-3 opacity-50" aria-hidden="true" />
99+
<span
100+
v-if="isLinkExternal"
101+
class="i-carbon:launch rtl-flip w-3 h-3 opacity-50"
102+
aria-hidden="true"
103+
/>
104+
<span
105+
v-else-if="isLinkAnchor && variant === 'link'"
106+
class="i-carbon:link w-3 h-3 opacity-0 group-hover:opacity-100 transition-opacity duration-200"
107+
aria-hidden="true"
108+
/>
87109
<kbd
88110
v-if="keyshortcut"
89111
class="inline-flex items-center justify-center w-4 h-4 text-xs text-fg bg-bg-muted border border-border rounded no-underline"

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,16 +1011,9 @@ onKeyStroke(
10111011
id="get-started-heading"
10121012
class="group text-xs text-fg-subtle uppercase tracking-wider"
10131013
>
1014-
<a
1015-
href="#get-started"
1016-
class="inline-flex items-center gap-1.5 py-1 text-fg-subtle hover:text-fg-muted transition-colors duration-200 no-underline"
1017-
>
1014+
<LinkBase href="#get-started">
10181015
{{ $t('package.get_started.title') }}
1019-
<span
1020-
class="i-carbon:link w-3 h-3 opacity-0 group-hover:opacity-100 transition-opacity duration-200"
1021-
aria-hidden="true"
1022-
/>
1023-
</a>
1016+
</LinkBase>
10241017
</h2>
10251018
<!-- Package manager dropdown -->
10261019
<PackageManagerSelect />
@@ -1064,16 +1057,9 @@ onKeyStroke(
10641057
<section id="readme" class="area-readme min-w-0 scroll-mt-20">
10651058
<div class="flex flex-wrap items-center justify-between mb-3 px-1">
10661059
<h2 id="readme-heading" class="group text-xs text-fg-subtle uppercase tracking-wider">
1067-
<a
1068-
href="#readme"
1069-
class="inline-flex items-center gap-1.5 text-fg-subtle hover:text-fg-muted transition-colors duration-200 no-underline mt-1"
1070-
>
1060+
<LinkBase href="#readme">
10711061
{{ $t('package.readme.title') }}
1072-
<span
1073-
class="i-carbon:link w-3 h-3 opacity-0 group-hover:opacity-100 transition-opacity duration-200"
1074-
aria-hidden="true"
1075-
/>
1076-
</a>
1062+
</LinkBase>
10771063
</h2>
10781064
<ClientOnly>
10791065
<ReadmeTocDropdown

0 commit comments

Comments
 (0)