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

Commit 451a1ab

Browse files
committed
feat(next): Textarea input
1 parent a32579a commit 451a1ab

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

dev/vue/App.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="page container">
44
<h1 class="title m-4">{{ title }}</h1>
55
<div class="flex justify-between">
6-
<div class="card p-6">
6+
<div class="card p-6 mr-4">
77
<dynamic-form
88
:form="form"
99
@submited="handleSubmit"
@@ -35,6 +35,7 @@ import {
3535
EmailInput,
3636
FormValidation,
3737
PasswordInput,
38+
TextAreaInput,
3839
} from '../../src/index';
3940
import { email, pattern } from '@/core/utils';
4041
@@ -83,6 +84,11 @@ export default defineComponent({
8384
},
8485
],
8586
}),
87+
new TextAreaInput({
88+
label: 'Bio',
89+
cols: 20,
90+
rows: 5,
91+
}),
8692
],
8793
});
8894
function handleSubmit(values) {

src/components/dynamic-input/DynamicInput.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import { defineComponent, PropType, computed, h } from 'vue';
55
import TextInput from '@/components/text-input/TextInput.vue';
66
import SelectInput from '@/components/select-input/SelectInput.vue';
7+
import TextAreaInput from '@/components/text-area-input/TextAreaInput.vue';
78
89
import { FormControl } from '@/core/models';
910
import { isEmpty, entries, values, keys } from '@/core/utils/helpers';
1011
1112
const components = {
1213
TextInput,
1314
SelectInput,
15+
TextAreaInput,
1416
};
1517
1618
const props = {
@@ -112,6 +114,9 @@ export default defineComponent({
112114
case 'select':
113115
component = h(SelectInput, attributes.value);
114116
break;
117+
case 'textarea':
118+
component = h(TextAreaInput, attributes.value);
119+
break;
115120
116121
default:
117122
break;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
const props = {
6+
control: Object as PropType<FormControl<any>>,
7+
};
8+
9+
export default defineComponent({
10+
name: 'asTextAreaInput',
11+
props,
12+
setup(props, { emit }) {
13+
const { onChange, onFocus, onBlur } = useInputEvents(props?.control, emit);
14+
15+
return () =>
16+
h('textarea', {
17+
name: props?.control?.name || '',
18+
type: props?.control?.type,
19+
disabled: props?.control?.disabled,
20+
placeholder: props?.control?.placeholder,
21+
class: ['form-control'],
22+
value: props?.control?.value,
23+
rows: props?.control?.rows,
24+
cols: props?.control?.cols,
25+
onFocus,
26+
onBlur,
27+
onChange,
28+
});
29+
},
30+
});
31+
</script>
32+
33+
<style></style>

src/core/models.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export class InputBase<T> {
2929
placeholder?: string;
3030
validations?: FormValidation[];
3131
options?: { key: string; value: string; disabled?: boolean }[];
32+
cols?: number;
33+
rows?: number;
3234

3335
constructor(
3436
options: {
@@ -42,6 +44,8 @@ export class InputBase<T> {
4244
placeholder?: string;
4345
validations?: FormValidation[];
4446
options?: { key: string; value: string; disabled?: boolean }[];
47+
cols?: number;
48+
rows?: number;
4549
} = {},
4650
) {
4751
this.value = options.value;
@@ -54,6 +58,8 @@ export class InputBase<T> {
5458
this.placeholder = options.placeholder;
5559
this.validations = options.validations || [];
5660
this.options = options.options;
61+
this.rows = options.rows || 0;
62+
this.cols = options.cols || 0;
5763
}
5864
}
5965

@@ -73,6 +79,10 @@ export class SelectInput<T> extends InputBase<T> {
7379
type = 'select';
7480
}
7581

82+
export class TextAreaInput extends InputBase<string> {
83+
type = 'textarea';
84+
}
85+
7686
export class FormControl<T> extends InputBase<T> {
7787
valid = true;
7888
invalid = false;
@@ -90,6 +100,8 @@ export class FormControl<T> extends InputBase<T> {
90100
customClass?: string;
91101
validations?: FormValidation[];
92102
options?: { key: string; value: string; disabled?: boolean }[];
103+
cols?: number;
104+
rows?: number;
93105
} = {},
94106
) {
95107
super({
@@ -102,6 +114,8 @@ export class FormControl<T> extends InputBase<T> {
102114
customClass: options.customClass,
103115
validations: options.validations,
104116
options: options.options,
117+
rows: options.rows,
118+
cols: options.cols,
105119
});
106120
}
107121
}

0 commit comments

Comments
 (0)