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

Commit d38c29a

Browse files
committed
feat(demo): update javascript dev app
2 parents 1c31da3 + 45cec79 commit d38c29a

File tree

17 files changed

+210
-66
lines changed

17 files changed

+210
-66
lines changed

dev/typescript/App.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,6 @@ export default defineComponent({
203203
}
204204
205205
onMounted(async () => {
206-
setTimeout(() => {
207-
form.fields.email.value = 'alvaro.saburido@gmail.com';
208-
}, 2000);
209-
210206
try {
211207
const consoleOptions = await mockAsync(true, 4000, [
212208
{

dev/typescript/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import './styles/main.scss';
55

66
import { createDynamicForms } from '../../src';
77

8-
// import { createDynamicForms } from '../../dist/as-dynamic-forms.esm';
9-
8+
/* import { createDynamicForms } from '../../dist/as-dynamic-forms.esm';
9+
*/
1010
const VueDynamicForms = createDynamicForms({
1111
autoValidate: true,
1212
form: {

dev/vue/App.vue

Lines changed: 160 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,25 @@
99
@submited="handleSubmit"
1010
@changed="valueChanged"
1111
@error="handleError"
12-
/>
12+
>
13+
<template
14+
v-slot:customField1="{ control, onChange, onFocus, onBlur }"
15+
>
16+
<div class="avocado-field">
17+
<input
18+
v-if="control"
19+
class="form-control"
20+
v-model="control.value"
21+
:type="control.type"
22+
:name="control.name"
23+
@change="onChange"
24+
@focus="onFocus"
25+
@blur="onBlur"
26+
/>
27+
<i>🥑</i>
28+
</div>
29+
</template>
30+
</dynamic-form>
1331
<button
1432
class="btn bg-teal-500 text-white hover:bg-teal-700 mt-4"
1533
submit="true"
@@ -27,49 +45,69 @@
2745
</template>
2846

2947
<script lang="ts">
30-
import { defineComponent, reactive, ref } from 'vue';
31-
import {
32-
TextInput,
33-
SelectInput,
34-
EmailInput,
35-
FormValidation,
36-
PasswordInput,
37-
email,
38-
pattern,
39-
TextAreaInput,
40-
ColorInput,
41-
} from '../../src';
48+
import { mockAsync } from '@/core/utils/helpers';
49+
import { defineComponent, onMounted, reactive, ref } from 'vue';
50+
import { email, pattern } from '../../src';
4251
4352
export default defineComponent({
4453
name: 'app',
4554
setup() {
4655
const title = ref('Vue Dynamic Forms');
4756
const formValues = reactive({});
57+
58+
const emailValidator = {
59+
validator: email,
60+
text: 'Email format is incorrect',
61+
};
62+
63+
const passwordValidator = {
64+
validator: pattern(
65+
'^(?=.*[a-z])(?=.*[A-Z])(?=.*)(?=.*[#$^+=!*()@%&]).{8,10}$',
66+
),
67+
text:
68+
'Password must contain at least 1 Uppercase, 1 Lowercase, 1 number, 1 special character and min 8 characters max 10',
69+
};
70+
4871
const form = reactive({
4972
id: 'example-form',
50-
fields: [
51-
new TextInput({
73+
fieldOrder: [
74+
'name',
75+
'email',
76+
'password',
77+
'console',
78+
'games',
79+
'stock',
80+
'steps',
81+
'character',
82+
'awesomeness',
83+
'color',
84+
'customField1',
85+
],
86+
fields: {
87+
name: {
5288
label: 'Name',
89+
type: 'text',
5390
value: 'Alvaro',
54-
}),
55-
new EmailInput({
91+
},
92+
email: {
5693
label: 'Email',
57-
validations: [new FormValidation(email, 'Email format is incorrect')],
58-
}),
59-
new PasswordInput({
94+
type: 'email',
95+
validations: [emailValidator],
96+
},
97+
password: {
6098
label: 'Password',
61-
validations: [
62-
new FormValidation(
63-
pattern(
64-
'^(?=.*[a-z])(?=.*[A-Z])(?=.*)(?=.*[#$^+=!*()@%&]).{8,10}$',
65-
),
66-
'Password must contain at least 1 Uppercase, 1 Lowercase, 1 number, 1 special character and min 8 characters max 10',
67-
),
68-
],
69-
}),
70-
new SelectInput<string>({
99+
type: 'password',
100+
validations: [passwordValidator],
101+
},
102+
stock: {
103+
label: 'Stock',
104+
type: 'number',
105+
},
106+
games: {
71107
label: 'Games',
108+
type: 'select',
72109
customClass: 'w-1/2',
110+
value: 'the-last-of-us',
73111
options: [
74112
{
75113
key: 'the-last-of-us',
@@ -84,17 +122,58 @@ export default defineComponent({
84122
value: 'Nier Automata',
85123
},
86124
],
87-
}),
88-
new TextAreaInput({
89-
label: 'Bio',
90-
cols: 20,
91-
rows: 5,
92-
}),
93-
new ColorInput({
125+
},
126+
console: {
127+
label: 'Console (Async Options)',
128+
type: 'select',
129+
customClass: 'w-1/2',
130+
options: [],
131+
},
132+
steps: {
133+
label: 'Number',
134+
type: 'number',
135+
min: 5,
136+
max: 60,
137+
step: 5,
138+
value: 5,
139+
},
140+
awesomeness: {
141+
label: "Check if you're awesome",
142+
type: 'checkbox',
143+
},
144+
character: {
145+
label: 'Select one option',
146+
type: 'radio',
147+
options: [
148+
{
149+
key: 'mario',
150+
value: 'Mario',
151+
},
152+
{
153+
key: 'crash-bandicoot',
154+
value: 'Crash Bandicoot',
155+
},
156+
{
157+
key: 'sonic',
158+
value: 'Sonic',
159+
},
160+
{
161+
key: 'banjo-kazooie',
162+
value: 'Banjo Kazooie',
163+
disabled: true,
164+
},
165+
],
166+
},
167+
customField1: {
168+
type: 'custom-field',
169+
label: 'Custom Field',
170+
},
171+
color: {
94172
label: 'Color',
173+
type: 'color',
95174
value: '#4DBA87',
96-
}),
97-
],
175+
},
176+
},
98177
});
99178
function handleSubmit(values) {
100179
console.log('Values Submitted', values);
@@ -107,6 +186,32 @@ export default defineComponent({
107186
alert(errors);
108187
}
109188
189+
onMounted(async () => {
190+
try {
191+
const consoleOptions = await mockAsync(true, 4000, [
192+
{
193+
key: 'playstation',
194+
value: 'Playstation',
195+
},
196+
{
197+
key: 'nintendo',
198+
value: 'Nintendo',
199+
},
200+
{
201+
key: 'xbox',
202+
value: 'Xbox',
203+
},
204+
]);
205+
form.fields.console.options = consoleOptions as {
206+
key: string;
207+
value: string;
208+
disabled?: boolean;
209+
}[];
210+
} catch (e) {
211+
console.error(e);
212+
}
213+
});
214+
110215
return {
111216
title,
112217
form,
@@ -118,4 +223,19 @@ export default defineComponent({
118223
},
119224
});
120225
</script>
121-
<style lang="scss"></style>
226+
<style lang="scss">
227+
.avocado-field {
228+
position: relative;
229+
230+
.form-control {
231+
border-color: #aec64c;
232+
background-color: #e2eb5d52;
233+
border-radius: 16px;
234+
}
235+
i {
236+
position: absolute;
237+
top: 5px;
238+
right: 15px;
239+
}
240+
}
241+
</style>

dev/vue/styles/_vendors.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
$input-border-radius: 50px; */
99
// @import '../../src/styles/themes/default.scss';
1010

11-
/* @import '@/styles/themes/default.scss'; */
11+
@import '@/styles/themes/default.scss';
1212

1313
// Third-party
1414

package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
},
5353
"devDependencies": {
5454
"@microsoft/api-extractor": "^7.10.1",
55+
"@rollup/plugin-alias": "^3.1.1",
5556
"@rollup/plugin-buble": "^0.21.3",
5657
"@rollup/plugin-commonjs": "^15.1.0",
5758
"@rollup/plugin-node-resolve": "^9.0.0",

rollup.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import commonjs from '@rollup/plugin-commonjs';
77
import { terser } from 'rollup-plugin-terser';
88
import ts from 'rollup-plugin-typescript2';
99
import vue from 'rollup-plugin-vue';
10+
import alias from '@rollup/plugin-alias';
1011

1112
import pkg from './package.json';
1213
const name = 'as-dynamic-forms';
@@ -89,6 +90,9 @@ function createConfig(format, output, plugins = []) {
8990
// used alone.
9091
external,
9192
plugins: [
93+
alias({
94+
entries: [{ find: '@', replacement: path.resolve(__dirname, 'src') }],
95+
}),
9296
tsPlugin,
9397
vue(),
9498
createReplacePlugin(

src/components/checkbox-input/CheckboxInput.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import { defineComponent, h, PropType } from 'vue';
3-
import { FormControl, CheckboxInput } from '../../core/models';
4-
import { useInputEvents } from '../../composables/input-events';
3+
import { FormControl, CheckboxInput } from '@/core/models';
4+
import { useInputEvents } from '@/composables/input-events';
55
66
const props = {
77
control: Object as PropType<FormControl<CheckboxInput>>,

src/components/dynamic-form/DynamicForm.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ import {
4949
import { DynamicForm } from './form';
5050
import DynamicInput from '../dynamic-input/DynamicInput.vue';
5151
52-
import { FormControl, InputType } from '../../core/models';
53-
import { dynamicFormsSymbol } from '../../useApi';
54-
import { removeEmpty } from '../../core/utils/helpers';
52+
import { FormControl, InputType } from '@/core/models';
53+
import { dynamicFormsSymbol } from '@/useApi';
54+
import { removeEmpty } from '@/core/utils/helpers';
5555
56+
/* import { warn } from '../../core/utils/warning';
57+
*/
5658
const props = {
5759
form: {
5860
type: Object as PropType<DynamicForm>,

src/components/dynamic-input/DynamicInput.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import {
2222
CheckboxInput,
2323
TextAreaInput,
2424
InputType,
25-
} from '../../core/models';
25+
} from '@/core/models';
2626
27-
import { isEmpty, entries, values, keys } from '../../core/utils/helpers';
28-
import { useInputEvents } from '../../composables/input-events';
29-
import { dynamicFormsSymbol } from '../../useApi';
27+
import { isEmpty, entries, values, keys } from '@/core/utils/helpers';
28+
import { useInputEvents } from '@/composables/input-events';
29+
import { dynamicFormsSymbol } from '@/useApi';
3030
3131
const components = {
3232
TextInputComponent,

0 commit comments

Comments
 (0)