-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathnuxt-icon.vue
46 lines (41 loc) · 901 Bytes
/
nuxt-icon.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
<template>
<span
class="nuxt-icon"
:class="{ 'nuxt-icon--fill': !filled }"
v-html="icon"
/>
</template>
<script setup lang="ts">
import { ref, watchEffect } from '#imports'
const props = withDefaults(defineProps<{
name: string;
filled?: boolean
}>(), { filled: false })
const icon = ref('')
watchEffect(async () => {
try {
const iconsImport = import.meta.glob('assets/icons/**/**.svg', {
as: 'raw',
eager: false
})
const rawIcon = await iconsImport[`/assets/icons/${props.name}.svg`]()
icon.value = rawIcon
} catch {
console.error(
`[nuxt-icons] Icon '${props.name}' doesn't exist in 'assets/icons'`
)
}
})
</script>
<style>
.nuxt-icon svg {
width: 1em;
height: 1em;
margin-bottom: 0.125em;
vertical-align: middle;
}
.nuxt-icon.nuxt-icon--fill,
.nuxt-icon.nuxt-icon--fill * {
fill: currentColor !important;
}
</style>