@@ -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"
0 commit comments