1
1
<script lang="ts" setup>
2
2
import { NH2 } from ' naive-ui' ;
3
-
4
- import { type Component , type PropType , useAttrs } from ' vue' ;
3
+ import { type Component , type PropType , toRefs , useAttrs } from ' vue' ;
5
4
6
5
import { useLinksStore } from ' ~/stores/settings/links.store' ;
7
6
8
- defineProps ({
7
+ const props = defineProps ({
9
8
component: {
10
9
type: Object as PropType <Component >,
11
10
required: false ,
@@ -15,13 +14,26 @@ defineProps({
15
14
type: String ,
16
15
required: false ,
17
16
},
17
+ text: {
18
+ type: Boolean ,
19
+ required: false ,
20
+ },
21
+ onClick: {
22
+ type: Function as PropType <
23
+ (e : MouseEvent , link : { url? : string ; label? : string }) => void
24
+ >,
25
+ required: false ,
26
+ },
18
27
});
19
28
29
+ const { onClick, label } = toRefs (props );
30
+
20
31
const attrs = useAttrs () as Record <keyof HTMLAnchorElement , string > | undefined ;
21
32
22
33
const { openTab } = useLinksStore ();
23
34
24
35
const onTitleClick = (e : MouseEvent ) => {
36
+ if (onClick ?.value ) return onClick .value (e , { url: attrs ?.href , label: label ?.value });
25
37
e .preventDefault ();
26
38
e .stopPropagation ();
27
39
openTab (attrs ?.href );
@@ -30,15 +42,22 @@ const onTitleClick = (e: MouseEvent) => {
30
42
31
43
<template >
32
44
<a
45
+ v-if =" $attrs?.href || onClick"
33
46
class =" anchor-link"
34
- :class =" { 'has-link': !!$attrs.href }"
35
47
:title =" label"
36
48
@click =" onTitleClick"
37
49
>
38
- <component :is =" component" class = " content " : class =" { ' hover-link': !!$attrs.href } " >
50
+ <component :is =" component" v-if = " !text && component " class =" content hover-link" >
39
51
<slot />
40
52
</component >
53
+ <slot v-else />
41
54
</a >
55
+ <template v-else >
56
+ <component :is =" component" v-if =" !text && component" class =" content" >
57
+ <slot />
58
+ </component >
59
+ <slot v-else />
60
+ </template >
42
61
</template >
43
62
44
63
<style lang="scss" scoped>
@@ -49,31 +68,34 @@ const onTitleClick = (e: MouseEvent) => {
49
68
color : inherit ;
50
69
text-decoration : none ;
51
70
outline : none ;
71
+ cursor : pointer ;
52
72
transition : color 0.3s var (--n-bezier );
53
73
will-change : color ;
54
74
55
- & :focus-visible:not (.has-link ) {
56
- text-decoration : underline ;
57
- text-underline-offset : 0.2rem ;
58
- }
59
-
60
75
.hover-link {
61
76
transition : color 0.3s var (--n-bezier );
62
77
will-change : color ;
63
78
64
79
& :active ,
65
80
& :focus-within ,
66
- & :hover {
81
+ & :hover ,
82
+ & :focus-visible {
67
83
color : var (--trakt-red );
68
84
}
69
85
}
70
86
71
- & :focus-visible .has-link .hover-link {
87
+ & :hover ,
88
+ & :focus-visible .hover-link {
72
89
color : var (--trakt-red );
73
90
}
74
91
75
92
.content {
76
93
margin : 0 ;
77
94
}
95
+
96
+ .content :not (.hover-link ) {
97
+ text-decoration : underline ;
98
+ text-underline-offset : 0.2rem ;
99
+ }
78
100
}
79
101
</style >
0 commit comments