@mgdis/mg-components 5.0.0 → 5.2.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/loader.cjs.js +1 -1
- package/dist/cjs/{mg-badge_24.cjs.entry.js → mg-badge_27.cjs.entry.js} +892 -295
- package/dist/cjs/mg-components.cjs.js +1 -1
- package/dist/collection/collection-manifest.json +2 -0
- package/dist/collection/components/atoms/mg-badge/mg-badge.js +1 -1
- package/dist/collection/components/atoms/mg-button/doc/mg-button.stories.js +1 -0
- package/dist/collection/components/atoms/mg-button/mg-button.css +8 -0
- package/dist/collection/components/atoms/mg-button/mg-button.js +41 -3
- package/dist/collection/components/atoms/mg-card/doc/mg-card.stories.js +18 -0
- package/dist/collection/components/atoms/mg-card/mg-card.css +7 -0
- package/dist/collection/components/atoms/mg-card/mg-card.js +26 -0
- package/dist/collection/components/atoms/mg-divider/doc/mg-divider.stories.js +18 -0
- package/dist/collection/components/atoms/mg-divider/mg-divider.css +9 -0
- package/dist/collection/components/atoms/mg-divider/mg-divider.js +57 -0
- package/dist/collection/components/atoms/mg-tag/mg-tag.js +1 -1
- package/dist/collection/components/atoms/mg-tooltip/doc/mg-tooltip.stories.js +0 -5
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.conf.js +0 -20
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.css +1 -1
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +2 -1
- package/dist/collection/components/molecules/inputs/MgInput.js +3 -11
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +41 -20
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +50 -39
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.css +25 -6
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +42 -33
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.css +25 -6
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +36 -17
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +35 -14
- package/dist/collection/components/molecules/inputs/mg-input-select/doc/mg-input-select.stories.js +2 -3
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.css +28 -6
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +36 -17
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.css +25 -6
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +38 -19
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.css +25 -6
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +37 -18
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +1 -1
- package/dist/collection/components/molecules/mg-details/doc/mg-details.stories.js +1 -0
- package/dist/collection/components/molecules/mg-details/mg-details.css +29 -0
- package/dist/collection/components/molecules/mg-details/mg-details.js +26 -4
- package/dist/collection/components/molecules/mg-form/mg-form.js +73 -27
- package/dist/collection/components/molecules/mg-illustrated-message/doc/mg-illustrated-message.stories.js +6 -6
- package/dist/collection/components/molecules/mg-message/mg-message.js +1 -1
- package/dist/collection/components/molecules/mg-modal/mg-modal.css +2 -1
- package/dist/collection/components/molecules/mg-modal/mg-modal.js +48 -4
- package/dist/collection/components/molecules/mg-panel/mg-panel.css +5 -14
- package/dist/collection/components/molecules/mg-popover/doc/mg-popover.stories.js +0 -5
- package/dist/collection/components/molecules/mg-popover/mg-popover.css +1 -1
- package/dist/collection/components/molecules/mg-popover/mg-popover.js +3 -2
- package/dist/collection/utils/components.utils.js +10 -6
- package/dist/collection/utils/unit.test.utils.js +51 -0
- package/dist/collection/variables.css +23 -8
- package/dist/components/MgInput.js +4 -12
- package/dist/components/components.utils.js +11 -7
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/components/mg-badge2.js +1 -1
- package/dist/components/mg-button2.js +23 -4
- package/dist/components/mg-card.d.ts +11 -0
- package/dist/components/mg-card.js +42 -0
- package/dist/components/mg-details.js +8 -3
- package/dist/components/mg-divider.d.ts +11 -0
- package/dist/components/mg-divider.js +51 -0
- package/dist/components/mg-form.js +67 -26
- package/dist/components/mg-input-checkbox.js +36 -21
- package/dist/components/mg-input-date.js +44 -39
- package/dist/components/mg-input-numeric.js +37 -34
- package/dist/components/mg-input-password.js +32 -19
- package/dist/components/mg-input-radio.js +30 -15
- package/dist/components/mg-input-select2.js +32 -19
- package/dist/components/mg-input-text2.js +34 -21
- package/dist/components/mg-input-textarea.js +32 -19
- package/dist/components/mg-input-toggle.js +1 -1
- package/dist/components/mg-message.js +1 -1
- package/dist/components/mg-modal.js +49 -5
- package/dist/components/mg-panel.js +1 -1
- package/dist/components/mg-popover.js +3 -2
- package/dist/components/mg-tag.js +1 -1
- package/dist/components/mg-tooltip2.js +2 -4
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{mg-badge_24.entry.js → mg-badge_27.entry.js} +839 -245
- package/dist/esm/mg-components.js +1 -1
- package/dist/mg-components/mg-components.css +1 -1
- package/dist/mg-components/mg-components.esm.js +1 -1
- package/dist/mg-components/p-b2b07c3f.entry.js +1 -0
- package/dist/mg-components/variables.css +23 -8
- package/dist/types/components/atoms/mg-button/mg-button.d.ts +8 -2
- package/dist/types/components/atoms/mg-card/doc/mg-card.stories.d.ts +6 -0
- package/dist/types/components/atoms/mg-card/mg-card.d.ts +11 -0
- package/dist/types/components/atoms/mg-divider/doc/mg-divider.stories.d.ts +6 -0
- package/dist/types/components/atoms/mg-divider/mg-divider.d.ts +15 -0
- package/dist/types/components/atoms/mg-tooltip/doc/mg-tooltip.stories.d.ts +0 -6
- package/dist/types/components/atoms/mg-tooltip/mg-tooltip.conf.d.ts +0 -8
- package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +1 -1
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +10 -8
- package/dist/types/components/molecules/inputs/mg-input-date/mg-input-date.d.ts +3 -8
- package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +3 -8
- package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.d.ts +4 -3
- package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.d.ts +4 -2
- package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.d.ts +4 -3
- package/dist/types/components/molecules/inputs/mg-input-text/mg-input-text.d.ts +5 -4
- package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.d.ts +4 -3
- package/dist/types/components/molecules/mg-details/mg-details.d.ts +4 -0
- package/dist/types/components/molecules/mg-form/mg-form.d.ts +21 -1
- package/dist/types/components/molecules/mg-message/mg-message.d.ts +3 -0
- package/dist/types/components/molecules/mg-modal/mg-modal.d.ts +11 -0
- package/dist/types/components/molecules/mg-popover/doc/mg-popover.stories.d.ts +0 -6
- package/dist/types/components/molecules/mg-popover/mg-popover.d.ts +1 -1
- package/dist/types/components.d.ts +55 -6
- package/dist/types/utils/components.utils.d.ts +7 -3
- package/package.json +9 -9
- package/dist/cjs/index-179621c8.js +0 -244
- package/dist/cjs/mg-modal.cjs.entry.js +0 -128
- package/dist/collection/components/molecules/mg-popover/mg-popover.conf.js +0 -20
- package/dist/collection/utils/test.utils.js +0 -38
- package/dist/esm/index-7efedd97.js +0 -238
- package/dist/esm/mg-modal.entry.js +0 -124
- package/dist/mg-components/p-5f89600c.js +0 -1
- package/dist/mg-components/p-b60a4c53.entry.js +0 -1
- package/dist/mg-components/p-df947fa5.entry.js +0 -1
- package/dist/types/components/molecules/mg-popover/mg-popover.conf.d.ts +0 -8
- package/dist/types/utils/test.utils.d.ts +0 -17
|
@@ -6,8 +6,8 @@ import { localeDate, dateRegExp } from '../../../../utils/locale.utils';
|
|
|
6
6
|
import { initLocales } from '../../../../locales';
|
|
7
7
|
export class MgInputDate {
|
|
8
8
|
constructor() {
|
|
9
|
-
//
|
|
10
|
-
this.
|
|
9
|
+
// hasDisplayedError (triggered by blur event)
|
|
10
|
+
this.hasDisplayedError = false;
|
|
11
11
|
/**
|
|
12
12
|
* Input name
|
|
13
13
|
* If not set the value equals the identifier
|
|
@@ -38,8 +38,8 @@ export class MgInputDate {
|
|
|
38
38
|
*/
|
|
39
39
|
this.handleInput = () => {
|
|
40
40
|
this.checkValidity();
|
|
41
|
-
if (this.
|
|
42
|
-
this.
|
|
41
|
+
if (this.hasDisplayedError) {
|
|
42
|
+
this.setErrorMessage();
|
|
43
43
|
}
|
|
44
44
|
this.value = this.input.value;
|
|
45
45
|
};
|
|
@@ -53,14 +53,11 @@ export class MgInputDate {
|
|
|
53
53
|
* Check if input is valid
|
|
54
54
|
*/
|
|
55
55
|
this.checkValidity = () => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
//Send event
|
|
62
|
-
this.inputValid.emit(validity);
|
|
63
|
-
}
|
|
56
|
+
var _a;
|
|
57
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
|
|
58
|
+
this.invalid = !this.valid;
|
|
59
|
+
// We need to send valid event even if it is the same value
|
|
60
|
+
this.inputValid.emit(this.valid);
|
|
64
61
|
};
|
|
65
62
|
/**
|
|
66
63
|
* get input error code
|
|
@@ -89,48 +86,50 @@ export class MgInputDate {
|
|
|
89
86
|
return inputError;
|
|
90
87
|
};
|
|
91
88
|
/**
|
|
92
|
-
*
|
|
89
|
+
* Check input errors
|
|
93
90
|
*
|
|
94
91
|
* @returns {void}
|
|
95
92
|
*/
|
|
96
93
|
this.setErrorMessage = () => {
|
|
97
94
|
var _a;
|
|
98
|
-
const inputError = this.getInputError();
|
|
99
|
-
// required
|
|
100
|
-
if (inputError === InputError.REQUIRED) {
|
|
101
|
-
this.errorMessage = this.messages.errors[inputError];
|
|
102
|
-
}
|
|
103
|
-
// min, max & minMax
|
|
104
|
-
else if ([InputError.MIN, InputError.MAX, InputError.MINMAX].includes(inputError)) {
|
|
105
|
-
this.errorMessage = this.messages.errors.date[inputError].replace('{min}', localeDate(this.min, this.locale)).replace('{max}', localeDate(this.max, this.locale));
|
|
106
|
-
}
|
|
107
|
-
// wrong date format
|
|
108
|
-
// element.validity.badInput is default error message
|
|
109
|
-
else {
|
|
110
|
-
this.errorMessage = this.messages.errors.date.badInput.replace('{min}', ((_a = this.min) === null || _a === void 0 ? void 0 : _a.length) > 0 ? localeDate(this.min, this.locale) : localeDate('1900-01-01', this.locale));
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* Check input errors
|
|
115
|
-
*
|
|
116
|
-
* @returns {void}
|
|
117
|
-
*/
|
|
118
|
-
this.checkError = () => {
|
|
119
95
|
// Set error message
|
|
120
96
|
this.errorMessage = undefined;
|
|
121
97
|
if (!this.valid) {
|
|
122
|
-
this.
|
|
98
|
+
const inputError = this.getInputError();
|
|
99
|
+
// required
|
|
100
|
+
if (inputError === InputError.REQUIRED) {
|
|
101
|
+
this.errorMessage = this.messages.errors[inputError];
|
|
102
|
+
}
|
|
103
|
+
// min, max & minMax
|
|
104
|
+
else if ([InputError.MIN, InputError.MAX, InputError.MINMAX].includes(inputError)) {
|
|
105
|
+
this.errorMessage = this.messages.errors.date[inputError].replace('{min}', localeDate(this.min, this.locale)).replace('{max}', localeDate(this.max, this.locale));
|
|
106
|
+
}
|
|
107
|
+
// wrong date format
|
|
108
|
+
// element.validity.badInput is default error message
|
|
109
|
+
else {
|
|
110
|
+
this.errorMessage = this.messages.errors.date.badInput.replace('{min}', ((_a = this.min) === null || _a === void 0 ? void 0 : _a.length) > 0 ? localeDate(this.min, this.locale) : localeDate('1900-01-01', this.locale));
|
|
111
|
+
}
|
|
123
112
|
}
|
|
124
113
|
};
|
|
125
114
|
}
|
|
126
115
|
validateValue(newValue) {
|
|
127
|
-
if (newValue !== undefined && (typeof newValue !== 'string' || !dateRegExp.test(newValue))) {
|
|
116
|
+
if (newValue !== undefined && newValue !== null && (typeof newValue !== 'string' || !dateRegExp.test(newValue))) {
|
|
128
117
|
throw new Error("<mg-input-date> props 'value' doesn't match pattern: yyyy-mm-dd");
|
|
129
118
|
}
|
|
130
119
|
else {
|
|
131
120
|
this.valueChange.emit(this.value);
|
|
132
121
|
}
|
|
133
122
|
}
|
|
123
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
124
|
+
if (this.input !== undefined) {
|
|
125
|
+
this.input[prop] = newValue;
|
|
126
|
+
this.checkValidity();
|
|
127
|
+
if (this.hasDisplayedError) {
|
|
128
|
+
this.setErrorMessage();
|
|
129
|
+
this.hasDisplayedError = false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
134
133
|
validateMinMax(newValue) {
|
|
135
134
|
if ((newValue === null || newValue === void 0 ? void 0 : newValue.length) === 0 || ((newValue === null || newValue === void 0 ? void 0 : newValue.length) > 0 && !(typeof newValue === 'string' && dateRegExp.test(newValue)))) {
|
|
136
135
|
throw new Error("<mg-input-date> props 'min/max' doesn't match pattern: yyyy-mm-dd");
|
|
@@ -143,8 +142,8 @@ export class MgInputDate {
|
|
|
143
142
|
*/
|
|
144
143
|
async displayError() {
|
|
145
144
|
this.checkValidity();
|
|
146
|
-
this.
|
|
147
|
-
this.
|
|
145
|
+
this.setErrorMessage();
|
|
146
|
+
this.hasDisplayedError = this.invalid;
|
|
148
147
|
}
|
|
149
148
|
/*************
|
|
150
149
|
* Lifecycle *
|
|
@@ -176,7 +175,10 @@ export class MgInputDate {
|
|
|
176
175
|
* @returns {HTMLElement} HTML Element
|
|
177
176
|
*/
|
|
178
177
|
render() {
|
|
179
|
-
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: undefined, disabled: this.disabled, value: this.value, readonlyValue: localeDate(this.value, this.locale), tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("input", { type: "date", class: "mg-input__box", min: this.min, max: this.max, value: this.value, id: this.identifier, name: this.name, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, pattern: "[0-9]{4}-[0-9]{2}-[0-9]{2}", ref: el =>
|
|
178
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: undefined, disabled: this.disabled, value: this.value, readonlyValue: localeDate(this.value, this.locale), tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("input", { type: "date", class: "mg-input__box", min: this.min, max: this.max, value: this.value, id: this.identifier, name: this.name, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, pattern: "[0-9]{4}-[0-9]{2}-[0-9]{2}", ref: el => {
|
|
179
|
+
if (el !== null)
|
|
180
|
+
this.input = el;
|
|
181
|
+
} })));
|
|
180
182
|
}
|
|
181
183
|
static get is() { return "mg-input-date"; }
|
|
182
184
|
static get encapsulation() { return "shadow"; }
|
|
@@ -521,6 +523,15 @@ export class MgInputDate {
|
|
|
521
523
|
return [{
|
|
522
524
|
"propName": "value",
|
|
523
525
|
"methodName": "validateValue"
|
|
526
|
+
}, {
|
|
527
|
+
"propName": "required",
|
|
528
|
+
"methodName": "handleValidityChange"
|
|
529
|
+
}, {
|
|
530
|
+
"propName": "readonly",
|
|
531
|
+
"methodName": "handleValidityChange"
|
|
532
|
+
}, {
|
|
533
|
+
"propName": "disabled",
|
|
534
|
+
"methodName": "handleValidityChange"
|
|
524
535
|
}, {
|
|
525
536
|
"propName": "min",
|
|
526
537
|
"methodName": "validateMinMax"
|
|
@@ -185,21 +185,40 @@
|
|
|
185
185
|
.mg-input.mg-input--width-full:not(.mg-input--label-on-top) {
|
|
186
186
|
justify-content: space-between;
|
|
187
187
|
}
|
|
188
|
+
.mg-input.mg-input--width-full.mg-input--label-on-top .mg-input__box {
|
|
189
|
+
width: 100%;
|
|
190
|
+
}
|
|
188
191
|
.mg-input.mg-input--width-full .mg-input__input-container {
|
|
189
192
|
flex: auto;
|
|
190
193
|
width: 100%;
|
|
191
194
|
}
|
|
192
195
|
.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box {
|
|
196
|
+
max-width: 100%;
|
|
197
|
+
}
|
|
198
|
+
.mg-input:not(.mg-input--label-on-top) .mg-input__box {
|
|
199
|
+
width: 100%;
|
|
200
|
+
max-width: calc(17.7rem + var(--mg-inputs-spacer) * 2);
|
|
201
|
+
min-width: 5rem;
|
|
202
|
+
}
|
|
203
|
+
.mg-input.mg-input--width-16 .mg-input__input-container {
|
|
204
|
+
width: 100%;
|
|
205
|
+
}
|
|
206
|
+
.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input {
|
|
207
|
+
width: 100%;
|
|
208
|
+
max-width: 21rem;
|
|
209
|
+
}
|
|
210
|
+
.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left {
|
|
193
211
|
width: 100%;
|
|
194
212
|
}
|
|
195
|
-
.mg-input.mg-input--width-16 .mg-input__box {
|
|
196
|
-
width: 21rem;
|
|
213
|
+
.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box {
|
|
214
|
+
max-width: 21rem;
|
|
215
|
+
min-width: 100%;
|
|
197
216
|
}
|
|
198
|
-
.mg-input.mg-input--width-4 .mg-input__box {
|
|
199
|
-
width: 7rem;
|
|
217
|
+
.mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box {
|
|
218
|
+
max-width: 7rem;
|
|
200
219
|
}
|
|
201
|
-
.mg-input.mg-input--width-2 .mg-input__box {
|
|
202
|
-
width: 5rem;
|
|
220
|
+
.mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box {
|
|
221
|
+
max-width: 5rem;
|
|
203
222
|
}
|
|
204
223
|
|
|
205
224
|
/**
|
|
@@ -6,8 +6,8 @@ import { initLocales } from '../../../../locales/';
|
|
|
6
6
|
import { localeCurrency, localeNumber } from '../../../../utils/locale.utils';
|
|
7
7
|
export class MgInputNumeric {
|
|
8
8
|
constructor() {
|
|
9
|
-
//
|
|
10
|
-
this.
|
|
9
|
+
// hasDisplayedError (triggered by blur event)
|
|
10
|
+
this.hasDisplayedError = false;
|
|
11
11
|
/**
|
|
12
12
|
* Input name
|
|
13
13
|
* If not set the value equals the identifier
|
|
@@ -63,8 +63,8 @@ export class MgInputNumeric {
|
|
|
63
63
|
this.handleInput = () => {
|
|
64
64
|
// Check validity
|
|
65
65
|
this.checkValidity();
|
|
66
|
-
if (this.
|
|
67
|
-
this.
|
|
66
|
+
if (this.hasDisplayedError) {
|
|
67
|
+
this.setErrorMessage();
|
|
68
68
|
}
|
|
69
69
|
this.value = this.input.value;
|
|
70
70
|
};
|
|
@@ -92,40 +92,27 @@ export class MgInputNumeric {
|
|
|
92
92
|
* @returns {void}
|
|
93
93
|
*/
|
|
94
94
|
this.checkValidity = () => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
this.invalid = !validity;
|
|
100
|
-
//Send event
|
|
101
|
-
this.inputValid.emit(validity);
|
|
102
|
-
}
|
|
95
|
+
this.valid = this.readonly || this.disabled || this.getInputError() === null;
|
|
96
|
+
this.invalid = !this.valid;
|
|
97
|
+
// We need to send valid event even if it is the same value
|
|
98
|
+
this.inputValid.emit(this.valid);
|
|
103
99
|
};
|
|
104
100
|
/**
|
|
105
|
-
* Set error message
|
|
101
|
+
* Set input error message
|
|
106
102
|
*
|
|
107
103
|
* @returns {void}
|
|
108
104
|
*/
|
|
109
105
|
this.setErrorMessage = () => {
|
|
110
|
-
const inputError = this.getInputError();
|
|
111
|
-
if (inputError === InputError.REQUIRED) {
|
|
112
|
-
this.errorMessage = this.messages.errors[inputError];
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
this.errorMessage = this.messages.errors.numeric[inputError].replace('{min}', `${this.formatValue(this.min)}`).replace('{max}', `${this.formatValue(this.max)}`);
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
/**
|
|
119
|
-
* Check input errors
|
|
120
|
-
*
|
|
121
|
-
* @returns {void}
|
|
122
|
-
*/
|
|
123
|
-
this.checkError = () => {
|
|
124
106
|
// Set error message
|
|
125
107
|
this.errorMessage = undefined;
|
|
126
|
-
// Update class
|
|
127
108
|
if (!this.valid) {
|
|
128
|
-
this.
|
|
109
|
+
const inputError = this.getInputError();
|
|
110
|
+
if (inputError === InputError.REQUIRED) {
|
|
111
|
+
this.errorMessage = this.messages.errors[inputError];
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
this.errorMessage = this.messages.errors.numeric[inputError].replace('{min}', `${this.formatValue(this.min)}`).replace('{max}', `${this.formatValue(this.max)}`);
|
|
115
|
+
}
|
|
129
116
|
}
|
|
130
117
|
};
|
|
131
118
|
/**
|
|
@@ -135,7 +122,7 @@ export class MgInputNumeric {
|
|
|
135
122
|
*/
|
|
136
123
|
this.getInputError = () => {
|
|
137
124
|
let inputError = null;
|
|
138
|
-
if (this.input === undefined)
|
|
125
|
+
if (this.input === undefined || this.input === null)
|
|
139
126
|
return inputError;
|
|
140
127
|
// required
|
|
141
128
|
if (!this.input.checkValidity() && this.input.validity.valueMissing) {
|
|
@@ -202,6 +189,16 @@ export class MgInputNumeric {
|
|
|
202
189
|
this.readonlyValue = this.numericValue !== null ? this.formatValue(this.numericValue) : '';
|
|
203
190
|
}
|
|
204
191
|
}
|
|
192
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
193
|
+
if (this.input !== undefined) {
|
|
194
|
+
this.input[prop] = newValue;
|
|
195
|
+
this.checkValidity();
|
|
196
|
+
if (this.hasDisplayedError) {
|
|
197
|
+
this.setErrorMessage();
|
|
198
|
+
this.hasDisplayedError = false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
205
202
|
validateType(newValue) {
|
|
206
203
|
if (!types.includes(newValue)) {
|
|
207
204
|
throw new Error(`<mg-input-numeric> prop "type" must be one of : ${types.join(', ')}`);
|
|
@@ -224,8 +221,8 @@ export class MgInputNumeric {
|
|
|
224
221
|
*/
|
|
225
222
|
async displayError() {
|
|
226
223
|
this.checkValidity();
|
|
227
|
-
this.
|
|
228
|
-
this.
|
|
224
|
+
this.setErrorMessage();
|
|
225
|
+
this.hasDisplayedError = this.invalid;
|
|
229
226
|
}
|
|
230
227
|
/**
|
|
231
228
|
* Displayed value in input
|
|
@@ -268,7 +265,10 @@ export class MgInputNumeric {
|
|
|
268
265
|
* @returns {HTMLElement} HTML Element
|
|
269
266
|
*/
|
|
270
267
|
render() {
|
|
271
|
-
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: this.mgWidth, disabled: this.disabled, value: this.value, readonlyValue: this.readonlyValue, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("input", { type: "text", class: "mg-input__box", value: this.displayValue(), id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el =>
|
|
268
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: this.mgWidth, disabled: this.disabled, value: this.value, readonlyValue: this.readonlyValue, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("input", { type: "text", class: "mg-input__box", value: this.displayValue(), id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el => {
|
|
269
|
+
if (el !== null)
|
|
270
|
+
this.input = el;
|
|
271
|
+
} }), h("slot", { name: "append-input" })));
|
|
272
272
|
}
|
|
273
273
|
static get is() { return "mg-input-numeric"; }
|
|
274
274
|
static get encapsulation() { return "shadow"; }
|
|
@@ -725,6 +725,15 @@ export class MgInputNumeric {
|
|
|
725
725
|
return [{
|
|
726
726
|
"propName": "value",
|
|
727
727
|
"methodName": "validateValue"
|
|
728
|
+
}, {
|
|
729
|
+
"propName": "required",
|
|
730
|
+
"methodName": "handleValidityChange"
|
|
731
|
+
}, {
|
|
732
|
+
"propName": "readonly",
|
|
733
|
+
"methodName": "handleValidityChange"
|
|
734
|
+
}, {
|
|
735
|
+
"propName": "disabled",
|
|
736
|
+
"methodName": "handleValidityChange"
|
|
728
737
|
}, {
|
|
729
738
|
"propName": "type",
|
|
730
739
|
"methodName": "validateType"
|
|
@@ -185,21 +185,40 @@
|
|
|
185
185
|
.mg-input.mg-input--width-full:not(.mg-input--label-on-top) {
|
|
186
186
|
justify-content: space-between;
|
|
187
187
|
}
|
|
188
|
+
.mg-input.mg-input--width-full.mg-input--label-on-top .mg-input__box {
|
|
189
|
+
width: 100%;
|
|
190
|
+
}
|
|
188
191
|
.mg-input.mg-input--width-full .mg-input__input-container {
|
|
189
192
|
flex: auto;
|
|
190
193
|
width: 100%;
|
|
191
194
|
}
|
|
192
195
|
.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box {
|
|
196
|
+
max-width: 100%;
|
|
197
|
+
}
|
|
198
|
+
.mg-input:not(.mg-input--label-on-top) .mg-input__box {
|
|
199
|
+
width: 100%;
|
|
200
|
+
max-width: calc(17.7rem + var(--mg-inputs-spacer) * 2);
|
|
201
|
+
min-width: 5rem;
|
|
202
|
+
}
|
|
203
|
+
.mg-input.mg-input--width-16 .mg-input__input-container {
|
|
204
|
+
width: 100%;
|
|
205
|
+
}
|
|
206
|
+
.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input {
|
|
207
|
+
width: 100%;
|
|
208
|
+
max-width: 21rem;
|
|
209
|
+
}
|
|
210
|
+
.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left {
|
|
193
211
|
width: 100%;
|
|
194
212
|
}
|
|
195
|
-
.mg-input.mg-input--width-16 .mg-input__box {
|
|
196
|
-
width: 21rem;
|
|
213
|
+
.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box {
|
|
214
|
+
max-width: 21rem;
|
|
215
|
+
min-width: 100%;
|
|
197
216
|
}
|
|
198
|
-
.mg-input.mg-input--width-4 .mg-input__box {
|
|
199
|
-
width: 7rem;
|
|
217
|
+
.mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box {
|
|
218
|
+
max-width: 7rem;
|
|
200
219
|
}
|
|
201
|
-
.mg-input.mg-input--width-2 .mg-input__box {
|
|
202
|
-
width: 5rem;
|
|
220
|
+
.mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box {
|
|
221
|
+
max-width: 5rem;
|
|
203
222
|
}
|
|
204
223
|
|
|
205
224
|
/**
|
|
@@ -4,8 +4,8 @@ import { ClassList } from '../../../../utils/components.utils';
|
|
|
4
4
|
import { initLocales } from '../../../../locales';
|
|
5
5
|
export class MgInputPassword {
|
|
6
6
|
constructor() {
|
|
7
|
-
//
|
|
8
|
-
this.
|
|
7
|
+
// hasDisplayedError (triggered by blur event)
|
|
8
|
+
this.hasDisplayedError = false;
|
|
9
9
|
/**
|
|
10
10
|
* Input name
|
|
11
11
|
* If not set the value equals the identifier
|
|
@@ -40,8 +40,8 @@ export class MgInputPassword {
|
|
|
40
40
|
*/
|
|
41
41
|
this.handleInput = () => {
|
|
42
42
|
this.checkValidity();
|
|
43
|
-
if (this.
|
|
44
|
-
this.
|
|
43
|
+
if (this.hasDisplayedError) {
|
|
44
|
+
this.setErrorMessage();
|
|
45
45
|
}
|
|
46
46
|
this.value = this.input.value;
|
|
47
47
|
};
|
|
@@ -55,19 +55,16 @@ export class MgInputPassword {
|
|
|
55
55
|
* Check if input is valid
|
|
56
56
|
*/
|
|
57
57
|
this.checkValidity = () => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
//Send event
|
|
64
|
-
this.inputValid.emit(validity);
|
|
65
|
-
}
|
|
58
|
+
var _a;
|
|
59
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
|
|
60
|
+
this.invalid = !this.valid;
|
|
61
|
+
// We need to send valid event even if it is the same value
|
|
62
|
+
this.inputValid.emit(this.valid);
|
|
66
63
|
};
|
|
67
64
|
/**
|
|
68
|
-
*
|
|
65
|
+
* Set input error message
|
|
69
66
|
*/
|
|
70
|
-
this.
|
|
67
|
+
this.setErrorMessage = () => {
|
|
71
68
|
// Set error message
|
|
72
69
|
this.errorMessage = undefined;
|
|
73
70
|
// required
|
|
@@ -79,6 +76,16 @@ export class MgInputPassword {
|
|
|
79
76
|
handleValue(newValue) {
|
|
80
77
|
this.valueChange.emit(newValue);
|
|
81
78
|
}
|
|
79
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
80
|
+
if (this.input !== undefined) {
|
|
81
|
+
this.input[prop] = newValue;
|
|
82
|
+
this.checkValidity();
|
|
83
|
+
if (this.hasDisplayedError) {
|
|
84
|
+
this.setErrorMessage();
|
|
85
|
+
this.hasDisplayedError = false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
82
89
|
/**
|
|
83
90
|
* Public method to display errors
|
|
84
91
|
*
|
|
@@ -86,8 +93,8 @@ export class MgInputPassword {
|
|
|
86
93
|
*/
|
|
87
94
|
async displayError() {
|
|
88
95
|
this.checkValidity();
|
|
89
|
-
this.
|
|
90
|
-
this.
|
|
96
|
+
this.setErrorMessage();
|
|
97
|
+
this.hasDisplayedError = this.invalid;
|
|
91
98
|
}
|
|
92
99
|
/*************
|
|
93
100
|
* Lifecycle *
|
|
@@ -113,7 +120,10 @@ export class MgInputPassword {
|
|
|
113
120
|
* @returns {HTMLElement} HTML Element
|
|
114
121
|
*/
|
|
115
122
|
render() {
|
|
116
|
-
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: this.mgWidth, disabled: this.disabled, value: this.value, readonlyValue: this.value !== undefined ? '•'.repeat(this.value.length) : undefined, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("input", { type: "password", class: "mg-input__box", value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, ref: el =>
|
|
123
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: this.mgWidth, disabled: this.disabled, value: this.value, readonlyValue: this.value !== undefined ? '•'.repeat(this.value.length) : undefined, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("input", { type: "password", class: "mg-input__box", value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, ref: el => {
|
|
124
|
+
if (el !== null)
|
|
125
|
+
this.input = el;
|
|
126
|
+
} })));
|
|
117
127
|
}
|
|
118
128
|
static get is() { return "mg-input-password"; }
|
|
119
129
|
static get encapsulation() { return "shadow"; }
|
|
@@ -464,6 +474,15 @@ export class MgInputPassword {
|
|
|
464
474
|
return [{
|
|
465
475
|
"propName": "value",
|
|
466
476
|
"methodName": "handleValue"
|
|
477
|
+
}, {
|
|
478
|
+
"propName": "required",
|
|
479
|
+
"methodName": "handleValidityChange"
|
|
480
|
+
}, {
|
|
481
|
+
"propName": "readonly",
|
|
482
|
+
"methodName": "handleValidityChange"
|
|
483
|
+
}, {
|
|
484
|
+
"propName": "disabled",
|
|
485
|
+
"methodName": "handleValidityChange"
|
|
467
486
|
}];
|
|
468
487
|
}
|
|
469
488
|
}
|
|
@@ -18,6 +18,8 @@ export class MgInputRadio {
|
|
|
18
18
|
************/
|
|
19
19
|
// HTML selector
|
|
20
20
|
this.inputs = [];
|
|
21
|
+
// hasDisplayedError (triggered by blur event)
|
|
22
|
+
this.hasDisplayedError = false;
|
|
21
23
|
/**
|
|
22
24
|
* Input name
|
|
23
25
|
* If not set the value equals the identifier
|
|
@@ -68,7 +70,7 @@ export class MgInputRadio {
|
|
|
68
70
|
*/
|
|
69
71
|
this.handleBlur = () => {
|
|
70
72
|
this.checkValidity();
|
|
71
|
-
this.
|
|
73
|
+
this.setErrorMessage();
|
|
72
74
|
};
|
|
73
75
|
/**
|
|
74
76
|
* Check if input is valid
|
|
@@ -76,21 +78,17 @@ export class MgInputRadio {
|
|
|
76
78
|
* @returns {void}
|
|
77
79
|
*/
|
|
78
80
|
this.checkValidity = () => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
this.invalid = !validity;
|
|
84
|
-
//Send event
|
|
85
|
-
this.inputValid.emit(validity);
|
|
86
|
-
}
|
|
81
|
+
this.valid = this.readonly || this.disabled || this.getInvalidElement() === undefined;
|
|
82
|
+
this.invalid = !this.valid;
|
|
83
|
+
// We need to send valid event even if it is the same value
|
|
84
|
+
this.inputValid.emit(this.valid);
|
|
87
85
|
};
|
|
88
86
|
/**
|
|
89
|
-
*
|
|
87
|
+
* Set input error message
|
|
90
88
|
*
|
|
91
89
|
* @returns {void}
|
|
92
90
|
*/
|
|
93
|
-
this.
|
|
91
|
+
this.setErrorMessage = () => {
|
|
94
92
|
const invalidElement = this.getInvalidElement();
|
|
95
93
|
// Set error message
|
|
96
94
|
this.errorMessage = undefined;
|
|
@@ -103,7 +101,7 @@ export class MgInputRadio {
|
|
|
103
101
|
*
|
|
104
102
|
* @returns {HTMLInputElement} element
|
|
105
103
|
*/
|
|
106
|
-
this.getInvalidElement = () => this.inputs.find((
|
|
104
|
+
this.getInvalidElement = () => this.inputs.find((input) => !input.disabled && !input.readOnly && !input.checkValidity());
|
|
107
105
|
}
|
|
108
106
|
handleValue(newValue) {
|
|
109
107
|
this.valueChange.emit(newValue);
|
|
@@ -125,6 +123,16 @@ export class MgInputRadio {
|
|
|
125
123
|
throw new Error('<mg-input-radio> prop "items" is required and all items must be the same type, string or RadioOption.');
|
|
126
124
|
}
|
|
127
125
|
}
|
|
126
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
127
|
+
this.inputs.forEach(input => {
|
|
128
|
+
input[prop] = newValue;
|
|
129
|
+
});
|
|
130
|
+
this.checkValidity();
|
|
131
|
+
if (this.hasDisplayedError) {
|
|
132
|
+
this.setErrorMessage();
|
|
133
|
+
this.hasDisplayedError = false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
128
136
|
/**
|
|
129
137
|
* Public method to display errors
|
|
130
138
|
*
|
|
@@ -132,7 +140,8 @@ export class MgInputRadio {
|
|
|
132
140
|
*/
|
|
133
141
|
async displayError() {
|
|
134
142
|
this.checkValidity();
|
|
135
|
-
this.
|
|
143
|
+
this.setErrorMessage();
|
|
144
|
+
this.hasDisplayedError = this.invalid;
|
|
136
145
|
}
|
|
137
146
|
/*************
|
|
138
147
|
* Lifecycle *
|
|
@@ -160,7 +169,10 @@ export class MgInputRadio {
|
|
|
160
169
|
* @returns {HTMLElement} HTML Element
|
|
161
170
|
*/
|
|
162
171
|
render() {
|
|
163
|
-
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, disabled: this.disabled, readonly: this.readonly, mgWidth: undefined, value: this.value, readonlyValue: this.value, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: true }, h("ul", { class: { 'mg-input__input-group-container': true, 'mg-input__input-group-container--vertical': this.inputVerticalList } }, this.options.map((input, index) => (h("li", { class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } }, h("input", { type: "radio", id: this.identifier + '_' + index, name: this.identifier, value: index, checked: JSON.stringify(this.value) === JSON.stringify(this.options[index].value), disabled: this.disabled || input.disabled, required: this.required, onBlur: this.handleBlur, onInput: this.handleInput, ref: el =>
|
|
172
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, disabled: this.disabled, readonly: this.readonly, mgWidth: undefined, value: this.value, readonlyValue: this.value, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: true }, h("ul", { class: { 'mg-input__input-group-container': true, 'mg-input__input-group-container--vertical': this.inputVerticalList } }, this.options.map((input, index) => (h("li", { class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } }, h("input", { type: "radio", id: this.identifier + '_' + index, name: this.identifier, value: index, checked: JSON.stringify(this.value) === JSON.stringify(this.options[index].value), disabled: this.disabled || input.disabled, required: this.required, onBlur: this.handleBlur, onInput: this.handleInput, ref: el => {
|
|
173
|
+
if (el !== null)
|
|
174
|
+
this.inputs[index] = el;
|
|
175
|
+
} }), h("label", { htmlFor: this.identifier + '_' + index }, input.title)))))));
|
|
164
176
|
}
|
|
165
177
|
static get is() { return "mg-input-radio"; }
|
|
166
178
|
static get encapsulation() { return "shadow"; }
|
|
@@ -514,6 +526,15 @@ export class MgInputRadio {
|
|
|
514
526
|
}, {
|
|
515
527
|
"propName": "items",
|
|
516
528
|
"methodName": "validateItems"
|
|
529
|
+
}, {
|
|
530
|
+
"propName": "required",
|
|
531
|
+
"methodName": "handleValidityChange"
|
|
532
|
+
}, {
|
|
533
|
+
"propName": "readonly",
|
|
534
|
+
"methodName": "handleValidityChange"
|
|
535
|
+
}, {
|
|
536
|
+
"propName": "disabled",
|
|
537
|
+
"methodName": "handleValidityChange"
|
|
517
538
|
}];
|
|
518
539
|
}
|
|
519
540
|
}
|
package/dist/collection/components/molecules/inputs/mg-input-select/doc/mg-input-select.stories.js
CHANGED
|
@@ -18,8 +18,7 @@ export default {
|
|
|
18
18
|
parameters: { actions: { handles: ['value-change', 'input-valid'] } },
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
* 2. boolean arguments with a default true value must be added like display-character-left={args.displayCharacterLeft ? 'true' : 'false'}
|
|
21
|
+
* Template
|
|
23
22
|
*
|
|
24
23
|
* @param {any} args component arguments
|
|
25
24
|
* @returns {HTMLElement} HTMLElement
|
|
@@ -40,7 +39,7 @@ MgInputSelect.args = {
|
|
|
40
39
|
required: true,
|
|
41
40
|
readonly: false,
|
|
42
41
|
disabled: false,
|
|
43
|
-
items: ['blu', 'bli', 'blo', '
|
|
42
|
+
items: ['blu', 'bli', 'blo', 'le long libellé qui va faire sortir le champ mg-input-select de sa zone de confort'],
|
|
44
43
|
mgWidth: undefined,
|
|
45
44
|
// Tooltip
|
|
46
45
|
tooltip: 'This is a tooltip',
|