@mgdis/mg-components 5.1.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_27.cjs.entry.js +354 -236
- package/dist/cjs/mg-components.cjs.js +1 -1
- package/dist/collection/components/atoms/mg-badge/mg-badge.js +1 -1
- package/dist/collection/components/atoms/mg-button/mg-button.js +3 -3
- 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/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/utils/unit.test.utils.js +51 -0
- package/dist/collection/variables.css +6 -6
- package/dist/components/MgInput.js +4 -12
- 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-message.js +1 -1
- package/dist/components/mg-modal.js +0 -4
- package/dist/components/mg-tag.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/mg-badge_27.entry.js +354 -236
- 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 +6 -6
- package/dist/types/components/atoms/mg-button/mg-button.d.ts +2 -2
- 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-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/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
|
@@ -7,11 +7,11 @@ export class MgInputTextarea {
|
|
|
7
7
|
/************
|
|
8
8
|
* Internal *
|
|
9
9
|
************/
|
|
10
|
-
//
|
|
10
|
+
// Classes
|
|
11
11
|
this.classFocus = 'is-focused';
|
|
12
12
|
this.classHasDisplayCharacterLeft = 'mg-input--has-display-character-left';
|
|
13
|
-
//
|
|
14
|
-
this.
|
|
13
|
+
// hasDisplayedError (triggered by blur event)
|
|
14
|
+
this.hasDisplayedError = false;
|
|
15
15
|
/**
|
|
16
16
|
* Input name
|
|
17
17
|
* If not set the value equals the identifier
|
|
@@ -61,9 +61,9 @@ export class MgInputTextarea {
|
|
|
61
61
|
* Handle input event
|
|
62
62
|
*/
|
|
63
63
|
this.handleInput = () => {
|
|
64
|
-
if (this.
|
|
64
|
+
if (this.hasDisplayedError) {
|
|
65
65
|
this.checkValidity();
|
|
66
|
-
this.
|
|
66
|
+
this.setErrorMessage();
|
|
67
67
|
}
|
|
68
68
|
this.value = this.input.value;
|
|
69
69
|
};
|
|
@@ -95,19 +95,16 @@ export class MgInputTextarea {
|
|
|
95
95
|
* Check if input is valid
|
|
96
96
|
*/
|
|
97
97
|
this.checkValidity = () => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
//Send event
|
|
104
|
-
this.inputValid.emit(validity);
|
|
105
|
-
}
|
|
98
|
+
var _a;
|
|
99
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined && this.input.checkValidity() && this.getPatternValidity());
|
|
100
|
+
this.invalid = !this.valid;
|
|
101
|
+
// We need to send valid event even if it is the same value
|
|
102
|
+
this.inputValid.emit(this.valid);
|
|
106
103
|
};
|
|
107
104
|
/**
|
|
108
|
-
*
|
|
105
|
+
* Set input error message
|
|
109
106
|
*/
|
|
110
|
-
this.
|
|
107
|
+
this.setErrorMessage = () => {
|
|
111
108
|
// Set error message
|
|
112
109
|
this.errorMessage = undefined;
|
|
113
110
|
// Does not match pattern
|
|
@@ -135,6 +132,16 @@ export class MgInputTextarea {
|
|
|
135
132
|
this.checkValidity();
|
|
136
133
|
this.valueChange.emit(newValue);
|
|
137
134
|
}
|
|
135
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
136
|
+
if (this.input !== undefined) {
|
|
137
|
+
this.input[prop] = newValue;
|
|
138
|
+
this.checkValidity();
|
|
139
|
+
if (this.hasDisplayedError) {
|
|
140
|
+
this.setErrorMessage();
|
|
141
|
+
this.hasDisplayedError = false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
138
145
|
validateDisplayCharacterLeft(newValue) {
|
|
139
146
|
if (newValue) {
|
|
140
147
|
this.classList.add(this.classHasDisplayCharacterLeft);
|
|
@@ -150,8 +157,8 @@ export class MgInputTextarea {
|
|
|
150
157
|
*/
|
|
151
158
|
async displayError() {
|
|
152
159
|
this.checkValidity();
|
|
153
|
-
this.
|
|
154
|
-
this.
|
|
160
|
+
this.setErrorMessage();
|
|
161
|
+
this.hasDisplayedError = this.invalid;
|
|
155
162
|
}
|
|
156
163
|
/*************
|
|
157
164
|
* Lifecycle *
|
|
@@ -186,7 +193,10 @@ export class MgInputTextarea {
|
|
|
186
193
|
'mg-input__box--resizable': this.resizable === 'both',
|
|
187
194
|
'mg-input__box--resizable-horizontal': this.resizable === 'horizontal',
|
|
188
195
|
'mg-input__box--resizable-vertical': this.resizable === 'vertical',
|
|
189
|
-
}, value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, rows: this.rows, maxlength: this.maxlength, disabled: this.disabled, required: this.required, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el =>
|
|
196
|
+
}, value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, rows: this.rows, maxlength: this.maxlength, disabled: this.disabled, required: this.required, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el => {
|
|
197
|
+
if (el !== null)
|
|
198
|
+
this.input = el;
|
|
199
|
+
} }), this.displayCharacterLeft && this.maxlength > 0 && (h("mg-character-left", { identifier: this.characterLeftId, characters: this.value, maxlength: this.maxlength })))));
|
|
190
200
|
}
|
|
191
201
|
static get is() { return "mg-input-textarea"; }
|
|
192
202
|
static get encapsulation() { return "shadow"; }
|
|
@@ -643,6 +653,15 @@ export class MgInputTextarea {
|
|
|
643
653
|
return [{
|
|
644
654
|
"propName": "value",
|
|
645
655
|
"methodName": "handleValue"
|
|
656
|
+
}, {
|
|
657
|
+
"propName": "required",
|
|
658
|
+
"methodName": "handleValidityChange"
|
|
659
|
+
}, {
|
|
660
|
+
"propName": "readonly",
|
|
661
|
+
"methodName": "handleValidityChange"
|
|
662
|
+
}, {
|
|
663
|
+
"propName": "disabled",
|
|
664
|
+
"methodName": "handleValidityChange"
|
|
646
665
|
}, {
|
|
647
666
|
"propName": "displayCharacterLeft",
|
|
648
667
|
"methodName": "validateDisplayCharacterLeft"
|
|
@@ -15,7 +15,7 @@ export class MgInputToggle {
|
|
|
15
15
|
/************
|
|
16
16
|
* Internal *
|
|
17
17
|
************/
|
|
18
|
-
//
|
|
18
|
+
// Classes
|
|
19
19
|
this.classReadonly = 'mg-input--toggle-readonly';
|
|
20
20
|
this.classDisabled = 'mg-input--toggle-disabled';
|
|
21
21
|
this.classIsActive = 'mg-input--toggle-is-active';
|
|
@@ -3,6 +3,8 @@ import { createID, ClassList } from '../../../utils/components.utils';
|
|
|
3
3
|
import { initLocales } from '../../../locales';
|
|
4
4
|
export class MgForm {
|
|
5
5
|
constructor() {
|
|
6
|
+
// Classes
|
|
7
|
+
this.classAllRequired = 'mg-form--all-required';
|
|
6
8
|
/**
|
|
7
9
|
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
8
10
|
* If not set, it will be created.
|
|
@@ -32,17 +34,24 @@ export class MgForm {
|
|
|
32
34
|
* @returns {void}
|
|
33
35
|
*/
|
|
34
36
|
this.setRequiredMessage = () => {
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
if
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
// init required message
|
|
38
|
+
this.requiredMessage = null;
|
|
39
|
+
this.classList.delete(this.classAllRequired);
|
|
40
|
+
// If the form is disabled or readonly none of them are required
|
|
41
|
+
// Check if all fields are not editable (readonly or disabled)
|
|
42
|
+
if (!this.disabled && !this.readonly && !this.mgInputs.every(input => input.disabled || input.readonly)) {
|
|
43
|
+
// Get required fields
|
|
44
|
+
const requiredInputs = this.mgInputs.filter(input => input.required && !input.disabled && !input.readonly);
|
|
45
|
+
// All fields are required
|
|
46
|
+
// mg-input-toggle can not be required
|
|
47
|
+
if (requiredInputs.length > 0 && requiredInputs.length === this.mgInputs.filter(input => input.nodeName !== 'MG-INPUT-TOGGLE').length) {
|
|
48
|
+
this.requiredMessage = this.messages.form.allRequired;
|
|
49
|
+
this.classList.add(this.classAllRequired);
|
|
50
|
+
}
|
|
51
|
+
// Some fields are required
|
|
52
|
+
else if (requiredInputs.length > 0) {
|
|
53
|
+
this.requiredMessage = this.messages.form.required;
|
|
54
|
+
}
|
|
46
55
|
}
|
|
47
56
|
};
|
|
48
57
|
/**
|
|
@@ -51,15 +60,46 @@ export class MgForm {
|
|
|
51
60
|
* @returns {void}
|
|
52
61
|
*/
|
|
53
62
|
this.checkValidity = () => {
|
|
54
|
-
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
63
|
+
// Update required on input event
|
|
64
|
+
this.setRequiredMessage();
|
|
65
|
+
this.valid = !this.mgInputs.some(input => input.invalid);
|
|
66
|
+
this.invalid = !this.valid;
|
|
67
|
+
// We need to send valid event if it is the same value
|
|
68
|
+
this.formValid.emit(this.valid);
|
|
58
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Handle Form Submit
|
|
72
|
+
*
|
|
73
|
+
* @param {SubmitEvent} event submit event
|
|
74
|
+
* @returns {void}
|
|
75
|
+
*/
|
|
59
76
|
this.handleFormSubmit = (event) => {
|
|
60
77
|
event.preventDefault();
|
|
61
78
|
this.formSubmit.emit();
|
|
62
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* Set mgInputs
|
|
82
|
+
*
|
|
83
|
+
* @returns {void}
|
|
84
|
+
*/
|
|
85
|
+
this.setMgInputs = () => {
|
|
86
|
+
// Get slotted mgInputs
|
|
87
|
+
this.mgInputs = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-INPUT-'));
|
|
88
|
+
// Set inputs readonly or disabled based on form configuration
|
|
89
|
+
// Othewise listen to events
|
|
90
|
+
this.mgInputs.map(input => {
|
|
91
|
+
if (this.readonly)
|
|
92
|
+
input.readonly = true;
|
|
93
|
+
else if (this.disabled)
|
|
94
|
+
input.disabled = true;
|
|
95
|
+
else
|
|
96
|
+
input.addEventListener('input-valid', this.checkValidity);
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
handleAttributeChange() {
|
|
101
|
+
this.setMgInputs();
|
|
102
|
+
this.setRequiredMessage();
|
|
63
103
|
}
|
|
64
104
|
/**
|
|
65
105
|
* Public method to display errors
|
|
@@ -85,26 +125,18 @@ export class MgForm {
|
|
|
85
125
|
componentWillLoad() {
|
|
86
126
|
// Get locales
|
|
87
127
|
this.messages = initLocales(this.element).messages;
|
|
88
|
-
// Get slotted mgInputs
|
|
89
|
-
this.mgInputs = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-INPUT-'));
|
|
90
128
|
// Get slotted mgButtons
|
|
91
|
-
this.mgButtons = Array.from(this.element.querySelectorAll('
|
|
129
|
+
this.mgButtons = Array.from(this.element.querySelectorAll('mg-button'));
|
|
92
130
|
// Set button form identifier
|
|
93
131
|
this.mgButtons.forEach(mgButton => {
|
|
94
132
|
mgButton.setAttribute('form', this.identifier);
|
|
95
133
|
});
|
|
134
|
+
// Set mgInputs
|
|
135
|
+
this.setMgInputs();
|
|
96
136
|
// Define required message
|
|
97
137
|
this.setRequiredMessage();
|
|
98
138
|
// Check validity when slotted mgInputs are ready
|
|
99
139
|
Promise.all(this.mgInputs.map(async (input) => {
|
|
100
|
-
// Set inputs readonly or disabled based on form configuration
|
|
101
|
-
// Othewise listen to events
|
|
102
|
-
if (this.readonly)
|
|
103
|
-
input.readonly = true;
|
|
104
|
-
else if (this.disabled)
|
|
105
|
-
input.disabled = true;
|
|
106
|
-
else
|
|
107
|
-
input.addEventListener('input-valid', this.checkValidity);
|
|
108
140
|
try {
|
|
109
141
|
await input.componentOnReady();
|
|
110
142
|
}
|
|
@@ -127,6 +159,10 @@ export class MgForm {
|
|
|
127
159
|
});
|
|
128
160
|
}
|
|
129
161
|
});
|
|
162
|
+
// Update mgInputs when mgForm content change
|
|
163
|
+
new MutationObserver(() => {
|
|
164
|
+
this.setMgInputs();
|
|
165
|
+
}).observe(this.element, { childList: true });
|
|
130
166
|
}
|
|
131
167
|
/**
|
|
132
168
|
* Render
|
|
@@ -260,7 +296,8 @@ export class MgForm {
|
|
|
260
296
|
}
|
|
261
297
|
static get states() {
|
|
262
298
|
return {
|
|
263
|
-
"classList": {}
|
|
299
|
+
"classList": {},
|
|
300
|
+
"requiredMessage": {}
|
|
264
301
|
};
|
|
265
302
|
}
|
|
266
303
|
static get events() {
|
|
@@ -320,4 +357,13 @@ export class MgForm {
|
|
|
320
357
|
};
|
|
321
358
|
}
|
|
322
359
|
static get elementRef() { return "element"; }
|
|
360
|
+
static get watchers() {
|
|
361
|
+
return [{
|
|
362
|
+
"propName": "readonly",
|
|
363
|
+
"methodName": "handleAttributeChange"
|
|
364
|
+
}, {
|
|
365
|
+
"propName": "disabled",
|
|
366
|
+
"methodName": "handleAttributeChange"
|
|
367
|
+
}];
|
|
368
|
+
}
|
|
323
369
|
}
|
|
@@ -5,13 +5,13 @@ export default {
|
|
|
5
5
|
title: 'Molecules/mg-illustrated-message',
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Template
|
|
9
|
+
*
|
|
10
|
+
* @param {any} args component arguments
|
|
11
|
+
* @returns {HTMLElement} HTMLElement
|
|
10
12
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return (h("mg-illustrated-message", Object.assign({}, filterArgs(args, { size: 'regular', direction: 'vertical' })), h("svg", { slot: "illustration", width: "190", height: "350", viewBox: "0 0 190 350", xmlns: "http://www.w3.org/2000/svg" }, h("path", { "fill-rule": "evenodd", "clip-rule": "evenodd", d: "M0 0H15C23.2843 0 30 6.71573 30 15V290H40V15C40 6.71573 46.7157 0 55 0C63.2843 0 70 6.71573 70 15V275C70 277.761 67.7615 280 65 280H60V40H50V340H60V290H65C67.7615 290 70 292.239 70 295V340H80V295C80 291.158 78.5558 287.654 76.1805 285C78.5558 282.346 80 278.842 80 275V0H95C103.284 0 110 6.71573 110 15V25C110 28.8418 108.556 32.3462 106.181 35C108.556 37.6538 110 41.1582 110 45V305C110 307.761 107.761 310 105 310H100V45C100 42.2386 97.7615 40 95 40H90V325C90 333.284 96.7157 340 105 340H120V330H105C102.239 330 100 327.761 100 325V320H105C113.284 320 120 313.284 120 305V15C120 6.71573 126.716 0 135 0C143.284 0 150 6.71573 150 15V330H140V15C140 12.2386 137.761 10 135 10C132.239 10 130 12.2386 130 15V340H165C173.284 340 180 333.284 180 325V15C180 12.2386 177.761 10 175 10H170V325C170 327.761 167.761 330 165 330H160V0H175C183.284 0 190 6.71573 190 15V350H0V0ZM10 325C10 333.284 16.7157 340 25 340C33.2843 340 40 333.284 40 325V300H30V325C30 327.761 27.7615 330 25 330C22.2385 330 20 327.761 20 325V15C20 12.2386 17.7615 10 15 10H10V325ZM60 15V30H50V15C50 12.2386 52.2385 10 55 10C57.7615 10 60 12.2386 60 15ZM95 30H90V10H95C97.7615 10 100 12.2386 100 15V25C100 27.7614 97.7615 30 95 30Z", fill: "black" })), h("h2", { slot: "title" }, "Lorem Ipsum"), h("h3", { slot: "details" }, "The standard Lorem Ipsum passage, used since the 1500s"), h("div", { slot: "details" }, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")));
|
|
14
|
-
};
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
const Template = (args) => (h("mg-illustrated-message", Object.assign({}, filterArgs(args, { size: 'regular', direction: 'vertical' })), h("svg", { slot: "illustration", width: "190", height: "350", viewBox: "0 0 190 350", xmlns: "http://www.w3.org/2000/svg" }, h("path", { "fill-rule": "evenodd", "clip-rule": "evenodd", d: "M0 0H15C23.2843 0 30 6.71573 30 15V290H40V15C40 6.71573 46.7157 0 55 0C63.2843 0 70 6.71573 70 15V275C70 277.761 67.7615 280 65 280H60V40H50V340H60V290H65C67.7615 290 70 292.239 70 295V340H80V295C80 291.158 78.5558 287.654 76.1805 285C78.5558 282.346 80 278.842 80 275V0H95C103.284 0 110 6.71573 110 15V25C110 28.8418 108.556 32.3462 106.181 35C108.556 37.6538 110 41.1582 110 45V305C110 307.761 107.761 310 105 310H100V45C100 42.2386 97.7615 40 95 40H90V325C90 333.284 96.7157 340 105 340H120V330H105C102.239 330 100 327.761 100 325V320H105C113.284 320 120 313.284 120 305V15C120 6.71573 126.716 0 135 0C143.284 0 150 6.71573 150 15V330H140V15C140 12.2386 137.761 10 135 10C132.239 10 130 12.2386 130 15V340H165C173.284 340 180 333.284 180 325V15C180 12.2386 177.761 10 175 10H170V325C170 327.761 167.761 330 165 330H160V0H175C183.284 0 190 6.71573 190 15V350H0V0ZM10 325C10 333.284 16.7157 340 25 340C33.2843 340 40 333.284 40 325V300H30V325C30 327.761 27.7615 330 25 330C22.2385 330 20 327.761 20 325V15C20 12.2386 17.7615 10 15 10H10V325ZM60 15V30H50V15C50 12.2386 52.2385 10 55 10C57.7615 10 60 12.2386 60 15ZM95 30H90V10H95C97.7615 10 100 12.2386 100 15V25C100 27.7614 97.7615 30 95 30Z", fill: "black" })), h("h2", { slot: "title" }, "Lorem Ipsum"), h("h3", { slot: "details" }, "The standard Lorem Ipsum passage, used since the 1500s"), h("div", { slot: "details" }, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")));
|
|
15
15
|
export const MgIllustratedMessage = Template.bind({});
|
|
16
16
|
MgIllustratedMessage.args = {
|
|
17
17
|
size: 'regular',
|
|
@@ -135,10 +135,6 @@ export class MgModal {
|
|
|
135
135
|
*/
|
|
136
136
|
componentDidLoad() {
|
|
137
137
|
new MutationObserver(mutationList => {
|
|
138
|
-
/*
|
|
139
|
-
TODO find a way to cover this callback
|
|
140
|
-
*/
|
|
141
|
-
/* istanbul ignore next */
|
|
142
138
|
if (mutationList.some(mutation => mutation.attributeName === 'aria-hidden' && mutation.target.ariaHidden === null)) {
|
|
143
139
|
this.setFocus();
|
|
144
140
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clone Deep function
|
|
3
|
+
*
|
|
4
|
+
* @param {unknown} obj object to clone
|
|
5
|
+
* @returns {unknown} cloned json
|
|
6
|
+
*/
|
|
7
|
+
export const cloneDeep = (obj) => JSON.parse(JSON.stringify(obj));
|
|
8
|
+
/**
|
|
9
|
+
* Utility function that mocks the `MutationObserver` API. Recommended to execute inside `beforeEach`.
|
|
10
|
+
*
|
|
11
|
+
* @param mutationObserverMock - Parameter that is sent to the `Object.defineProperty`
|
|
12
|
+
* overwrite method. `jest.fn()` mock functions can be passed here if the goal is to not only
|
|
13
|
+
* mock the resize observer, but its methods.
|
|
14
|
+
* You can manually fire an intersection entry:
|
|
15
|
+
* @param {Function} mutationObserverMock.disconnect disconnect function
|
|
16
|
+
* @param {Function} mutationObserverMock.observe observe fnuction
|
|
17
|
+
* @param {Function} mutationObserverMock.takeRecords takeRecords fnuction
|
|
18
|
+
* @returns {MutationObserver} Mocked MutationObserver
|
|
19
|
+
* @example
|
|
20
|
+
* ```
|
|
21
|
+
* let fireMo;
|
|
22
|
+
* setupMutationObserverMock({
|
|
23
|
+
* observe: function () {
|
|
24
|
+
* fireMo = this.cb;
|
|
25
|
+
* },
|
|
26
|
+
* });
|
|
27
|
+
* ...
|
|
28
|
+
* fireMo([{ type: 'childList', addedNodes: [AMockElemenet, AnotherMockElemenet], target: yourMockElemenet }]);;
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const setupMutationObserverMock = ({ disconnect, observe, takeRecords }) => {
|
|
32
|
+
class MockMutationObserver {
|
|
33
|
+
constructor(fn) {
|
|
34
|
+
this.disconnect = disconnect;
|
|
35
|
+
this.observe = observe;
|
|
36
|
+
this.takeRecords = takeRecords;
|
|
37
|
+
this.cb = fn;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
Object.defineProperty(window, 'MutationObserver', {
|
|
41
|
+
writable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
value: MockMutationObserver,
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(global, 'MutationObserver', {
|
|
46
|
+
writable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
value: MockMutationObserver,
|
|
49
|
+
});
|
|
50
|
+
return MockMutationObserver;
|
|
51
|
+
};
|
|
@@ -77,15 +77,15 @@
|
|
|
77
77
|
--color-light: var(--color-light-h), var(--color-light-s), var(--color-light-l);
|
|
78
78
|
|
|
79
79
|
/* Primary */
|
|
80
|
-
--color-primary-h:
|
|
81
|
-
--color-primary-s:
|
|
82
|
-
--color-primary-l:
|
|
80
|
+
--color-primary-h: var(--color-dark-h);
|
|
81
|
+
--color-primary-s: var(--color-dark-s);
|
|
82
|
+
--color-primary-l: var(--color-dark-l);
|
|
83
83
|
--color-primary: hsl(var(--color-dark));
|
|
84
84
|
|
|
85
85
|
/* Secondary */
|
|
86
|
-
--color-secondary-h:
|
|
87
|
-
--color-secondary-s:
|
|
88
|
-
--color-secondary-l:
|
|
86
|
+
--color-secondary-h: var(--color-neutral-h);
|
|
87
|
+
--color-secondary-s: var(--color-neutral-s);
|
|
88
|
+
--color-secondary-l: var(--color-neutral-l);
|
|
89
89
|
--color-secondary: hsl(var(--color-neutral));
|
|
90
90
|
|
|
91
91
|
/* Shadow */
|
|
@@ -77,15 +77,6 @@ const MgInput = (props, children, utils) => {
|
|
|
77
77
|
if (typeof props.errorMessage === 'string' && props.errorMessage !== '') {
|
|
78
78
|
ariaDescribedbyIDs.add(helpTextErrorId);
|
|
79
79
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Update input(s) in children
|
|
82
|
-
*/
|
|
83
|
-
if (props.readonly) {
|
|
84
|
-
children = children.filter(child => child.$name$ === 'append-input');
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
children = applyAriadescribedBy(children, ariaDescribedbyIDs, utils);
|
|
88
|
-
}
|
|
89
80
|
/**
|
|
90
81
|
* Return template
|
|
91
82
|
*
|
|
@@ -111,19 +102,20 @@ const MgInput = (props, children, utils) => {
|
|
|
111
102
|
h("mg-icon", { icon: "info-circle" })));
|
|
112
103
|
/**
|
|
113
104
|
* Get input title (label) node
|
|
105
|
+
* Display asterisk only if not disabled and not readonly
|
|
114
106
|
*
|
|
115
107
|
* @returns {VNode[]} mg-input-title
|
|
116
108
|
*/
|
|
117
|
-
const getInputTitle = () => (h("mg-input-title", { identifier: props.identifier, class: props.labelHide ? 'sr-only' : undefined, required: props.required && !props.disabled, "is-legend": props.isFieldset }, props.label));
|
|
109
|
+
const getInputTitle = () => (h("mg-input-title", { identifier: props.identifier, class: props.labelHide ? 'sr-only' : undefined, required: props.required && !props.disabled && !props.readonly, "is-legend": props.isFieldset }, props.label));
|
|
118
110
|
return (h(TagName, { class: props.classList.join() },
|
|
119
111
|
props.labelOnTop ? (h("div", { class: "mg-input__title" },
|
|
120
112
|
getInputTitle(),
|
|
121
113
|
!props.readonly && props.tooltip && getTooltip())) : (getInputTitle()),
|
|
122
114
|
props.readonly ? (h("div", { class: "mg-input__input-container" },
|
|
123
115
|
h("strong", null, props.readonlyValue || props.value),
|
|
124
|
-
children)) : (h("div", { class: "mg-input__input-container" },
|
|
116
|
+
children.filter(child => child.$name$ === 'append-input'))) : (h("div", { class: "mg-input__input-container" },
|
|
125
117
|
h("div", { class: { 'mg-input__input': true, 'mg-input__input--has-error': props.errorMessage !== undefined } },
|
|
126
|
-
children,
|
|
118
|
+
applyAriadescribedBy(children, ariaDescribedbyIDs, utils),
|
|
127
119
|
!props.labelOnTop && props.tooltip && getTooltip()),
|
|
128
120
|
props.helpText && h("div", { id: helpTextId, class: "mg-input__help-text", innerHTML: props.helpText }),
|
|
129
121
|
props.errorMessage && !props.readonly && !props.disabled && (h("div", { id: helpTextErrorId, class: "mg-input__error", innerHTML: props.errorMessage, "aria-live": "assertive" }))))));
|
|
@@ -65,7 +65,7 @@ const MgButton = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
/**
|
|
68
|
-
* Handle
|
|
68
|
+
* Handle onKeydown event
|
|
69
69
|
*
|
|
70
70
|
* @param {KeyboardEvent} event keyboard event
|
|
71
71
|
* @returns {void}
|
|
@@ -80,7 +80,7 @@ const MgButton = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
/**
|
|
83
|
-
* Handle
|
|
83
|
+
* Handle onKeyup event
|
|
84
84
|
*
|
|
85
85
|
* @param {KeyboardEvent} event keyboard event
|
|
86
86
|
* @returns {void}
|
|
@@ -163,7 +163,7 @@ const MgButton = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
163
163
|
* @returns {HTMLElement} html element
|
|
164
164
|
*/
|
|
165
165
|
render() {
|
|
166
|
-
return (h(Host, { role: "button", tabIndex: this.disabled ? -1 : 0, type: this.type, form: this.form, "full-width": this.fullWidth, "aria-label": this.label, "aria-disabled": this.disabled !== undefined && this.disabled.toString(), onClick: this.handleClick,
|
|
166
|
+
return (h(Host, { role: "button", tabIndex: this.disabled ? -1 : 0, type: this.type, form: this.form, "full-width": this.fullWidth, "aria-label": this.label, "aria-disabled": this.disabled !== undefined && this.disabled.toString(), onClick: this.handleClick, onKeyup: this.handleKeyup, onKeydown: this.handleKeydown }, h("div", { class: this.classList.join(), id: this.identifier }, this.loading && h("mg-icon", { icon: "loader", spin: true }), h("div", { class: "mg-button__content" }, h("slot", null)))));
|
|
167
167
|
}
|
|
168
168
|
get element() { return this; }
|
|
169
169
|
static get watchers() { return {
|
|
@@ -11,6 +11,8 @@ const MgForm$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
11
11
|
this.__attachShadow();
|
|
12
12
|
this.formValid = createEvent(this, "form-valid", 7);
|
|
13
13
|
this.formSubmit = createEvent(this, "form-submit", 7);
|
|
14
|
+
// Classes
|
|
15
|
+
this.classAllRequired = 'mg-form--all-required';
|
|
14
16
|
/**
|
|
15
17
|
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
16
18
|
* If not set, it will be created.
|
|
@@ -40,17 +42,24 @@ const MgForm$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
40
42
|
* @returns {void}
|
|
41
43
|
*/
|
|
42
44
|
this.setRequiredMessage = () => {
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
//
|
|
47
|
-
if
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
// init required message
|
|
46
|
+
this.requiredMessage = null;
|
|
47
|
+
this.classList.delete(this.classAllRequired);
|
|
48
|
+
// If the form is disabled or readonly none of them are required
|
|
49
|
+
// Check if all fields are not editable (readonly or disabled)
|
|
50
|
+
if (!this.disabled && !this.readonly && !this.mgInputs.every(input => input.disabled || input.readonly)) {
|
|
51
|
+
// Get required fields
|
|
52
|
+
const requiredInputs = this.mgInputs.filter(input => input.required && !input.disabled && !input.readonly);
|
|
53
|
+
// All fields are required
|
|
54
|
+
// mg-input-toggle can not be required
|
|
55
|
+
if (requiredInputs.length > 0 && requiredInputs.length === this.mgInputs.filter(input => input.nodeName !== 'MG-INPUT-TOGGLE').length) {
|
|
56
|
+
this.requiredMessage = this.messages.form.allRequired;
|
|
57
|
+
this.classList.add(this.classAllRequired);
|
|
58
|
+
}
|
|
59
|
+
// Some fields are required
|
|
60
|
+
else if (requiredInputs.length > 0) {
|
|
61
|
+
this.requiredMessage = this.messages.form.required;
|
|
62
|
+
}
|
|
54
63
|
}
|
|
55
64
|
};
|
|
56
65
|
/**
|
|
@@ -59,15 +68,46 @@ const MgForm$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
59
68
|
* @returns {void}
|
|
60
69
|
*/
|
|
61
70
|
this.checkValidity = () => {
|
|
62
|
-
|
|
63
|
-
this.
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
71
|
+
// Update required on input event
|
|
72
|
+
this.setRequiredMessage();
|
|
73
|
+
this.valid = !this.mgInputs.some(input => input.invalid);
|
|
74
|
+
this.invalid = !this.valid;
|
|
75
|
+
// We need to send valid event if it is the same value
|
|
76
|
+
this.formValid.emit(this.valid);
|
|
66
77
|
};
|
|
78
|
+
/**
|
|
79
|
+
* Handle Form Submit
|
|
80
|
+
*
|
|
81
|
+
* @param {SubmitEvent} event submit event
|
|
82
|
+
* @returns {void}
|
|
83
|
+
*/
|
|
67
84
|
this.handleFormSubmit = (event) => {
|
|
68
85
|
event.preventDefault();
|
|
69
86
|
this.formSubmit.emit();
|
|
70
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* Set mgInputs
|
|
90
|
+
*
|
|
91
|
+
* @returns {void}
|
|
92
|
+
*/
|
|
93
|
+
this.setMgInputs = () => {
|
|
94
|
+
// Get slotted mgInputs
|
|
95
|
+
this.mgInputs = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-INPUT-'));
|
|
96
|
+
// Set inputs readonly or disabled based on form configuration
|
|
97
|
+
// Othewise listen to events
|
|
98
|
+
this.mgInputs.map(input => {
|
|
99
|
+
if (this.readonly)
|
|
100
|
+
input.readonly = true;
|
|
101
|
+
else if (this.disabled)
|
|
102
|
+
input.disabled = true;
|
|
103
|
+
else
|
|
104
|
+
input.addEventListener('input-valid', this.checkValidity);
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
handleAttributeChange() {
|
|
109
|
+
this.setMgInputs();
|
|
110
|
+
this.setRequiredMessage();
|
|
71
111
|
}
|
|
72
112
|
/**
|
|
73
113
|
* Public method to display errors
|
|
@@ -93,26 +133,18 @@ const MgForm$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
93
133
|
componentWillLoad() {
|
|
94
134
|
// Get locales
|
|
95
135
|
this.messages = initLocales(this.element).messages;
|
|
96
|
-
// Get slotted mgInputs
|
|
97
|
-
this.mgInputs = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-INPUT-'));
|
|
98
136
|
// Get slotted mgButtons
|
|
99
|
-
this.mgButtons = Array.from(this.element.querySelectorAll('
|
|
137
|
+
this.mgButtons = Array.from(this.element.querySelectorAll('mg-button'));
|
|
100
138
|
// Set button form identifier
|
|
101
139
|
this.mgButtons.forEach(mgButton => {
|
|
102
140
|
mgButton.setAttribute('form', this.identifier);
|
|
103
141
|
});
|
|
142
|
+
// Set mgInputs
|
|
143
|
+
this.setMgInputs();
|
|
104
144
|
// Define required message
|
|
105
145
|
this.setRequiredMessage();
|
|
106
146
|
// Check validity when slotted mgInputs are ready
|
|
107
147
|
Promise.all(this.mgInputs.map(async (input) => {
|
|
108
|
-
// Set inputs readonly or disabled based on form configuration
|
|
109
|
-
// Othewise listen to events
|
|
110
|
-
if (this.readonly)
|
|
111
|
-
input.readonly = true;
|
|
112
|
-
else if (this.disabled)
|
|
113
|
-
input.disabled = true;
|
|
114
|
-
else
|
|
115
|
-
input.addEventListener('input-valid', this.checkValidity);
|
|
116
148
|
try {
|
|
117
149
|
await input.componentOnReady();
|
|
118
150
|
}
|
|
@@ -135,6 +167,10 @@ const MgForm$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
135
167
|
});
|
|
136
168
|
}
|
|
137
169
|
});
|
|
170
|
+
// Update mgInputs when mgForm content change
|
|
171
|
+
new MutationObserver(() => {
|
|
172
|
+
this.setMgInputs();
|
|
173
|
+
}).observe(this.element, { childList: true });
|
|
138
174
|
}
|
|
139
175
|
/**
|
|
140
176
|
* Render
|
|
@@ -145,6 +181,10 @@ const MgForm$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
145
181
|
return (h("form", { class: this.classList.join(), id: this.identifier, name: this.name, ref: el => (this.form = el), onSubmit: this.handleFormSubmit }, this.requiredMessage && h("p", { innerHTML: this.requiredMessage }), h("slot", null), !this.readonly && !this.disabled && h("slot", { name: "actions" })));
|
|
146
182
|
}
|
|
147
183
|
get element() { return this; }
|
|
184
|
+
static get watchers() { return {
|
|
185
|
+
"readonly": ["handleAttributeChange"],
|
|
186
|
+
"disabled": ["handleAttributeChange"]
|
|
187
|
+
}; }
|
|
148
188
|
static get style() { return mgFormCss; }
|
|
149
189
|
}, [1, "mg-form", {
|
|
150
190
|
"identifier": [1],
|
|
@@ -154,6 +194,7 @@ const MgForm$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
154
194
|
"valid": [1028],
|
|
155
195
|
"invalid": [1028],
|
|
156
196
|
"classList": [32],
|
|
197
|
+
"requiredMessage": [32],
|
|
157
198
|
"displayError": [64]
|
|
158
199
|
}]);
|
|
159
200
|
function defineCustomElement$1() {
|