-
Notifications
You must be signed in to change notification settings - Fork 391
/
Copy pathIntegerControlRenderer.vue
74 lines (70 loc) · 1.98 KB
/
IntegerControlRenderer.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
68
69
70
71
72
73
74
<template>
<control-wrapper
v-bind="controlWrapper"
:styles="styles"
:isFocused="isFocused"
:appliedOptions="appliedOptions"
>
<v-number-input
v-disabled-icon-focus
:step="step"
:id="control.id + '-input'"
:class="styles.control.input"
:disabled="!control.enabled"
:autofocus="appliedOptions.focus"
:placeholder="appliedOptions.placeholder"
:label="computedLabel"
:hint="control.description"
:persistent-hint="persistentHint()"
:required="control.required"
:error-messages="control.errors"
:model-value="control.data"
:clearable="control.enabled"
v-bind="vuetifyProps('v-text-field')"
@update:model-value="onChange"
@focus="handleFocus"
@blur="handleBlur"
></v-number-input>
</control-wrapper>
</template>
<script lang="ts">
import { type ControlElement } from '@jsonforms/core';
import {
rendererProps,
useJsonFormsControl,
type RendererProps,
} from '@jsonforms/vue';
import { defineComponent } from 'vue';
import { VNumberInput } from 'vuetify/components/VNumberInput';
import { useVuetifyControl } from '../util';
import { default as ControlWrapper } from './ControlWrapper.vue';
import { DisabledIconFocus } from './directives';
const controlRenderer = defineComponent({
name: 'integer-control-renderer',
components: {
ControlWrapper,
VNumberInput,
},
directives: {
DisabledIconFocus,
},
props: {
...rendererProps<ControlElement>(),
},
setup(props: RendererProps<ControlElement>) {
const adaptValue = (value: any) => (value === null ? undefined : value);
const input = useVuetifyControl(useJsonFormsControl(props), adaptValue);
return { ...input, adaptValue };
},
computed: {
step(): number {
const options: any = this.appliedOptions;
return options.step ?? 1;
},
allowUnsafeInteger(): boolean {
return this.appliedOptions.allowUnsafeInteger;
},
},
});
export default controlRenderer;
</script>