mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-10 18:38:22 +00:00
Implement EnumValueDisplay
This commit is contained in:
parent
6019025df2
commit
2ae4c7f5fb
1 changed files with 34 additions and 0 deletions
34
client/src/components/display/EnumValueDisplay.vue
Normal file
34
client/src/components/display/EnumValueDisplay.vue
Normal 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>
|
Loading…
Add table
Reference in a new issue