-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathLink.vue
61 lines (56 loc) · 1.39 KB
/
Link.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<template>
<component
:is="tag"
:class="rootClasses"
v-bind="attrs"
>
<slot />
<IconNorthEast v-if="href" class="ml-[4px] self-center" />
</component>
</template>
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator'
@Component
export default class Link extends Vue {
// Equivalent to `to` of `<NuxtLink/>`
@Prop({ default: null }) readonly to: object | null | undefined
@Prop(String) readonly href: string | undefined
@Prop({ default: false }) readonly nofollow!: boolean
@Prop({ default: false }) readonly noreferrer!: boolean
@Prop({ default: false }) readonly ugc!: boolean
@Prop({ default: false }) readonly isInline!: boolean
get attrs() {
if (this.to) {
return { to: this.to }
}
if (this.href) {
const rel = ['noopener']
if (this.nofollow) { rel.push('nofollow') }
if (this.noreferrer) { rel.push('noreferrer') }
if (this.ugc) { rel.push('ugc') }
return {
href: this.href,
target: '_blank',
rel: rel.join(' '),
}
}
return {}
}
get tag() {
if (this.to) return 'NuxtLink'
return 'a'
}
get rootClasses() {
return [
this.isInline ? 'inline-flex' : 'flex',
'flex-row',
'text-[16px]',
'font-normal',
'text-like-green',
'leading-[22px]',
'underline',
'cursor-pointer',
]
}
}
</script>