Handle unknown icon

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-10-10 16:45:45 +02:00
parent 6f9a941b18
commit 15766c4e16
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -1,5 +1,9 @@
<template> <template>
<component :is="componentInstance" :size="realSize" /> <component
:is="componentInstance"
v-if="componentInstance"
:size="realSize"
/>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, defineAsyncComponent } from "vue"; import { computed, defineAsyncComponent } from "vue";
@ -234,6 +238,8 @@ const icons: Record<string, () => Promise<any>> = {
import(`../../../node_modules/vue-material-design-icons/CheckCircle.vue`), import(`../../../node_modules/vue-material-design-icons/CheckCircle.vue`),
ViewList: () => ViewList: () =>
import(`../../../node_modules/vue-material-design-icons/ViewList.vue`), import(`../../../node_modules/vue-material-design-icons/ViewList.vue`),
SmokingOff: () =>
import(`../../../node_modules/vue-material-design-icons/SmokingOff.vue`),
}; };
const props = withDefaults( const props = withDefaults(
@ -247,9 +253,14 @@ const props = withDefaults(
const name = computed(() => toPascalCase(props.icon[1])); const name = computed(() => toPascalCase(props.icon[1]));
const componentInstance = computed(() => const componentInstance = computed(() => {
defineAsyncComponent(icons[name.value]) if (Object.prototype.hasOwnProperty.call(icons, name.value)) {
); return defineAsyncComponent(icons[name.value]);
} else {
console.error("Icon is undefined", name.value);
return undefined;
}
});
const realSize = computed(() => Number.parseInt(props.size ?? "18")); const realSize = computed(() => Number.parseInt(props.size ?? "18"));