-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputText.vue
166 lines (156 loc) · 3.44 KB
/
InputText.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<template>
<div
class="InputBox"
v-bind:class="[inputSize, isDisabled ? 'disabled' : '']"
>
<div
class="InputWrap InputField HLayout align-center"
v-bind:class="errorClass"
>
<input
type="text"
:value="inputValue"
:placeholder="placeholder"
:disabled="isDisabled"
:aria-describedby="describeBy"
@change="onchange"
@focus="onfocus"
@blur="onblur"
@keypress="onkeypress"
@keyup="onkeyup"
/>
</div>
<div class="error-message" v-if="!!error">{{ error }}</div>
</div>
</template>
<script>
import { normalizeInput } from "../../../utils/utilities";
const INPUTSIZE = {
small: "size-small",
default: "size-normal",
large: "size-large",
xlarge: "size-xlarge",
};
export default {
controlName: "l-input-text",
name: "InputText",
data: function () {
return {
inputValue: this.value,
};
},
props: {
placeholder: {
type: String,
default: "text",
description: "Placeholder text of the control.",
},
value: {
type: String,
default: "",
description: "Initial value of the control.",
},
size: {
type: String,
default: "default",
description: "Size of the text.",
options: Object.keys(INPUTSIZE),
},
disabled: {
type: Boolean,
default: false,
description: "Disable the control.",
},
error: {
type: String,
default: "",
description: "Passed in error message. Show error message if any.",
},
},
computed: {
inputSize: function () {
return this.size
? normalizeInput(INPUTSIZE, this.size)
: this.$parent.labelSize
? ""
: normalizeInput(INPUTSIZE, "default");
},
describeBy: function () {
return this.$parent.labelID || "";
},
isDisabled: function () {
return this.$parent.isDisabled || this.disabled;
},
placeholderText: function () {
return this.placeholder || this.$parent.value || "Placeholder";
},
errorClass: function () {
return this.error ? "invalid-input" : "";
},
},
methods: {
onchange: function (event) {
!this.isDisabled &&
!!this._events.change &&
this.$emit("change", event);
},
onfocus: function (event) {
!this.isDisabled &&
!!this._events.focus &&
this.$emit("focus", event);
},
onblur: function (event) {
this.setValue(event.target.value);
!this.isDisabled &&
!!this._events.blur &&
this.$emit("blur", event);
},
onkeypress: function (event) {
!this.isDisabled &&
!!this._events.keypress &&
this.$emit("keypress", event);
},
onkeyup: function (event) {
!this.isDisabled &&
!!this._events.keyup &&
this.$emit("keyup", event);
},
setValue: function (newVal) {
if (newVal !== this.inputValue) {
this.inputValue = newVal;
}
},
getValue: function () {
return this.inputValue;
},
},
expose_events: {
"@change": {
description: "Binded action, triggered on value being changed.",
},
"@focus": {
description: "Binded action, triggered on the control being focus.",
},
"@blur": {
description: "Binded action, triggered on the control being blur.",
},
"@keypress": {
description: "Binded action, triggered on key being pressed.",
},
"@keyup": {
description: "Binded action, triggered on key being pressed up.",
},
},
expose_methods: {
onchange: {
description: "Programmatically trigger the on change method.",
},
setValue: {
description: "<String> | Set the value programmatically.",
},
getValue: {
description: "<String> | Get the value.",
},
},
};
</script>