-
Notifications
You must be signed in to change notification settings - Fork 373
/
EnumControlRenderer.vue
67 lines (63 loc) · 1.66 KB
/
EnumControlRenderer.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<template>
<control-wrapper
v-bind="controlWrapper"
:styles="styles"
:is-focused="isFocused"
:applied-options="appliedOptions"
>
<select
:id="control.id + '-select'"
:class="styles.control.select"
:value="control.data"
:disabled="!control.enabled"
:autofocus="appliedOptions.focus"
@change="onChange"
@focus="isFocused = true"
@blur="isFocused = false"
>
<option key="empty" value="" :class="styles.control.option" />
<option
v-for="optionElement in control.options"
:key="optionElement.value"
:value="optionElement.value"
:label="optionElement.label"
:class="styles.control.option"
></option>
</select>
</control-wrapper>
</template>
<script lang="ts">
import {
ControlElement,
JsonFormsRendererRegistryEntry,
rankWith,
isEnumControl,
} from '@jsonforms/core';
import { defineComponent } from 'vue';
import {
rendererProps,
useJsonFormsEnumControl,
RendererProps,
} from '../../config/jsonforms';
import { default as ControlWrapper } from './ControlWrapper.vue';
import { useVanillaControl } from '../util';
const controlRenderer = defineComponent({
name: 'EnumControlRenderer',
components: {
ControlWrapper,
},
props: {
...rendererProps<ControlElement>(),
},
setup(props: RendererProps<ControlElement>) {
return useVanillaControl(useJsonFormsEnumControl(props), (target) =>
target.selectedIndex === 0 ? undefined : target.value
);
},
});
export default controlRenderer;
export const entry: JsonFormsRendererRegistryEntry = {
renderer: controlRenderer,
tester: rankWith(2, isEnumControl),
};
</script>