-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Icon): support custom component and emoji
Co-Authored-By: Benjamin Canac <canacb1@gmail.com> Co-Authored-By: Sylvain Marroufin <marroufin.sylvain@gmail.com>
- Loading branch information
1 parent
189c9f3
commit c1a7629
Showing
1 changed file
with
13 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
<template> | ||
<Icon :icon="icon" /> | ||
<Iconify v-if="icon" :icon="icon" /> | ||
<Component :is="component" v-else-if="component" /> | ||
<span v-else>{{ name }}</span> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import type { Ref } from 'vue' | ||
import type { IconifyIcon } from '@iconify/vue' | ||
import { ref, watch } from 'vue' | ||
import { Icon } from '@iconify/vue/dist/offline' | ||
import { ref, watch, computed } from 'vue' | ||
import { Icon as Iconify } from '@iconify/vue/dist/offline' | ||
import { loadIcon } from '@iconify/vue' | ||
import { useNuxtApp } from '#imports' | ||
const nuxtApp = useNuxtApp() | ||
const props = defineProps({ | ||
name: { | ||
type: [String, Object], | ||
type: String, | ||
required: true | ||
} | ||
}) | ||
const icon: Ref<IconifyIcon> = ref(null) | ||
icon.value = await loadIcon(props.name) | ||
const icon: Ref<IconifyIcon | null> = ref(null) | ||
const component = computed(() => nuxtApp.vueApp.component(props.name)) | ||
icon.value = await loadIcon(props.name).catch(_ => null) | ||
watch(() => props.name, async () => { | ||
icon.value = await loadIcon(props.name) | ||
icon.value = await loadIcon(props.name).catch(_ => null) | ||
}) | ||
</script> |