@mgdis/mg-components 5.1.0 → 5.3.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_27.cjs.entry.js → mg-badge_29.cjs.entry.js} +730 -242
- package/dist/cjs/mg-components.cjs.js +1 -1
- package/dist/collection/collection-manifest.json +3 -1
- package/dist/collection/components/atoms/mg-badge/mg-badge.js +14 -19
- package/dist/collection/components/atoms/mg-button/mg-button.js +3 -3
- package/dist/collection/components/atoms/mg-icon/mg-icon.js +17 -7
- package/dist/collection/components/atoms/mg-tag/mg-tag.js +1 -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/menu/mg-menu/doc/mg-menu.stories.js +87 -0
- package/dist/collection/components/molecules/menu/mg-menu/mg-menu.conf.js +8 -0
- package/dist/collection/components/molecules/menu/mg-menu/mg-menu.css +10 -0
- package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js +185 -0
- package/dist/collection/components/molecules/menu/mg-menu-item/doc/mg-menu-item.stories.js +32 -0
- package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.conf.js +22 -0
- package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.css +316 -0
- package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js +324 -0
- 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.js +0 -4
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.conf.js +3 -0
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.css +67 -17
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +10 -4
- package/dist/collection/locales/index.js +3 -1
- package/dist/collection/utils/unit.test.utils.js +51 -0
- package/dist/collection/variables.css +29 -7
- package/dist/components/MgInput.js +4 -12
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/components/index2.js +3 -1
- package/dist/components/mg-badge2.js +1 -1
- package/dist/components/mg-button2.js +3 -3
- 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-menu-item.d.ts +11 -0
- package/dist/components/mg-menu-item.js +273 -0
- package/dist/components/mg-menu.conf.js +10 -0
- package/dist/components/mg-menu.d.ts +11 -0
- package/dist/components/mg-menu.js +149 -0
- package/dist/components/mg-message.js +1 -1
- package/dist/components/mg-modal.js +0 -4
- package/dist/components/mg-tabs.js +6 -2
- package/dist/components/mg-tag.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{mg-badge_27.entry.js → mg-badge_29.entry.js} +729 -243
- 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-204af46f.entry.js +1 -0
- package/dist/mg-components/variables.css +29 -7
- package/dist/types/components/atoms/mg-badge/doc/mg-badge.stories.d.ts +2 -2
- package/dist/types/components/atoms/mg-badge/mg-badge.conf.d.ts +5 -5
- package/dist/types/components/atoms/mg-badge/mg-badge.d.ts +8 -8
- package/dist/types/components/atoms/mg-button/mg-button.d.ts +2 -2
- package/dist/types/components/atoms/mg-icon/doc/mg-icon.stories.d.ts +2 -2
- package/dist/types/components/atoms/mg-icon/mg-icon.conf.d.ts +10 -2
- package/dist/types/components/atoms/mg-icon/mg-icon.d.ts +7 -6
- 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/menu/mg-menu/doc/mg-menu.stories.d.ts +17 -0
- package/dist/types/components/molecules/menu/mg-menu/mg-menu.conf.d.ts +7 -0
- package/dist/types/components/molecules/menu/mg-menu/mg-menu.d.ts +69 -0
- package/dist/types/components/molecules/menu/mg-menu-item/doc/mg-menu-item.stories.d.ts +11 -0
- package/dist/types/components/molecules/menu/mg-menu-item/mg-menu-item.conf.d.ts +24 -0
- package/dist/types/components/molecules/menu/mg-menu-item/mg-menu-item.d.ts +119 -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 +3 -0
- package/dist/types/components/molecules/mg-tabs/doc/mg-tabs.stories.d.ts +1 -1
- package/dist/types/components/molecules/mg-tabs/mg-tabs.conf.d.ts +12 -4
- package/dist/types/components/molecules/mg-tabs/mg-tabs.d.ts +6 -6
- package/dist/types/components.d.ts +91 -14
- package/dist/types/locales/index.d.ts +7 -1
- package/dist/types/stories/icons.stories.d.ts +1 -1
- package/package.json +7 -8
- package/dist/collection/utils/test.utils.js +0 -38
- package/dist/mg-components/p-e131701a.entry.js +0 -1
- package/dist/types/utils/test.utils.d.ts +0 -17
|
@@ -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',
|
|
@@ -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 {
|
|
193
199
|
width: 100%;
|
|
200
|
+
max-width: calc(17.7rem + var(--mg-inputs-spacer) * 2);
|
|
201
|
+
min-width: 5rem;
|
|
194
202
|
}
|
|
195
|
-
.mg-input.mg-input--width-16 .mg-
|
|
196
|
-
width:
|
|
203
|
+
.mg-input.mg-input--width-16 .mg-input__input-container {
|
|
204
|
+
width: 100%;
|
|
197
205
|
}
|
|
198
|
-
.mg-input.mg-input--width-
|
|
199
|
-
width:
|
|
206
|
+
.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input {
|
|
207
|
+
width: 100%;
|
|
208
|
+
max-width: 21rem;
|
|
200
209
|
}
|
|
201
|
-
.mg-input.mg-input--width-
|
|
202
|
-
width:
|
|
210
|
+
.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left {
|
|
211
|
+
width: 100%;
|
|
212
|
+
}
|
|
213
|
+
.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box {
|
|
214
|
+
max-width: 21rem;
|
|
215
|
+
min-width: 100%;
|
|
216
|
+
}
|
|
217
|
+
.mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box {
|
|
218
|
+
max-width: 7rem;
|
|
219
|
+
}
|
|
220
|
+
.mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box {
|
|
221
|
+
max-width: 5rem;
|
|
203
222
|
}
|
|
204
223
|
|
|
205
224
|
/**
|
|
@@ -228,4 +247,7 @@
|
|
|
228
247
|
padding-top: 0;
|
|
229
248
|
padding-bottom: 0;
|
|
230
249
|
padding-right: 1rem;
|
|
250
|
+
}
|
|
251
|
+
.mg-input.mg-input--select:not(.mg-input--label-on-top) .mg-input__box {
|
|
252
|
+
max-width: unset;
|
|
231
253
|
}
|
|
@@ -42,8 +42,8 @@ const groupOptions = (acc, { group, title, value, disabled }) => {
|
|
|
42
42
|
};
|
|
43
43
|
export class MgInputSelect {
|
|
44
44
|
constructor() {
|
|
45
|
-
//
|
|
46
|
-
this.
|
|
45
|
+
// hasDisplayedError (triggered by blur event)
|
|
46
|
+
this.hasDisplayedError = false;
|
|
47
47
|
/**
|
|
48
48
|
* Input name
|
|
49
49
|
* If not set the value equals the identifier
|
|
@@ -82,8 +82,8 @@ export class MgInputSelect {
|
|
|
82
82
|
*/
|
|
83
83
|
this.handleInput = () => {
|
|
84
84
|
this.checkValidity();
|
|
85
|
-
if (this.
|
|
86
|
-
this.
|
|
85
|
+
if (this.hasDisplayedError) {
|
|
86
|
+
this.setErrorMessage();
|
|
87
87
|
}
|
|
88
88
|
if (this.input.value !== '') {
|
|
89
89
|
this.value = allItemsAreString(this.items) ? this.input.value : this.items.find(item => item.title === this.input.value).value;
|
|
@@ -102,19 +102,16 @@ export class MgInputSelect {
|
|
|
102
102
|
* Check if input is valid
|
|
103
103
|
*/
|
|
104
104
|
this.checkValidity = () => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
//Send event
|
|
111
|
-
this.inputValid.emit(validity);
|
|
112
|
-
}
|
|
105
|
+
var _a;
|
|
106
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
|
|
107
|
+
this.invalid = !this.valid;
|
|
108
|
+
// We need to send valid event even if it is the same value
|
|
109
|
+
this.inputValid.emit(this.valid);
|
|
113
110
|
};
|
|
114
111
|
/**
|
|
115
|
-
*
|
|
112
|
+
* Set input error message
|
|
116
113
|
*/
|
|
117
|
-
this.
|
|
114
|
+
this.setErrorMessage = () => {
|
|
118
115
|
// Set error message
|
|
119
116
|
this.errorMessage = undefined;
|
|
120
117
|
if (!this.valid && this.input.validity.valueMissing) {
|
|
@@ -153,6 +150,16 @@ export class MgInputSelect {
|
|
|
153
150
|
throw new Error('<mg-input-select> prop "items" is required and all items must be the same type, string or Option.');
|
|
154
151
|
}
|
|
155
152
|
}
|
|
153
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
154
|
+
if (this.input !== undefined) {
|
|
155
|
+
this.input[prop] = newValue;
|
|
156
|
+
this.checkValidity();
|
|
157
|
+
if (this.hasDisplayedError) {
|
|
158
|
+
this.setErrorMessage();
|
|
159
|
+
this.hasDisplayedError = false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
156
163
|
/**
|
|
157
164
|
* Public method to display errors
|
|
158
165
|
*
|
|
@@ -160,8 +167,8 @@ export class MgInputSelect {
|
|
|
160
167
|
*/
|
|
161
168
|
async displayError() {
|
|
162
169
|
this.checkValidity();
|
|
163
|
-
this.
|
|
164
|
-
this.
|
|
170
|
+
this.setErrorMessage();
|
|
171
|
+
this.hasDisplayedError = this.invalid;
|
|
165
172
|
}
|
|
166
173
|
/*************
|
|
167
174
|
* Lifecycle *
|
|
@@ -193,7 +200,10 @@ export class MgInputSelect {
|
|
|
193
200
|
* @returns {HTMLElement} HTML Element
|
|
194
201
|
*/
|
|
195
202
|
render() {
|
|
196
|
-
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("select", { class: "mg-input__box", id: this.identifier, name: this.name, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, ref: el =>
|
|
203
|
+
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("select", { class: "mg-input__box", id: this.identifier, name: this.name, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, ref: el => {
|
|
204
|
+
if (el !== null)
|
|
205
|
+
this.input = el;
|
|
206
|
+
} }, (!this.placeholderHide || !this.valueExist) && ( // In case passed value does not match any option we display the placeholder
|
|
197
207
|
h("option", { value: "", disabled: this.placeholderDisabled && this.valueExist }, this.placeholder)), this.options.map(option => option.group !== undefined ? (h("optgroup", { label: option.group }, option.options.map(optgroup => (h("option", { value: optgroup.title, selected: JSON.stringify(this.value) === JSON.stringify(optgroup.value), disabled: optgroup.disabled }, optgroup.title))))) : (h("option", { value: option.title, selected: JSON.stringify(this.value) === JSON.stringify(option.value), disabled: option.disabled }, option.title))))));
|
|
198
208
|
}
|
|
199
209
|
static get is() { return "mg-input-select"; }
|
|
@@ -606,6 +616,15 @@ export class MgInputSelect {
|
|
|
606
616
|
}, {
|
|
607
617
|
"propName": "items",
|
|
608
618
|
"methodName": "validateItems"
|
|
619
|
+
}, {
|
|
620
|
+
"propName": "required",
|
|
621
|
+
"methodName": "handleValidityChange"
|
|
622
|
+
}, {
|
|
623
|
+
"propName": "readonly",
|
|
624
|
+
"methodName": "handleValidityChange"
|
|
625
|
+
}, {
|
|
626
|
+
"propName": "disabled",
|
|
627
|
+
"methodName": "handleValidityChange"
|
|
609
628
|
}];
|
|
610
629
|
}
|
|
611
630
|
}
|
|
@@ -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
|
/**
|