Implement EnumValueDisplay

This commit is contained in:
Samuel Lorch 2024-08-02 11:59:00 +02:00
parent 6019025df2
commit 2ae4c7f5fb

View file

@ -0,0 +1,34 @@
<script setup lang="ts">
import { variantOf, atPath } from '~/util';
import type { Component } from 'vue';
const props = withDefaults(defineProps<{
data: object | string,
definition: { [key: string]: { path: string, component: Component | undefined } } | undefined,
}>(), {
data: '',
definition: undefined,
});
const value = computed(() => {
let variant = variantOf(props.data);
if (variant == null) {
return {};
}
if (props.definition === undefined) {
return {};
}
let thing = props.definition[variant];
if (thing == null) {
return {};
}
return { data: atPath(props.data, thing.path), component: thing.component };
});
</script>
<template>
<component :is="value.component" v-if="value.component" :data="value.data"/>
<div v-else>
{{ value.data }}
</div>
</template>