22/* eslint-disable @typescript-eslint/no-use-before-define */
33
44import { defineComponent , PropType , computed , h , inject } from ' vue' ;
5- import TextInput from ' ../text-input/TextInput.vue' ;
6- import SelectInput from ' ../select-input/SelectInput.vue' ;
7- import TextAreaInput from ' ../text-area-input/TextAreaInput.vue' ;
8- import CheckboxInput from ' ../checkbox-input/CheckboxInput.vue' ;
9- import RadioInput from ' ../radio-input/RadioInput.vue' ;
10- import NumberInput from ' ../number-input/NumberInput.vue' ;
11-
12- import { FormControl } from ' ../../core/models' ;
5+ import TextInputComponent from ' ../text-input/TextInput.vue' ;
6+ import SelectInputComponent from ' ../select-input/SelectInput.vue' ;
7+ import TextAreaInputComponent from ' ../text-area-input/TextAreaInput.vue' ;
8+ import CheckboxInputComponent from ' ../checkbox-input/CheckboxInput.vue' ;
9+ import RadioInputComponent from ' ../radio-input/RadioInput.vue' ;
10+ import NumberInputComponent from ' ../number-input/NumberInput.vue' ;
11+
12+ import {
13+ FormControl ,
14+ TextInput ,
15+ NumberInput ,
16+ EmailInput ,
17+ PasswordInput ,
18+ UrlInput ,
19+ ColorInput ,
20+ SelectInput ,
21+ RadioInput ,
22+ CheckboxInput ,
23+ TextAreaInput ,
24+ } from ' ../../core/models' ;
25+
1326import { isEmpty , entries , values , keys } from ' ../../core/utils/helpers' ;
1427import { useInputEvents } from ' ../../composables/input-events' ;
1528import { dynamicFormsSymbol } from ' ../../useApi' ;
1629
1730const components = {
18- TextInput ,
19- SelectInput ,
20- TextAreaInput ,
21- CheckboxInput ,
22- RadioInput ,
23- NumberInput ,
31+ TextInputComponent ,
32+ SelectInputComponent ,
33+ TextAreaInputComponent ,
34+ CheckboxInputComponent ,
35+ RadioInputComponent ,
36+ NumberInputComponent ,
2437};
2538
2639const props = {
2740 control: {
28- type: Object as PropType <FormControl < any > >,
41+ type: Object as PropType <FormControl >,
2942 required: true ,
3043 },
3144 submited: {
3245 type: Boolean ,
3346 required: true ,
3447 },
3548};
49+
50+ export type ControlAttribute <T > = {
51+ control: FormControl <T >;
52+ onChanged: (value : unknown ) => void ;
53+ };
54+
3655export default defineComponent ({
3756 name: ' asDynamicInput' ,
3857 components ,
@@ -45,7 +64,7 @@ export default defineComponent({
4564
4665 const attributes = computed (() => {
4766 return {
48- control: props .control ,
67+ control: props ? .control ,
4968 onChanged: valueChange ,
5069 };
5170 });
@@ -134,26 +153,64 @@ export default defineComponent({
134153 return () => {
135154 switch (props ?.control ?.type ) {
136155 case ' text' :
156+ component = h (
157+ TextInputComponent ,
158+ attributes .value as ControlAttribute <TextInput >,
159+ );
160+ break ;
137161 case ' email' :
162+ component = h (
163+ TextInputComponent ,
164+ attributes .value as ControlAttribute <EmailInput >,
165+ );
166+ break ;
138167 case ' password' :
168+ component = h (
169+ TextInputComponent ,
170+ attributes .value as ControlAttribute <PasswordInput >,
171+ );
172+ break ;
139173 case ' url' :
174+ component = h (
175+ TextInputComponent ,
176+ attributes .value as ControlAttribute <UrlInput >,
177+ );
178+ break ;
140179 case ' color' :
141- component = h (TextInput , attributes .value );
180+ component = h (
181+ TextInputComponent ,
182+ attributes .value as ControlAttribute <ColorInput >,
183+ );
142184 break ;
143185 case ' number' :
144- component = h (NumberInput , attributes .value );
186+ component = h (
187+ NumberInputComponent ,
188+ attributes .value as ControlAttribute <NumberInput >,
189+ );
145190 break ;
146191 case ' select' :
147- component = h (SelectInput , attributes .value );
192+ component = h (
193+ SelectInputComponent ,
194+ attributes .value as ControlAttribute <SelectInput >,
195+ );
148196 break ;
149197 case ' textarea' :
150- component = h (TextAreaInput , attributes .value );
198+ component = h (
199+ TextAreaInputComponent ,
200+ attributes .value as ControlAttribute <TextAreaInput >,
201+ );
151202 break ;
152203 case ' checkbox' :
153- component = h (CheckboxInput , attributes .value );
204+ component = h (
205+ CheckboxInputComponent ,
206+ attributes .value as ControlAttribute <CheckboxInput >,
207+ );
154208 break ;
155209 case ' radio' :
156- component = h (RadioInput , attributes .value );
210+ component = h (
211+ RadioInputComponent ,
212+ attributes .value as ControlAttribute <RadioInput >,
213+ );
157214 break ;
158215 case ' custom-field' :
159216 component = h (
0 commit comments