-
Notifications
You must be signed in to change notification settings - Fork 422
Expand file tree
/
Copy pathStringControlRenderer.vue
More file actions
137 lines (133 loc) · 3.74 KB
/
StringControlRenderer.vue
File metadata and controls
137 lines (133 loc) · 3.74 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<template>
<control-wrapper
v-bind="controlWrapper"
:styles="styles"
:isFocused="isFocused"
:appliedOptions="appliedOptions"
>
<v-combobox
v-if="suggestions !== undefined"
v-disabled-icon-focus
: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"
:maxlength="
appliedOptions.restrict ? control.schema.maxLength : undefined
"
:counter="
control.schema.maxLength !== undefined
? control.schema.maxLength
: undefined
"
:clearable="clearable"
:model-value="control.data"
:items="suggestions"
hide-no-data
v-bind="vuetifyProps('v-combobox')"
@update:model-value="onChange"
@focus="handleFocus"
@blur="handleBlur"
>
<template v-slot:prepend v-if="$slots.prepend">
<slot name="prepend" />
</template>
<template v-slot:append v-if="$slots.append">
<slot name="append" />
</template>
</v-combobox>
<v-text-field
v-else
v-disabled-icon-focus
: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"
:maxlength="
appliedOptions.restrict ? control.schema.maxLength : undefined
"
:counter="
control.schema.maxLength !== undefined
? control.schema.maxLength
: undefined
"
:clearable="clearable"
v-bind="vuetifyProps('v-text-field')"
@update:model-value="onChange"
@focus="handleFocus"
@blur="handleBlur"
>
<template v-slot:prepend v-if="$slots.prepend">
<slot name="prepend" />
</template>
<template v-slot:append v-if="$slots.append">
<slot name="append" />
</template>
</v-text-field>
</control-wrapper>
</template>
<script lang="ts">
import { type ControlElement } from '@jsonforms/core';
import {
rendererProps,
useJsonFormsControl,
type RendererProps,
} from '@jsonforms/vue';
import every from 'lodash/every';
import isString from 'lodash/isString';
import { defineComponent } from 'vue';
import { VCombobox, VTextField } from 'vuetify/components';
import { useVuetifyControl, determineClearValue } from '../util';
import { default as ControlWrapper } from './ControlWrapper.vue';
import { DisabledIconFocus } from './directives';
const controlRenderer = defineComponent({
name: 'string-control-renderer',
components: {
ControlWrapper,
VTextField,
VCombobox,
},
directives: {
DisabledIconFocus,
},
props: {
...rendererProps<ControlElement>(),
},
setup(props: RendererProps<ControlElement>) {
const clearValue = determineClearValue('');
return useVuetifyControl(
useJsonFormsControl(props),
(value) => value || clearValue,
300,
);
},
computed: {
suggestions(): string[] | undefined {
const suggestions = this.control.uischema.options?.suggestion;
if (
suggestions === undefined ||
!Array.isArray(suggestions) ||
!every(suggestions, isString)
) {
// check for incorrect data
return undefined;
}
return suggestions;
},
},
});
export default controlRenderer;
</script>