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

Commit 1ee9c81

Browse files
committed
feat(number): added independent number field component
1 parent ee8f5e4 commit 1ee9c81

File tree

6 files changed

+66
-3
lines changed

6 files changed

+66
-3
lines changed

dev/typescript/App.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
</template>
4646

4747
<script lang="ts">
48-
import { defineComponent, onMounted, reactive, ref } from 'vue';
48+
import { defineComponent, reactive, ref } from 'vue';
4949
import {
5050
TextInput,
5151
SelectInput,
@@ -59,8 +59,9 @@ import {
5959
email,
6060
pattern,
6161
ColorInput,
62+
NumberInput,
6263
} from '../../src';
63-
64+
/* } from '../../dist/as-dynamic-forms.esm'; */
6465
export default defineComponent({
6566
name: 'app',
6667
setup() {
@@ -88,9 +89,16 @@ export default defineComponent({
8889
),
8990
],
9091
}),
92+
new NumberInput({
93+
label: 'Number',
94+
min: 5,
95+
max: 60,
96+
step: 5,
97+
}),
9198
new SelectInput<string>({
9299
label: 'Games',
93100
customClass: 'w-1/2',
101+
value: 'the-last-of-us',
94102
options: [
95103
{
96104
key: 'the-last-of-us',

src/components/dynamic-input/DynamicInput.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import SelectInput from '../select-input/SelectInput.vue';
77
import TextAreaInput from '../text-area-input/TextAreaInput.vue';
88
import CheckboxInput from '../checkbox-input/CheckboxInput.vue';
99
import RadioInput from '../radio-input/RadioInput.vue';
10+
import NumberInput from '../number-input/NumberInput.vue';
1011
1112
import { FormControl } from '../../core/models';
1213
import { isEmpty, entries, values, keys } from '../../core/utils/helpers';
@@ -19,6 +20,7 @@ const components = {
1920
TextAreaInput,
2021
CheckboxInput,
2122
RadioInput,
23+
NumberInput,
2224
};
2325
2426
const props = {
@@ -138,6 +140,9 @@ export default defineComponent({
138140
case 'color':
139141
component = h(TextInput, attributes.value);
140142
break;
143+
case 'number':
144+
component = h(NumberInput, attributes.value);
145+
break;
141146
case 'select':
142147
component = h(SelectInput, attributes.value);
143148
break;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<script lang="ts">
2+
import { defineComponent, h, PropType } from 'vue';
3+
import { FormControl } from '../../core/models';
4+
import { useInputEvents } from '../../composables/input-events';
5+
6+
const props = {
7+
control: Object as PropType<FormControl<string>>,
8+
};
9+
10+
export default defineComponent({
11+
name: 'asNumberInput',
12+
props,
13+
setup(props, { emit }) {
14+
const { onChange, onFocus, onBlur } = useInputEvents(props?.control, emit);
15+
16+
return () =>
17+
h('input', {
18+
name: props?.control?.name || '',
19+
type: props?.control?.type,
20+
disabled: props?.control?.disabled,
21+
placeholder: props?.control?.placeholder,
22+
class: ['form-control'],
23+
value: props?.control?.value,
24+
min: props?.control?.min,
25+
max: props?.control?.max,
26+
step: props?.control?.step,
27+
onFocus,
28+
onBlur,
29+
onChange,
30+
});
31+
},
32+
});
33+
</script>
34+
35+
<style></style>

src/components/text-input/TextInput.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FormControl } from '../../core/models';
44
import { useInputEvents } from '../../composables/input-events';
55
66
const props = {
7-
control: Object as PropType<FormControl<any>>,
7+
control: Object as PropType<FormControl<string>>,
88
};
99
1010
export default defineComponent({

src/core/models.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export class InputBase<T> {
3131
options?: { key: string; value: string; disabled?: boolean }[];
3232
cols?: number;
3333
rows?: number;
34+
min?: number;
35+
max?: number;
36+
step?: number;
3437

3538
constructor(
3639
options: {
@@ -46,6 +49,9 @@ export class InputBase<T> {
4649
options?: { key: string; value: string; disabled?: boolean }[];
4750
cols?: number;
4851
rows?: number;
52+
min?: number;
53+
max?: number;
54+
step?: number;
4955
} = {},
5056
) {
5157
this.value = options.value;
@@ -60,6 +66,9 @@ export class InputBase<T> {
6066
this.options = options.options;
6167
this.rows = options.rows || 0;
6268
this.cols = options.cols || 0;
69+
this.min = options.min || 0;
70+
this.max = options.max || 0;
71+
this.step = options.step || 0;
6372
}
6473
}
6574

@@ -122,6 +131,9 @@ export class FormControl<T> extends InputBase<T> {
122131
options?: { key: string; value: string; disabled?: boolean }[];
123132
cols?: number;
124133
rows?: number;
134+
min?: number;
135+
max?: number;
136+
step?: number;
125137
} = {},
126138
) {
127139
super({
@@ -136,6 +148,9 @@ export class FormControl<T> extends InputBase<T> {
136148
options: options.options,
137149
rows: options.rows,
138150
cols: options.cols,
151+
min: options.min,
152+
max: options.max,
153+
step: options.step,
139154
});
140155
}
141156
}

0 commit comments

Comments
 (0)