@everymatrix/general-input 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/checkbox-input_9.cjs.entry.js +686 -0
- package/dist/cjs/general-input.cjs.entry.js +45 -0
- package/dist/cjs/general-input.cjs.js +19 -0
- package/dist/cjs/index-64a5cb7f.js +1214 -0
- package/dist/cjs/index.cjs.js +2 -0
- package/dist/cjs/loader.cjs.js +21 -0
- package/dist/collection/collection-manifest.json +21 -0
- package/dist/collection/components/checkbox-input/checkbox-input.css +20 -0
- package/dist/collection/components/checkbox-input/checkbox-input.js +196 -0
- package/dist/collection/components/date-input/date-input.css +60 -0
- package/dist/collection/components/date-input/date-input.js +242 -0
- package/dist/collection/components/email-input/email-input.css +60 -0
- package/dist/collection/components/email-input/email-input.js +259 -0
- package/dist/collection/components/general-input/general-input.css +3 -0
- package/dist/collection/components/general-input/general-input.js +204 -0
- package/dist/collection/components/number-input/number-input.css +67 -0
- package/dist/collection/components/number-input/number-input.js +245 -0
- package/dist/collection/components/password-input/password-input.css +60 -0
- package/dist/collection/components/password-input/password-input.js +210 -0
- package/dist/collection/components/radio-input/radio-input.css +22 -0
- package/dist/collection/components/radio-input/radio-input.js +245 -0
- package/dist/collection/components/select-input/select-input.css +49 -0
- package/dist/collection/components/select-input/select-input.js +308 -0
- package/dist/collection/components/tel-input/tel-input.css +67 -0
- package/dist/collection/components/tel-input/tel-input.js +294 -0
- package/dist/collection/components/text-input/text-input.css +60 -0
- package/dist/collection/components/text-input/text-input.js +278 -0
- package/dist/collection/index.js +1 -0
- package/dist/collection/utils/locale.utils.js +27 -0
- package/dist/collection/utils/types.js +1 -0
- package/dist/collection/utils/utils.js +5 -0
- package/dist/components/checkbox-input.d.ts +11 -0
- package/dist/components/checkbox-input.js +6 -0
- package/dist/components/checkbox-input2.js +78 -0
- package/dist/components/date-input.d.ts +11 -0
- package/dist/components/date-input.js +6 -0
- package/dist/components/date-input2.js +90 -0
- package/dist/components/email-input.d.ts +11 -0
- package/dist/components/email-input.js +6 -0
- package/dist/components/email-input2.js +108 -0
- package/dist/components/general-input.d.ts +11 -0
- package/dist/components/general-input.js +123 -0
- package/dist/components/index.d.ts +26 -0
- package/dist/components/index.js +1 -0
- package/dist/components/locale.utils.js +29 -0
- package/dist/components/number-input.d.ts +11 -0
- package/dist/components/number-input.js +6 -0
- package/dist/components/number-input2.js +96 -0
- package/dist/components/password-input.d.ts +11 -0
- package/dist/components/password-input.js +6 -0
- package/dist/components/password-input2.js +93 -0
- package/dist/components/radio-input.d.ts +11 -0
- package/dist/components/radio-input.js +6 -0
- package/dist/components/radio-input2.js +89 -0
- package/dist/components/select-input.d.ts +11 -0
- package/dist/components/select-input.js +6 -0
- package/dist/components/select-input2.js +127 -0
- package/dist/components/tel-input.d.ts +11 -0
- package/dist/components/tel-input.js +6 -0
- package/dist/components/tel-input2.js +111 -0
- package/dist/components/text-input.d.ts +11 -0
- package/dist/components/text-input.js +6 -0
- package/dist/components/text-input2.js +112 -0
- package/dist/esm/checkbox-input_9.entry.js +674 -0
- package/dist/esm/general-input.entry.js +41 -0
- package/dist/esm/general-input.js +17 -0
- package/dist/esm/index-df80f936.js +1188 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/loader.js +17 -0
- package/dist/esm/polyfills/core-js.js +11 -0
- package/dist/esm/polyfills/css-shim.js +1 -0
- package/dist/esm/polyfills/dom.js +79 -0
- package/dist/esm/polyfills/es5-html-element.js +1 -0
- package/dist/esm/polyfills/index.js +34 -0
- package/dist/esm/polyfills/system.js +6 -0
- package/dist/general-input/general-input.esm.js +1 -0
- package/dist/general-input/index.esm.js +0 -0
- package/dist/general-input/p-c9e79656.entry.js +1 -0
- package/dist/general-input/p-d9f7fa2e.js +1 -0
- package/dist/general-input/p-dea0a4ac.entry.js +1 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/stencil.config.js +22 -0
- package/dist/types/Users/user/workspace/everymatrix/widgets-stencil/packages/general-input/.stencil/packages/general-input/stencil.config.d.ts +2 -0
- package/dist/types/components/checkbox-input/checkbox-input.d.ts +39 -0
- package/dist/types/components/date-input/date-input.d.ts +47 -0
- package/dist/types/components/email-input/email-input.d.ts +51 -0
- package/dist/types/components/general-input/general-input.d.ts +40 -0
- package/dist/types/components/number-input/number-input.d.ts +48 -0
- package/dist/types/components/password-input/password-input.d.ts +42 -0
- package/dist/types/components/radio-input/radio-input.d.ts +48 -0
- package/dist/types/components/select-input/select-input.d.ts +55 -0
- package/dist/types/components/tel-input/tel-input.d.ts +59 -0
- package/dist/types/components.d.ts +749 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/stencil-public-runtime.d.ts +1565 -0
- package/dist/types/utils/locale.utils.d.ts +5 -0
- package/dist/types/utils/types.d.ts +55 -0
- package/dist/types/utils/utils.d.ts +1 -0
- package/loader/cdn.js +3 -0
- package/loader/index.cjs.js +3 -0
- package/loader/index.d.ts +12 -0
- package/loader/index.es2017.js +3 -0
- package/loader/index.js +4 -0
- package/loader/package.json +10 -0
- package/package.json +19 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { Component, h, Prop, State, Event, Watch } from '@stencil/core';
|
|
2
|
+
import { translate } from '../../utils/locale.utils';
|
|
3
|
+
export class TelInput {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.validationPattern = '';
|
|
6
|
+
}
|
|
7
|
+
checkValidityHandler(newValue) {
|
|
8
|
+
if (newValue == true) {
|
|
9
|
+
this.isValid = this.setValidity();
|
|
10
|
+
this.errorMessage = this.setErrorMessage();
|
|
11
|
+
this.validityStateHandler({ valid: this.isValid, name: this.name });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
validityChanged() {
|
|
15
|
+
if (this.checkValidity == true) {
|
|
16
|
+
this.validityStateHandler({ valid: this.isValid, name: this.name });
|
|
17
|
+
}
|
|
18
|
+
if (this.emitValue == true) {
|
|
19
|
+
this.valueHandler({ name: this.name, value: this.value });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
validityStateHandler(inputStateEvent) {
|
|
23
|
+
this.sendValidityState.emit(inputStateEvent);
|
|
24
|
+
}
|
|
25
|
+
emitValueHandler(newValue) {
|
|
26
|
+
if (newValue == true && this.isValid) {
|
|
27
|
+
this.valueHandler({ name: this.name, value: this.value });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
valueHandler(inputValueEvent) {
|
|
31
|
+
this.sendInputValue.emit(inputValueEvent);
|
|
32
|
+
}
|
|
33
|
+
connectedCallback() {
|
|
34
|
+
this.validationPattern = this.setPattern();
|
|
35
|
+
}
|
|
36
|
+
handleInput(event) {
|
|
37
|
+
this.value = event.target.value;
|
|
38
|
+
if (this.debounceTime) {
|
|
39
|
+
clearTimeout(this.debounceTime);
|
|
40
|
+
}
|
|
41
|
+
this.debounceTime = setTimeout(() => {
|
|
42
|
+
this.errorMessage = this.setErrorMessage();
|
|
43
|
+
this.isValid = this.setValidity();
|
|
44
|
+
}, 500);
|
|
45
|
+
}
|
|
46
|
+
setValidity() {
|
|
47
|
+
return this.inputReference.validity.valid;
|
|
48
|
+
}
|
|
49
|
+
setPattern() {
|
|
50
|
+
var _a;
|
|
51
|
+
if (((_a = this.validation.custom) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
52
|
+
return this.validation.custom.find(customValidation => customValidation.rule === 'regex').pattern;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
setErrorMessage() {
|
|
56
|
+
if (this.inputReference.validity.patternMismatch) {
|
|
57
|
+
return this.validation.custom.find(customValidation => customValidation.rule === 'regex').errorMessage;
|
|
58
|
+
}
|
|
59
|
+
if (this.inputReference.validity.tooShort || this.inputReference.validity.tooLong) {
|
|
60
|
+
return translate('lengthError', this.language, { values: { minLength: this.validation.minLength, maxLength: this.validation.maxLength } });
|
|
61
|
+
}
|
|
62
|
+
if (this.inputReference.validity.valueMissing) {
|
|
63
|
+
return translate('requiredError', this.language);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
render() {
|
|
67
|
+
const invalidClass = this.isValid == true || this.isValid == undefined ? '' : 'tel__input--invalid';
|
|
68
|
+
return h("div", { class: 'tel__wrapper' },
|
|
69
|
+
h("input", { type: "tel", ref: (el) => this.inputReference = el, id: `${this.name}__input`, value: this.defaultValue, class: `tel__input ${invalidClass}`, placeholder: `${this.displayName} ${this.validation.mandatory ? '*' : ''}`, required: this.validation.mandatory, minlength: this.validation.minLength, maxlength: this.validation.maxLength, pattern: this.validationPattern, onInput: (e) => this.handleInput(e) }),
|
|
70
|
+
h("label", { class: `tel__label ${this.validation.mandatory ? 'tel__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName),
|
|
71
|
+
h("small", { class: 'tel__error-message' }, this.errorMessage));
|
|
72
|
+
}
|
|
73
|
+
static get is() { return "tel-input"; }
|
|
74
|
+
static get encapsulation() { return "shadow"; }
|
|
75
|
+
static get originalStyleUrls() { return {
|
|
76
|
+
"$": ["tel-input.scss"]
|
|
77
|
+
}; }
|
|
78
|
+
static get styleUrls() { return {
|
|
79
|
+
"$": ["tel-input.css"]
|
|
80
|
+
}; }
|
|
81
|
+
static get properties() { return {
|
|
82
|
+
"name": {
|
|
83
|
+
"type": "string",
|
|
84
|
+
"mutable": false,
|
|
85
|
+
"complexType": {
|
|
86
|
+
"original": "string",
|
|
87
|
+
"resolved": "string",
|
|
88
|
+
"references": {}
|
|
89
|
+
},
|
|
90
|
+
"required": false,
|
|
91
|
+
"optional": false,
|
|
92
|
+
"docs": {
|
|
93
|
+
"tags": [],
|
|
94
|
+
"text": "Name of the input."
|
|
95
|
+
},
|
|
96
|
+
"attribute": "name",
|
|
97
|
+
"reflect": false
|
|
98
|
+
},
|
|
99
|
+
"displayName": {
|
|
100
|
+
"type": "string",
|
|
101
|
+
"mutable": false,
|
|
102
|
+
"complexType": {
|
|
103
|
+
"original": "string",
|
|
104
|
+
"resolved": "string",
|
|
105
|
+
"references": {}
|
|
106
|
+
},
|
|
107
|
+
"required": false,
|
|
108
|
+
"optional": false,
|
|
109
|
+
"docs": {
|
|
110
|
+
"tags": [],
|
|
111
|
+
"text": "Name of input to be shown to the user."
|
|
112
|
+
},
|
|
113
|
+
"attribute": "display-name",
|
|
114
|
+
"reflect": false
|
|
115
|
+
},
|
|
116
|
+
"showLabels": {
|
|
117
|
+
"type": "boolean",
|
|
118
|
+
"mutable": false,
|
|
119
|
+
"complexType": {
|
|
120
|
+
"original": "boolean",
|
|
121
|
+
"resolved": "boolean",
|
|
122
|
+
"references": {}
|
|
123
|
+
},
|
|
124
|
+
"required": false,
|
|
125
|
+
"optional": false,
|
|
126
|
+
"docs": {
|
|
127
|
+
"tags": [],
|
|
128
|
+
"text": "Boolean that defines if the widget show labels or placeholders."
|
|
129
|
+
},
|
|
130
|
+
"attribute": "show-labels",
|
|
131
|
+
"reflect": false
|
|
132
|
+
},
|
|
133
|
+
"action": {
|
|
134
|
+
"type": "string",
|
|
135
|
+
"mutable": false,
|
|
136
|
+
"complexType": {
|
|
137
|
+
"original": "string",
|
|
138
|
+
"resolved": "string",
|
|
139
|
+
"references": {}
|
|
140
|
+
},
|
|
141
|
+
"required": false,
|
|
142
|
+
"optional": false,
|
|
143
|
+
"docs": {
|
|
144
|
+
"tags": [],
|
|
145
|
+
"text": "Special behaviour an input should have. Can be fetching for data."
|
|
146
|
+
},
|
|
147
|
+
"attribute": "action",
|
|
148
|
+
"reflect": false
|
|
149
|
+
},
|
|
150
|
+
"validation": {
|
|
151
|
+
"type": "unknown",
|
|
152
|
+
"mutable": false,
|
|
153
|
+
"complexType": {
|
|
154
|
+
"original": "ValidationSchema",
|
|
155
|
+
"resolved": "ValidationSchema",
|
|
156
|
+
"references": {
|
|
157
|
+
"ValidationSchema": {
|
|
158
|
+
"location": "import",
|
|
159
|
+
"path": "../../utils/types"
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
"required": false,
|
|
164
|
+
"optional": false,
|
|
165
|
+
"docs": {
|
|
166
|
+
"tags": [],
|
|
167
|
+
"text": "Object of validation rules for the input."
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
"defaultValue": {
|
|
171
|
+
"type": "any",
|
|
172
|
+
"mutable": false,
|
|
173
|
+
"complexType": {
|
|
174
|
+
"original": "number | string",
|
|
175
|
+
"resolved": "number | string",
|
|
176
|
+
"references": {}
|
|
177
|
+
},
|
|
178
|
+
"required": false,
|
|
179
|
+
"optional": false,
|
|
180
|
+
"docs": {
|
|
181
|
+
"tags": [],
|
|
182
|
+
"text": "Default value for the input."
|
|
183
|
+
},
|
|
184
|
+
"attribute": "default-value",
|
|
185
|
+
"reflect": false
|
|
186
|
+
},
|
|
187
|
+
"language": {
|
|
188
|
+
"type": "string",
|
|
189
|
+
"mutable": false,
|
|
190
|
+
"complexType": {
|
|
191
|
+
"original": "string",
|
|
192
|
+
"resolved": "string",
|
|
193
|
+
"references": {}
|
|
194
|
+
},
|
|
195
|
+
"required": false,
|
|
196
|
+
"optional": false,
|
|
197
|
+
"docs": {
|
|
198
|
+
"tags": [],
|
|
199
|
+
"text": "Currently selected language."
|
|
200
|
+
},
|
|
201
|
+
"attribute": "language",
|
|
202
|
+
"reflect": false
|
|
203
|
+
},
|
|
204
|
+
"checkValidity": {
|
|
205
|
+
"type": "boolean",
|
|
206
|
+
"mutable": false,
|
|
207
|
+
"complexType": {
|
|
208
|
+
"original": "boolean",
|
|
209
|
+
"resolved": "boolean",
|
|
210
|
+
"references": {}
|
|
211
|
+
},
|
|
212
|
+
"required": false,
|
|
213
|
+
"optional": false,
|
|
214
|
+
"docs": {
|
|
215
|
+
"tags": [],
|
|
216
|
+
"text": "State passed down from the parent element. Will trigger the input to check for validity."
|
|
217
|
+
},
|
|
218
|
+
"attribute": "check-validity",
|
|
219
|
+
"reflect": false
|
|
220
|
+
},
|
|
221
|
+
"emitValue": {
|
|
222
|
+
"type": "boolean",
|
|
223
|
+
"mutable": false,
|
|
224
|
+
"complexType": {
|
|
225
|
+
"original": "boolean",
|
|
226
|
+
"resolved": "boolean",
|
|
227
|
+
"references": {}
|
|
228
|
+
},
|
|
229
|
+
"required": false,
|
|
230
|
+
"optional": false,
|
|
231
|
+
"docs": {
|
|
232
|
+
"tags": [],
|
|
233
|
+
"text": "State passed down from the parent element. Will trigger the input to send it's value through an event."
|
|
234
|
+
},
|
|
235
|
+
"attribute": "emit-value",
|
|
236
|
+
"reflect": false
|
|
237
|
+
}
|
|
238
|
+
}; }
|
|
239
|
+
static get states() { return {
|
|
240
|
+
"isValid": {},
|
|
241
|
+
"errorMessage": {}
|
|
242
|
+
}; }
|
|
243
|
+
static get events() { return [{
|
|
244
|
+
"method": "sendValidityState",
|
|
245
|
+
"name": "sendValidityState",
|
|
246
|
+
"bubbles": true,
|
|
247
|
+
"cancelable": true,
|
|
248
|
+
"composed": true,
|
|
249
|
+
"docs": {
|
|
250
|
+
"tags": [],
|
|
251
|
+
"text": ""
|
|
252
|
+
},
|
|
253
|
+
"complexType": {
|
|
254
|
+
"original": "InputStateEvent",
|
|
255
|
+
"resolved": "InputStateEvent",
|
|
256
|
+
"references": {
|
|
257
|
+
"InputStateEvent": {
|
|
258
|
+
"location": "import",
|
|
259
|
+
"path": "../../utils/types"
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}, {
|
|
264
|
+
"method": "sendInputValue",
|
|
265
|
+
"name": "sendInputValue",
|
|
266
|
+
"bubbles": true,
|
|
267
|
+
"cancelable": true,
|
|
268
|
+
"composed": true,
|
|
269
|
+
"docs": {
|
|
270
|
+
"tags": [],
|
|
271
|
+
"text": ""
|
|
272
|
+
},
|
|
273
|
+
"complexType": {
|
|
274
|
+
"original": "InputValueEvent",
|
|
275
|
+
"resolved": "InputValueEvent",
|
|
276
|
+
"references": {
|
|
277
|
+
"InputValueEvent": {
|
|
278
|
+
"location": "import",
|
|
279
|
+
"path": "../../utils/types"
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}]; }
|
|
284
|
+
static get watchers() { return [{
|
|
285
|
+
"propName": "checkValidity",
|
|
286
|
+
"methodName": "checkValidityHandler"
|
|
287
|
+
}, {
|
|
288
|
+
"propName": "isValid",
|
|
289
|
+
"methodName": "validityChanged"
|
|
290
|
+
}, {
|
|
291
|
+
"propName": "emitValue",
|
|
292
|
+
"methodName": "emitValueHandler"
|
|
293
|
+
}]; }
|
|
294
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
*,
|
|
2
|
+
*::before,
|
|
3
|
+
*::after {
|
|
4
|
+
padding: 0;
|
|
5
|
+
margin: 0;
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.text__wrapper {
|
|
10
|
+
position: relative;
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column-reverse;
|
|
13
|
+
padding-top: 10px;
|
|
14
|
+
}
|
|
15
|
+
.text__label {
|
|
16
|
+
color: #474747;
|
|
17
|
+
font-size: 16px;
|
|
18
|
+
position: absolute;
|
|
19
|
+
bottom: 15px;
|
|
20
|
+
left: 5px;
|
|
21
|
+
transform: translateY(-25px);
|
|
22
|
+
transition: all 0.3s cubic-bezier(0.5, 0, 0.5, 1);
|
|
23
|
+
}
|
|
24
|
+
.text__label--required::after {
|
|
25
|
+
content: "*";
|
|
26
|
+
margin-left: 5px;
|
|
27
|
+
color: #666666;
|
|
28
|
+
}
|
|
29
|
+
.text__input {
|
|
30
|
+
width: inherit;
|
|
31
|
+
padding: 15px 6px;
|
|
32
|
+
position: relative;
|
|
33
|
+
border: none;
|
|
34
|
+
border-bottom: 3px solid #666666;
|
|
35
|
+
background-color: transparent;
|
|
36
|
+
color: #666666;
|
|
37
|
+
font-size: 16px;
|
|
38
|
+
font-family: inherit;
|
|
39
|
+
}
|
|
40
|
+
.text__input:focus {
|
|
41
|
+
outline: none;
|
|
42
|
+
box-shadow: 0 5px 5px rgba(16, 15, 15, 0.1);
|
|
43
|
+
}
|
|
44
|
+
.text__input::placeholder {
|
|
45
|
+
color: #666666;
|
|
46
|
+
}
|
|
47
|
+
.text__input--invalid {
|
|
48
|
+
border-bottom: 3px solid #cc0000;
|
|
49
|
+
}
|
|
50
|
+
.text__input:placeholder-shown + .text__label {
|
|
51
|
+
opacity: 0;
|
|
52
|
+
visibility: hidden;
|
|
53
|
+
transform: translateY(0);
|
|
54
|
+
}
|
|
55
|
+
.text__error-message {
|
|
56
|
+
position: absolute;
|
|
57
|
+
top: calc(100% + 5px);
|
|
58
|
+
left: 0;
|
|
59
|
+
color: #cc0000;
|
|
60
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { Component, h, Prop, State, Watch, Event } from '@stencil/core';
|
|
2
|
+
import { translate } from '../../utils/locale.utils';
|
|
3
|
+
export class TextInput {
|
|
4
|
+
constructor() {
|
|
5
|
+
/**
|
|
6
|
+
* Default value for the input.
|
|
7
|
+
*/
|
|
8
|
+
this.defaultValue = '';
|
|
9
|
+
this.errorMessage = '';
|
|
10
|
+
this.value = '';
|
|
11
|
+
this.customRules = [];
|
|
12
|
+
this.validationPattern = '';
|
|
13
|
+
}
|
|
14
|
+
validityChanged() {
|
|
15
|
+
if (this.emitValue == true) {
|
|
16
|
+
this.valueHandler({ name: this.name, value: this.value });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
validityStateHandler(inputStateEvent) {
|
|
20
|
+
this.sendValidityState.emit(inputStateEvent);
|
|
21
|
+
}
|
|
22
|
+
emitValueHandler(newValue) {
|
|
23
|
+
if (newValue == true && this.isValid) {
|
|
24
|
+
this.valueHandler({ name: this.name, value: this.value });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
valueHandler(inputValueEvent) {
|
|
28
|
+
this.sendInputValue.emit(inputValueEvent);
|
|
29
|
+
}
|
|
30
|
+
connectedCallback() {
|
|
31
|
+
// @TODO do something with customRules !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
32
|
+
this.customRules = this.setCustomRules();
|
|
33
|
+
this.validationPattern = this.setPattern();
|
|
34
|
+
}
|
|
35
|
+
handleInput(event) {
|
|
36
|
+
this.value = event.target.value;
|
|
37
|
+
this.isValid = this.setValidity();
|
|
38
|
+
this.errorMessage = this.setErrorMessage();
|
|
39
|
+
this.validityStateHandler({ valid: this.isValid, name: this.name });
|
|
40
|
+
}
|
|
41
|
+
setValidity() {
|
|
42
|
+
return this.inputReference.validity.valid;
|
|
43
|
+
}
|
|
44
|
+
// @TODO type here
|
|
45
|
+
setCustomRules() {
|
|
46
|
+
var _a;
|
|
47
|
+
if (((_a = this.validation.custom) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
48
|
+
return this.validation.custom.filter(customValidation => customValidation.rule !== 'regex');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
setPattern() {
|
|
52
|
+
var _a;
|
|
53
|
+
if (((_a = this.validation.custom) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
54
|
+
return this.validation.custom.find(customValidation => customValidation.rule === 'regex').pattern;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
setErrorMessage() {
|
|
58
|
+
if (this.inputReference.validity.patternMismatch) {
|
|
59
|
+
return this.validation.custom.find(customValidation => customValidation.rule === 'regex').errorMessage;
|
|
60
|
+
}
|
|
61
|
+
if (this.inputReference.validity.tooShort || this.inputReference.validity.tooLong) {
|
|
62
|
+
return translate('lengthError', this.language, { values: { minLength: this.validation.minLength, maxLength: this.validation.maxLength } });
|
|
63
|
+
}
|
|
64
|
+
if (this.inputReference.validity.valueMissing) {
|
|
65
|
+
return translate('requiredError', this.language);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
render() {
|
|
69
|
+
const invalidClass = this.isValid == true || this.isValid == undefined ? '' : 'text__input--invalid';
|
|
70
|
+
console.log('this', this.name, this.defaultValue, this.displayName);
|
|
71
|
+
return h("div", { class: 'text__wrapper' },
|
|
72
|
+
h("input", { id: `${this.name}__input`, value: this.defaultValue, type: 'text', class: `text__input ${invalidClass}`, placeholder: `${this.displayName} ${this.validation.mandatory ? '*' : ''}`, ref: (el) => this.inputReference = el, pattern: this.validationPattern, required: this.validation.mandatory, minlength: this.validation.minLength, maxlength: this.validation.maxLength, onBlur: (e) => { this.handleInput(e); } }),
|
|
73
|
+
h("label", { class: `text__label ${this.validation.mandatory ? 'text__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName),
|
|
74
|
+
h("small", { class: 'text__error-message' }, this.errorMessage));
|
|
75
|
+
}
|
|
76
|
+
static get is() { return "text-input"; }
|
|
77
|
+
static get encapsulation() { return "shadow"; }
|
|
78
|
+
static get originalStyleUrls() { return {
|
|
79
|
+
"$": ["text-input.scss"]
|
|
80
|
+
}; }
|
|
81
|
+
static get styleUrls() { return {
|
|
82
|
+
"$": ["text-input.css"]
|
|
83
|
+
}; }
|
|
84
|
+
static get properties() { return {
|
|
85
|
+
"name": {
|
|
86
|
+
"type": "string",
|
|
87
|
+
"mutable": true,
|
|
88
|
+
"complexType": {
|
|
89
|
+
"original": "string",
|
|
90
|
+
"resolved": "string",
|
|
91
|
+
"references": {}
|
|
92
|
+
},
|
|
93
|
+
"required": false,
|
|
94
|
+
"optional": false,
|
|
95
|
+
"docs": {
|
|
96
|
+
"tags": [],
|
|
97
|
+
"text": "Name of the input."
|
|
98
|
+
},
|
|
99
|
+
"attribute": "name",
|
|
100
|
+
"reflect": false
|
|
101
|
+
},
|
|
102
|
+
"displayName": {
|
|
103
|
+
"type": "string",
|
|
104
|
+
"mutable": false,
|
|
105
|
+
"complexType": {
|
|
106
|
+
"original": "string",
|
|
107
|
+
"resolved": "string",
|
|
108
|
+
"references": {}
|
|
109
|
+
},
|
|
110
|
+
"required": false,
|
|
111
|
+
"optional": false,
|
|
112
|
+
"docs": {
|
|
113
|
+
"tags": [],
|
|
114
|
+
"text": "Name of input to be shown to the user."
|
|
115
|
+
},
|
|
116
|
+
"attribute": "display-name",
|
|
117
|
+
"reflect": false
|
|
118
|
+
},
|
|
119
|
+
"validation": {
|
|
120
|
+
"type": "unknown",
|
|
121
|
+
"mutable": false,
|
|
122
|
+
"complexType": {
|
|
123
|
+
"original": "ValidationSchema",
|
|
124
|
+
"resolved": "ValidationSchema",
|
|
125
|
+
"references": {
|
|
126
|
+
"ValidationSchema": {
|
|
127
|
+
"location": "import",
|
|
128
|
+
"path": "../../utils/types"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
"required": false,
|
|
133
|
+
"optional": false,
|
|
134
|
+
"docs": {
|
|
135
|
+
"tags": [],
|
|
136
|
+
"text": "Object of validation rules for the input."
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
"defaultValue": {
|
|
140
|
+
"type": "string",
|
|
141
|
+
"mutable": true,
|
|
142
|
+
"complexType": {
|
|
143
|
+
"original": "string",
|
|
144
|
+
"resolved": "string",
|
|
145
|
+
"references": {}
|
|
146
|
+
},
|
|
147
|
+
"required": false,
|
|
148
|
+
"optional": false,
|
|
149
|
+
"docs": {
|
|
150
|
+
"tags": [],
|
|
151
|
+
"text": "Default value for the input."
|
|
152
|
+
},
|
|
153
|
+
"attribute": "default-value",
|
|
154
|
+
"reflect": false,
|
|
155
|
+
"defaultValue": "''"
|
|
156
|
+
},
|
|
157
|
+
"rules": {
|
|
158
|
+
"type": "string",
|
|
159
|
+
"mutable": false,
|
|
160
|
+
"complexType": {
|
|
161
|
+
"original": "string",
|
|
162
|
+
"resolved": "string",
|
|
163
|
+
"references": {}
|
|
164
|
+
},
|
|
165
|
+
"required": false,
|
|
166
|
+
"optional": false,
|
|
167
|
+
"docs": {
|
|
168
|
+
"tags": [],
|
|
169
|
+
"text": "-----------------------"
|
|
170
|
+
},
|
|
171
|
+
"attribute": "rules",
|
|
172
|
+
"reflect": false
|
|
173
|
+
},
|
|
174
|
+
"language": {
|
|
175
|
+
"type": "string",
|
|
176
|
+
"mutable": false,
|
|
177
|
+
"complexType": {
|
|
178
|
+
"original": "string",
|
|
179
|
+
"resolved": "string",
|
|
180
|
+
"references": {}
|
|
181
|
+
},
|
|
182
|
+
"required": false,
|
|
183
|
+
"optional": false,
|
|
184
|
+
"docs": {
|
|
185
|
+
"tags": [],
|
|
186
|
+
"text": "Currently selected language."
|
|
187
|
+
},
|
|
188
|
+
"attribute": "language",
|
|
189
|
+
"reflect": false
|
|
190
|
+
},
|
|
191
|
+
"checkValidity": {
|
|
192
|
+
"type": "boolean",
|
|
193
|
+
"mutable": false,
|
|
194
|
+
"complexType": {
|
|
195
|
+
"original": "boolean",
|
|
196
|
+
"resolved": "boolean",
|
|
197
|
+
"references": {}
|
|
198
|
+
},
|
|
199
|
+
"required": false,
|
|
200
|
+
"optional": false,
|
|
201
|
+
"docs": {
|
|
202
|
+
"tags": [],
|
|
203
|
+
"text": "State passed down from the parent element. Will trigger the input to check for validity."
|
|
204
|
+
},
|
|
205
|
+
"attribute": "check-validity",
|
|
206
|
+
"reflect": false
|
|
207
|
+
},
|
|
208
|
+
"emitValue": {
|
|
209
|
+
"type": "boolean",
|
|
210
|
+
"mutable": false,
|
|
211
|
+
"complexType": {
|
|
212
|
+
"original": "boolean",
|
|
213
|
+
"resolved": "boolean",
|
|
214
|
+
"references": {}
|
|
215
|
+
},
|
|
216
|
+
"required": false,
|
|
217
|
+
"optional": false,
|
|
218
|
+
"docs": {
|
|
219
|
+
"tags": [],
|
|
220
|
+
"text": "State passed down from the parent element. Will trigger the input to send it's value through an event."
|
|
221
|
+
},
|
|
222
|
+
"attribute": "emit-value",
|
|
223
|
+
"reflect": false
|
|
224
|
+
}
|
|
225
|
+
}; }
|
|
226
|
+
static get states() { return {
|
|
227
|
+
"isValid": {},
|
|
228
|
+
"errorMessage": {}
|
|
229
|
+
}; }
|
|
230
|
+
static get events() { return [{
|
|
231
|
+
"method": "sendValidityState",
|
|
232
|
+
"name": "sendValidityState",
|
|
233
|
+
"bubbles": true,
|
|
234
|
+
"cancelable": true,
|
|
235
|
+
"composed": true,
|
|
236
|
+
"docs": {
|
|
237
|
+
"tags": [],
|
|
238
|
+
"text": ""
|
|
239
|
+
},
|
|
240
|
+
"complexType": {
|
|
241
|
+
"original": "InputStateEvent",
|
|
242
|
+
"resolved": "InputStateEvent",
|
|
243
|
+
"references": {
|
|
244
|
+
"InputStateEvent": {
|
|
245
|
+
"location": "import",
|
|
246
|
+
"path": "../../utils/types"
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}, {
|
|
251
|
+
"method": "sendInputValue",
|
|
252
|
+
"name": "sendInputValue",
|
|
253
|
+
"bubbles": true,
|
|
254
|
+
"cancelable": true,
|
|
255
|
+
"composed": true,
|
|
256
|
+
"docs": {
|
|
257
|
+
"tags": [],
|
|
258
|
+
"text": ""
|
|
259
|
+
},
|
|
260
|
+
"complexType": {
|
|
261
|
+
"original": "InputValueEvent",
|
|
262
|
+
"resolved": "InputValueEvent",
|
|
263
|
+
"references": {
|
|
264
|
+
"InputValueEvent": {
|
|
265
|
+
"location": "import",
|
|
266
|
+
"path": "../../utils/types"
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}]; }
|
|
271
|
+
static get watchers() { return [{
|
|
272
|
+
"propName": "isValid",
|
|
273
|
+
"methodName": "validityChanged"
|
|
274
|
+
}, {
|
|
275
|
+
"propName": "emitValue",
|
|
276
|
+
"methodName": "emitValueHandler"
|
|
277
|
+
}]; }
|
|
278
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const DEFAULT_LANGUAGE = 'en';
|
|
2
|
+
const SUPPORTED_LANGUAGES = ['ro', 'en'];
|
|
3
|
+
const TRANSLATIONS = {
|
|
4
|
+
en: {
|
|
5
|
+
dateError: 'The selected date should be between {min} and {max}',
|
|
6
|
+
numberLengthError: 'The number should be between ${min} and ${max}',
|
|
7
|
+
lengthError: `The length should be between {minLength} and {maxLength}`,
|
|
8
|
+
requiredError: 'This input is required.',
|
|
9
|
+
nextButton: 'Next',
|
|
10
|
+
backButton: 'Back'
|
|
11
|
+
},
|
|
12
|
+
ro: {
|
|
13
|
+
lengthError: `Cuvântul introdus este prea scurt. {minLength} and {maxLength}`,
|
|
14
|
+
requiredError: 'Acest câmp este obligatoriu.'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export const translate = (key, customLang, values) => {
|
|
18
|
+
const lang = customLang;
|
|
19
|
+
let translation = TRANSLATIONS[lang !== undefined && SUPPORTED_LANGUAGES.includes(lang) ? lang : DEFAULT_LANGUAGE][key];
|
|
20
|
+
if (values !== undefined) {
|
|
21
|
+
for (const [key, value] of Object.entries(values.values)) {
|
|
22
|
+
const regex = new RegExp(`{${key}}`, 'g');
|
|
23
|
+
translation = translation.replace(regex, value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return translation;
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Components, JSX } from "../types/components";
|
|
2
|
+
|
|
3
|
+
interface CheckboxInput extends Components.CheckboxInput, HTMLElement {}
|
|
4
|
+
export const CheckboxInput: {
|
|
5
|
+
prototype: CheckboxInput;
|
|
6
|
+
new (): CheckboxInput;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Used to define this component and all nested components recursively.
|
|
10
|
+
*/
|
|
11
|
+
export const defineCustomElement: () => void;
|