-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSocialIcon.vue
70 lines (63 loc) · 1.39 KB
/
SocialIcon.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
62
63
64
65
66
67
68
69
70
<script lang="ts">
const iconMap = {
email: 'bi:envelope-fill',
github: 'bi:github',
facebook: 'bi:facebook',
telegram: 'bi:telegram',
twitter: 'bi:twitter',
linkedin: 'bi:linkedin',
reddit: 'bi:reddit',
}
export default defineComponent({
components: {
Icon,
},
props: {
href: [String],
kind: {
type: String,
default: '',
},
icon: [String],
size: {
type: Number,
required: false,
default: 32,
},
},
setup(props) {
const computedHref = computed(() => {
if (!props.href)
return ''
if (props.kind === 'email') {
if (props.href.startsWith('mailto:'))
return props.href
return `mailto:${props.href}`
}
return props.href
})
const computedIcon = computed(() => {
if (typeof props.icon === 'string' && props.icon.length > 0)
return props.icon
return iconMap[props.kind]
})
return { computedHref, computedIcon }
},
})
</script>
<template>
<a
class="text-sm text-gray-500 transition hover:text-gray-600"
target="_blank"
rel="noopener noreferrer"
:href="computedHref"
>
<span class="sr-only">{{ kind }}</span>
<Icon
:icon="computedIcon"
:width="size"
:height="size"
class="fill-current text-gray-700 dark:text-gray-200 hover:text-blue-500 dark:hover:text-blue-400"
/>
</a>
</template>