Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 27519ec

Browse files
committed
feat: added factory function typing
1 parent 1b3a962 commit 27519ec

File tree

5 files changed

+85
-81
lines changed

5 files changed

+85
-81
lines changed

dev/vue/App.vue

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<script lang="ts">
4848
import { mockAsync } from '@/core/utils/helpers';
4949
import { defineComponent, onMounted, reactive, ref } from 'vue';
50-
import { email, pattern } from '../../src';
50+
import { email, FieldTypes, pattern } from '../../src';
5151
5252
export default defineComponent({
5353
name: 'app',
@@ -86,26 +86,26 @@ export default defineComponent({
8686
fields: {
8787
name: {
8888
label: 'Name',
89-
type: 'text',
89+
type: FieldTypes.TEXT,
9090
value: 'Alvaro',
9191
},
9292
email: {
9393
label: 'Email',
94-
type: 'email',
94+
type: FieldTypes.EMAIL,
9595
validations: [emailValidator],
9696
},
9797
password: {
9898
label: 'Password',
99-
type: 'password',
99+
type: FieldTypes.PASSWORD,
100100
validations: [passwordValidator],
101101
},
102102
stock: {
103103
label: 'Stock',
104-
type: 'number',
104+
type: FieldTypes.NUMBER,
105105
},
106106
games: {
107107
label: 'Games',
108-
type: 'select',
108+
type: FieldTypes.SELECT,
109109
customClass: 'w-1/2',
110110
value: 'the-last-of-us',
111111
options: [
@@ -125,25 +125,25 @@ export default defineComponent({
125125
},
126126
console: {
127127
label: 'Console (Async Options)',
128-
type: 'select',
128+
type: FieldTypes.SELECT,
129129
customClass: 'w-1/2',
130130
options: [],
131131
},
132132
steps: {
133133
label: 'Number',
134-
type: 'number',
134+
type: FieldTypes.NUMBER,
135135
min: 5,
136136
max: 60,
137137
step: 5,
138138
value: 5,
139139
},
140140
awesomeness: {
141141
label: "Check if you're awesome",
142-
type: 'checkbox',
142+
type: FieldTypes.CHECKBOX,
143143
},
144144
character: {
145145
label: 'Select one option',
146-
type: 'radio',
146+
type: FieldTypes.RADIO,
147147
options: [
148148
{
149149
key: 'mario',
@@ -165,12 +165,12 @@ export default defineComponent({
165165
],
166166
},
167167
customField1: {
168-
type: 'custom-field',
168+
type: FieldTypes.CUSTOM,
169169
label: 'Custom Field',
170170
},
171171
color: {
172172
label: 'Color',
173-
type: 'color',
173+
type: FieldTypes.COLOR,
174174
value: '#4DBA87',
175175
},
176176
},

src/components/dynamic-form/DynamicForm.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
import { DynamicForm } from './form';
5050
import DynamicInput from '../dynamic-input/DynamicInput.vue';
5151
52-
import { FormControl, InputType } from '@/core/models';
52+
import { FieldTypes, FormControl, InputType } from '@/core/models';
5353
import { dynamicFormsSymbol } from '@/useApi';
5454
import { removeEmpty } from '@/core/utils/helpers';
5555
@@ -215,7 +215,7 @@ export default defineComponent({
215215
? controls.value.reduce((prev, curr) => {
216216
const obj = {};
217217
obj[curr.name] =
218-
curr.type === 'number'
218+
curr.type === FieldTypes.NUMBER
219219
? parseFloat(`${curr.value}`)
220220
: curr.value;
221221
return {

src/components/dynamic-input/DynamicInput.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
TextAreaInput,
2424
InputType,
2525
BindingObject,
26+
FieldTypes,
2627
} from '@/core/models';
2728
2829
import {
@@ -88,7 +89,7 @@ export default defineComponent({
8889
'dynamic-input',
8990
'form-group',
9091
{
91-
'form-group--inline': props?.control?.type === 'checkbox',
92+
'form-group--inline': props?.control?.type === FieldTypes.CHECKBOX,
9293
},
9394
{
9495
'form-group--error': showErrors.value,
@@ -185,7 +186,7 @@ export default defineComponent({
185186
186187
return () => {
187188
switch (props?.control?.type) {
188-
case 'text':
189+
case FieldTypes.TEXT:
189190
component = h(
190191
TextInputComponent,
191192
attributes.value as ControlAttribute<TextInput>,

0 commit comments

Comments
 (0)