Handle unknown icon
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
6f9a941b18
commit
15766c4e16
@ -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"));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user