@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
|
@@ -102,7 +102,7 @@ const MgBadge = class {
|
|
|
102
102
|
/************
|
|
103
103
|
* Internal *
|
|
104
104
|
************/
|
|
105
|
-
//
|
|
105
|
+
// Classes
|
|
106
106
|
this.classOutline = `mg-badge--outline`;
|
|
107
107
|
/**
|
|
108
108
|
* Define button variant
|
|
@@ -229,7 +229,7 @@ const MgButton = class {
|
|
|
229
229
|
}
|
|
230
230
|
};
|
|
231
231
|
/**
|
|
232
|
-
* Handle
|
|
232
|
+
* Handle onKeydown event
|
|
233
233
|
*
|
|
234
234
|
* @param {KeyboardEvent} event keyboard event
|
|
235
235
|
* @returns {void}
|
|
@@ -244,7 +244,7 @@ const MgButton = class {
|
|
|
244
244
|
}
|
|
245
245
|
};
|
|
246
246
|
/**
|
|
247
|
-
* Handle
|
|
247
|
+
* Handle onKeyup event
|
|
248
248
|
*
|
|
249
249
|
* @param {KeyboardEvent} event keyboard event
|
|
250
250
|
* @returns {void}
|
|
@@ -327,7 +327,7 @@ const MgButton = class {
|
|
|
327
327
|
* @returns {HTMLElement} html element
|
|
328
328
|
*/
|
|
329
329
|
render() {
|
|
330
|
-
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,
|
|
330
|
+
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)))));
|
|
331
331
|
}
|
|
332
332
|
get element() { return getElement(this); }
|
|
333
333
|
static get watchers() { return {
|
|
@@ -489,7 +489,9 @@ const messages = { en, fr };
|
|
|
489
489
|
*/
|
|
490
490
|
const getLocale = (element) => {
|
|
491
491
|
var _a;
|
|
492
|
-
|
|
492
|
+
// validate locale
|
|
493
|
+
const closestLang = Intl.NumberFormat.supportedLocalesOf((_a = element.closest('[lang]')) === null || _a === void 0 ? void 0 : _a.lang);
|
|
494
|
+
return closestLang.length > 0 ? closestLang[0] : navigator.language || defaultLocale;
|
|
493
495
|
};
|
|
494
496
|
/**
|
|
495
497
|
* Get Intl object
|
|
@@ -646,6 +648,8 @@ const MgForm = class {
|
|
|
646
648
|
registerInstance(this, hostRef);
|
|
647
649
|
this.formValid = createEvent(this, "form-valid", 7);
|
|
648
650
|
this.formSubmit = createEvent(this, "form-submit", 7);
|
|
651
|
+
// Classes
|
|
652
|
+
this.classAllRequired = 'mg-form--all-required';
|
|
649
653
|
/**
|
|
650
654
|
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
651
655
|
* If not set, it will be created.
|
|
@@ -675,17 +679,24 @@ const MgForm = class {
|
|
|
675
679
|
* @returns {void}
|
|
676
680
|
*/
|
|
677
681
|
this.setRequiredMessage = () => {
|
|
678
|
-
//
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
//
|
|
682
|
-
if
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
682
|
+
// init required message
|
|
683
|
+
this.requiredMessage = null;
|
|
684
|
+
this.classList.delete(this.classAllRequired);
|
|
685
|
+
// If the form is disabled or readonly none of them are required
|
|
686
|
+
// Check if all fields are not editable (readonly or disabled)
|
|
687
|
+
if (!this.disabled && !this.readonly && !this.mgInputs.every(input => input.disabled || input.readonly)) {
|
|
688
|
+
// Get required fields
|
|
689
|
+
const requiredInputs = this.mgInputs.filter(input => input.required && !input.disabled && !input.readonly);
|
|
690
|
+
// All fields are required
|
|
691
|
+
// mg-input-toggle can not be required
|
|
692
|
+
if (requiredInputs.length > 0 && requiredInputs.length === this.mgInputs.filter(input => input.nodeName !== 'MG-INPUT-TOGGLE').length) {
|
|
693
|
+
this.requiredMessage = this.messages.form.allRequired;
|
|
694
|
+
this.classList.add(this.classAllRequired);
|
|
695
|
+
}
|
|
696
|
+
// Some fields are required
|
|
697
|
+
else if (requiredInputs.length > 0) {
|
|
698
|
+
this.requiredMessage = this.messages.form.required;
|
|
699
|
+
}
|
|
689
700
|
}
|
|
690
701
|
};
|
|
691
702
|
/**
|
|
@@ -694,15 +705,46 @@ const MgForm = class {
|
|
|
694
705
|
* @returns {void}
|
|
695
706
|
*/
|
|
696
707
|
this.checkValidity = () => {
|
|
697
|
-
|
|
698
|
-
this.
|
|
699
|
-
this.
|
|
700
|
-
this.
|
|
708
|
+
// Update required on input event
|
|
709
|
+
this.setRequiredMessage();
|
|
710
|
+
this.valid = !this.mgInputs.some(input => input.invalid);
|
|
711
|
+
this.invalid = !this.valid;
|
|
712
|
+
// We need to send valid event if it is the same value
|
|
713
|
+
this.formValid.emit(this.valid);
|
|
701
714
|
};
|
|
715
|
+
/**
|
|
716
|
+
* Handle Form Submit
|
|
717
|
+
*
|
|
718
|
+
* @param {SubmitEvent} event submit event
|
|
719
|
+
* @returns {void}
|
|
720
|
+
*/
|
|
702
721
|
this.handleFormSubmit = (event) => {
|
|
703
722
|
event.preventDefault();
|
|
704
723
|
this.formSubmit.emit();
|
|
705
724
|
};
|
|
725
|
+
/**
|
|
726
|
+
* Set mgInputs
|
|
727
|
+
*
|
|
728
|
+
* @returns {void}
|
|
729
|
+
*/
|
|
730
|
+
this.setMgInputs = () => {
|
|
731
|
+
// Get slotted mgInputs
|
|
732
|
+
this.mgInputs = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-INPUT-'));
|
|
733
|
+
// Set inputs readonly or disabled based on form configuration
|
|
734
|
+
// Othewise listen to events
|
|
735
|
+
this.mgInputs.map(input => {
|
|
736
|
+
if (this.readonly)
|
|
737
|
+
input.readonly = true;
|
|
738
|
+
else if (this.disabled)
|
|
739
|
+
input.disabled = true;
|
|
740
|
+
else
|
|
741
|
+
input.addEventListener('input-valid', this.checkValidity);
|
|
742
|
+
});
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
handleAttributeChange() {
|
|
746
|
+
this.setMgInputs();
|
|
747
|
+
this.setRequiredMessage();
|
|
706
748
|
}
|
|
707
749
|
/**
|
|
708
750
|
* Public method to display errors
|
|
@@ -728,26 +770,18 @@ const MgForm = class {
|
|
|
728
770
|
componentWillLoad() {
|
|
729
771
|
// Get locales
|
|
730
772
|
this.messages = initLocales(this.element).messages;
|
|
731
|
-
// Get slotted mgInputs
|
|
732
|
-
this.mgInputs = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-INPUT-'));
|
|
733
773
|
// Get slotted mgButtons
|
|
734
|
-
this.mgButtons = Array.from(this.element.querySelectorAll('
|
|
774
|
+
this.mgButtons = Array.from(this.element.querySelectorAll('mg-button'));
|
|
735
775
|
// Set button form identifier
|
|
736
776
|
this.mgButtons.forEach(mgButton => {
|
|
737
777
|
mgButton.setAttribute('form', this.identifier);
|
|
738
778
|
});
|
|
779
|
+
// Set mgInputs
|
|
780
|
+
this.setMgInputs();
|
|
739
781
|
// Define required message
|
|
740
782
|
this.setRequiredMessage();
|
|
741
783
|
// Check validity when slotted mgInputs are ready
|
|
742
784
|
Promise.all(this.mgInputs.map(async (input) => {
|
|
743
|
-
// Set inputs readonly or disabled based on form configuration
|
|
744
|
-
// Othewise listen to events
|
|
745
|
-
if (this.readonly)
|
|
746
|
-
input.readonly = true;
|
|
747
|
-
else if (this.disabled)
|
|
748
|
-
input.disabled = true;
|
|
749
|
-
else
|
|
750
|
-
input.addEventListener('input-valid', this.checkValidity);
|
|
751
785
|
try {
|
|
752
786
|
await input.componentOnReady();
|
|
753
787
|
}
|
|
@@ -770,6 +804,10 @@ const MgForm = class {
|
|
|
770
804
|
});
|
|
771
805
|
}
|
|
772
806
|
});
|
|
807
|
+
// Update mgInputs when mgForm content change
|
|
808
|
+
new MutationObserver(() => {
|
|
809
|
+
this.setMgInputs();
|
|
810
|
+
}).observe(this.element, { childList: true });
|
|
773
811
|
}
|
|
774
812
|
/**
|
|
775
813
|
* Render
|
|
@@ -780,6 +818,10 @@ const MgForm = class {
|
|
|
780
818
|
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" })));
|
|
781
819
|
}
|
|
782
820
|
get element() { return getElement(this); }
|
|
821
|
+
static get watchers() { return {
|
|
822
|
+
"readonly": ["handleAttributeChange"],
|
|
823
|
+
"disabled": ["handleAttributeChange"]
|
|
824
|
+
}; }
|
|
783
825
|
};
|
|
784
826
|
MgForm.style = mgFormCss;
|
|
785
827
|
|
|
@@ -942,7 +984,7 @@ const icons = {
|
|
|
942
984
|
/**
|
|
943
985
|
* List of all possibles sizes
|
|
944
986
|
*/
|
|
945
|
-
const sizes$
|
|
987
|
+
const sizes$2 = ['small', 'regular', 'large', 'extra-large'];
|
|
946
988
|
/**
|
|
947
989
|
* List of all possibles variants
|
|
948
990
|
*/
|
|
@@ -984,8 +1026,8 @@ const MgIcon = class {
|
|
|
984
1026
|
}
|
|
985
1027
|
}
|
|
986
1028
|
validateSize(newValue, oldValue) {
|
|
987
|
-
if (!sizes$
|
|
988
|
-
throw new Error(`<mg-icon> prop "size" must be one of : ${sizes$
|
|
1029
|
+
if (!sizes$2.includes(newValue)) {
|
|
1030
|
+
throw new Error(`<mg-icon> prop "size" must be one of : ${sizes$2.join(', ')}`);
|
|
989
1031
|
}
|
|
990
1032
|
else {
|
|
991
1033
|
if (oldValue !== undefined) {
|
|
@@ -1168,15 +1210,6 @@ const MgInput = (props, children, utils) => {
|
|
|
1168
1210
|
if (typeof props.errorMessage === 'string' && props.errorMessage !== '') {
|
|
1169
1211
|
ariaDescribedbyIDs.add(helpTextErrorId);
|
|
1170
1212
|
}
|
|
1171
|
-
/**
|
|
1172
|
-
* Update input(s) in children
|
|
1173
|
-
*/
|
|
1174
|
-
if (props.readonly) {
|
|
1175
|
-
children = children.filter(child => child.$name$ === 'append-input');
|
|
1176
|
-
}
|
|
1177
|
-
else {
|
|
1178
|
-
children = applyAriadescribedBy(children, ariaDescribedbyIDs, utils);
|
|
1179
|
-
}
|
|
1180
1213
|
/**
|
|
1181
1214
|
* Return template
|
|
1182
1215
|
*
|
|
@@ -1202,19 +1235,20 @@ const MgInput = (props, children, utils) => {
|
|
|
1202
1235
|
h("mg-icon", { icon: "info-circle" })));
|
|
1203
1236
|
/**
|
|
1204
1237
|
* Get input title (label) node
|
|
1238
|
+
* Display asterisk only if not disabled and not readonly
|
|
1205
1239
|
*
|
|
1206
1240
|
* @returns {VNode[]} mg-input-title
|
|
1207
1241
|
*/
|
|
1208
|
-
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));
|
|
1242
|
+
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));
|
|
1209
1243
|
return (h(TagName, { class: props.classList.join() },
|
|
1210
1244
|
props.labelOnTop ? (h("div", { class: "mg-input__title" },
|
|
1211
1245
|
getInputTitle(),
|
|
1212
1246
|
!props.readonly && props.tooltip && getTooltip())) : (getInputTitle()),
|
|
1213
1247
|
props.readonly ? (h("div", { class: "mg-input__input-container" },
|
|
1214
1248
|
h("strong", null, props.readonlyValue || props.value),
|
|
1215
|
-
children)) : (h("div", { class: "mg-input__input-container" },
|
|
1249
|
+
children.filter(child => child.$name$ === 'append-input'))) : (h("div", { class: "mg-input__input-container" },
|
|
1216
1250
|
h("div", { class: { 'mg-input__input': true, 'mg-input__input--has-error': props.errorMessage !== undefined } },
|
|
1217
|
-
children,
|
|
1251
|
+
applyAriadescribedBy(children, ariaDescribedbyIDs, utils),
|
|
1218
1252
|
!props.labelOnTop && props.tooltip && getTooltip()),
|
|
1219
1253
|
props.helpText && h("div", { id: helpTextId, class: "mg-input__help-text", innerHTML: props.helpText }),
|
|
1220
1254
|
props.errorMessage && !props.readonly && !props.disabled && (h("div", { id: helpTextErrorId, class: "mg-input__error", innerHTML: props.errorMessage, "aria-live": "assertive" }))))));
|
|
@@ -1239,6 +1273,8 @@ const MgInputCheckbox = class {
|
|
|
1239
1273
|
************/
|
|
1240
1274
|
// HTML selector
|
|
1241
1275
|
this.inputs = [];
|
|
1276
|
+
// hasDisplayedError (triggered by blur event)
|
|
1277
|
+
this.hasDisplayedError = false;
|
|
1242
1278
|
/**
|
|
1243
1279
|
* Input name
|
|
1244
1280
|
* If not set the value equals the identifier
|
|
@@ -1293,25 +1329,27 @@ const MgInputCheckbox = class {
|
|
|
1293
1329
|
this.handleBlur = () => {
|
|
1294
1330
|
// Check validity
|
|
1295
1331
|
this.checkValidity();
|
|
1296
|
-
this.
|
|
1332
|
+
this.setErrorMessage();
|
|
1297
1333
|
};
|
|
1334
|
+
/**
|
|
1335
|
+
* get invalid element
|
|
1336
|
+
*
|
|
1337
|
+
* @returns {HTMLInputElement} element
|
|
1338
|
+
*/
|
|
1339
|
+
this.getInvalidElement = () => this.inputs.find((input) => input !== null && !input.disabled && !input.checkValidity());
|
|
1298
1340
|
/**
|
|
1299
1341
|
* Check if input is valid
|
|
1300
1342
|
*/
|
|
1301
1343
|
this.checkValidity = () => {
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
this.invalid = !validity;
|
|
1307
|
-
//Send event
|
|
1308
|
-
this.inputValid.emit(validity);
|
|
1309
|
-
}
|
|
1344
|
+
this.valid = this.readonly || this.disabled || this.getInvalidElement() === undefined;
|
|
1345
|
+
this.invalid = !this.valid;
|
|
1346
|
+
// We need to send valid event even if it is the same value
|
|
1347
|
+
this.inputValid.emit(this.valid);
|
|
1310
1348
|
};
|
|
1311
1349
|
/**
|
|
1312
|
-
*
|
|
1350
|
+
* Set input error message
|
|
1313
1351
|
*/
|
|
1314
|
-
this.
|
|
1352
|
+
this.setErrorMessage = () => {
|
|
1315
1353
|
const invalidElement = this.getInvalidElement();
|
|
1316
1354
|
// Set error message
|
|
1317
1355
|
this.errorMessage = undefined;
|
|
@@ -1319,12 +1357,6 @@ const MgInputCheckbox = class {
|
|
|
1319
1357
|
this.errorMessage = this.messages.errors.required;
|
|
1320
1358
|
}
|
|
1321
1359
|
};
|
|
1322
|
-
/**
|
|
1323
|
-
* get invalid element
|
|
1324
|
-
*
|
|
1325
|
-
* @returns {HTMLInputElement} element
|
|
1326
|
-
*/
|
|
1327
|
-
this.getInvalidElement = () => this.inputs.find((element) => !element.disabled && !element.checkValidity());
|
|
1328
1360
|
}
|
|
1329
1361
|
validateValue(newValue) {
|
|
1330
1362
|
if (newValue && newValue.every(item => isCheckboxItem(item))) {
|
|
@@ -1340,6 +1372,16 @@ const MgInputCheckbox = class {
|
|
|
1340
1372
|
throw new Error('<mg-input-checkbox> prop "value" is required and all values must be the same type, CheckboxItem.');
|
|
1341
1373
|
}
|
|
1342
1374
|
}
|
|
1375
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
1376
|
+
this.inputs.forEach(input => {
|
|
1377
|
+
input[prop] = newValue;
|
|
1378
|
+
});
|
|
1379
|
+
this.checkValidity();
|
|
1380
|
+
if (this.hasDisplayedError) {
|
|
1381
|
+
this.setErrorMessage();
|
|
1382
|
+
this.hasDisplayedError = false;
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1343
1385
|
/**
|
|
1344
1386
|
* Public method to display errors
|
|
1345
1387
|
*
|
|
@@ -1347,7 +1389,8 @@ const MgInputCheckbox = class {
|
|
|
1347
1389
|
*/
|
|
1348
1390
|
async displayError() {
|
|
1349
1391
|
this.checkValidity();
|
|
1350
|
-
this.
|
|
1392
|
+
this.setErrorMessage();
|
|
1393
|
+
this.hasDisplayedError = this.invalid;
|
|
1351
1394
|
}
|
|
1352
1395
|
/*************
|
|
1353
1396
|
* Lifecycle *
|
|
@@ -1375,15 +1418,21 @@ const MgInputCheckbox = class {
|
|
|
1375
1418
|
* @returns {HTMLElement} HTML Element
|
|
1376
1419
|
*/
|
|
1377
1420
|
render() {
|
|
1378
|
-
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: undefined, mgWidth: undefined, disabled: this.disabled, value: this.value && this.value.toString(), readonlyValue: undefined, tooltip: !this.readonly
|
|
1421
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: !this.readonly ? this.required : undefined, readonly: undefined, mgWidth: undefined, disabled: this.disabled, value: this.value && this.value.toString(), readonlyValue: undefined, tooltip: !this.readonly ? this.tooltip : undefined, helpText: !this.readonly ? this.helpText : undefined, errorMessage: !this.readonly ? this.errorMessage : undefined, isFieldset: true }, h("ul", { class: { 'mg-input__input-group-container': true, 'mg-input__input-group-container--vertical': this.inputVerticalList } }, this.checkboxItems
|
|
1379
1422
|
.filter(item => {
|
|
1380
1423
|
return !this.readonly || item.value;
|
|
1381
1424
|
})
|
|
1382
|
-
.map(input => (h("li", { class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } }, h("input", { type: "checkbox", id: input.id, name: this.identifier, value: input.value && input.value.toString(), checked: Boolean(input.value), disabled: this.readonly || this.disabled || input.disabled, required: this.required, indeterminate: input.value === null, onInput: this.handleInput, onBlur: this.handleBlur, ref: el =>
|
|
1425
|
+
.map((input, index) => (h("li", { class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } }, h("input", { type: "checkbox", id: input.id, name: this.identifier, value: input.value && input.value.toString(), checked: Boolean(input.value), disabled: this.readonly || this.disabled || input.disabled, required: this.required, indeterminate: input.value === null, onInput: this.handleInput, onBlur: this.handleBlur, ref: el => {
|
|
1426
|
+
if (el !== null)
|
|
1427
|
+
this.inputs[index] = el;
|
|
1428
|
+
} }), h("label", { htmlFor: input.id }, input.title)))))));
|
|
1383
1429
|
}
|
|
1384
1430
|
get element() { return getElement(this); }
|
|
1385
1431
|
static get watchers() { return {
|
|
1386
|
-
"value": ["validateValue"]
|
|
1432
|
+
"value": ["validateValue"],
|
|
1433
|
+
"required": ["handleValidityChange"],
|
|
1434
|
+
"readonly": ["handleValidityChange"],
|
|
1435
|
+
"disabled": ["handleValidityChange"]
|
|
1387
1436
|
}; }
|
|
1388
1437
|
};
|
|
1389
1438
|
MgInputCheckbox.style = mgInputCheckboxCss;
|
|
@@ -1442,8 +1491,8 @@ const MgInputDate = class {
|
|
|
1442
1491
|
registerInstance(this, hostRef);
|
|
1443
1492
|
this.valueChange = createEvent(this, "value-change", 7);
|
|
1444
1493
|
this.inputValid = createEvent(this, "input-valid", 7);
|
|
1445
|
-
//
|
|
1446
|
-
this.
|
|
1494
|
+
// hasDisplayedError (triggered by blur event)
|
|
1495
|
+
this.hasDisplayedError = false;
|
|
1447
1496
|
/**
|
|
1448
1497
|
* Input name
|
|
1449
1498
|
* If not set the value equals the identifier
|
|
@@ -1474,8 +1523,8 @@ const MgInputDate = class {
|
|
|
1474
1523
|
*/
|
|
1475
1524
|
this.handleInput = () => {
|
|
1476
1525
|
this.checkValidity();
|
|
1477
|
-
if (this.
|
|
1478
|
-
this.
|
|
1526
|
+
if (this.hasDisplayedError) {
|
|
1527
|
+
this.setErrorMessage();
|
|
1479
1528
|
}
|
|
1480
1529
|
this.value = this.input.value;
|
|
1481
1530
|
};
|
|
@@ -1489,14 +1538,11 @@ const MgInputDate = class {
|
|
|
1489
1538
|
* Check if input is valid
|
|
1490
1539
|
*/
|
|
1491
1540
|
this.checkValidity = () => {
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
//Send event
|
|
1498
|
-
this.inputValid.emit(validity);
|
|
1499
|
-
}
|
|
1541
|
+
var _a;
|
|
1542
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
|
|
1543
|
+
this.invalid = !this.valid;
|
|
1544
|
+
// We need to send valid event even if it is the same value
|
|
1545
|
+
this.inputValid.emit(this.valid);
|
|
1500
1546
|
};
|
|
1501
1547
|
/**
|
|
1502
1548
|
* get input error code
|
|
@@ -1525,48 +1571,50 @@ const MgInputDate = class {
|
|
|
1525
1571
|
return inputError;
|
|
1526
1572
|
};
|
|
1527
1573
|
/**
|
|
1528
|
-
*
|
|
1574
|
+
* Check input errors
|
|
1529
1575
|
*
|
|
1530
1576
|
* @returns {void}
|
|
1531
1577
|
*/
|
|
1532
1578
|
this.setErrorMessage = () => {
|
|
1533
1579
|
var _a;
|
|
1534
|
-
const inputError = this.getInputError();
|
|
1535
|
-
// required
|
|
1536
|
-
if (inputError === InputError$1.REQUIRED) {
|
|
1537
|
-
this.errorMessage = this.messages.errors[inputError];
|
|
1538
|
-
}
|
|
1539
|
-
// min, max & minMax
|
|
1540
|
-
else if ([InputError$1.MIN, InputError$1.MAX, InputError$1.MINMAX].includes(inputError)) {
|
|
1541
|
-
this.errorMessage = this.messages.errors.date[inputError].replace('{min}', localeDate(this.min, this.locale)).replace('{max}', localeDate(this.max, this.locale));
|
|
1542
|
-
}
|
|
1543
|
-
// wrong date format
|
|
1544
|
-
// element.validity.badInput is default error message
|
|
1545
|
-
else {
|
|
1546
|
-
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));
|
|
1547
|
-
}
|
|
1548
|
-
};
|
|
1549
|
-
/**
|
|
1550
|
-
* Check input errors
|
|
1551
|
-
*
|
|
1552
|
-
* @returns {void}
|
|
1553
|
-
*/
|
|
1554
|
-
this.checkError = () => {
|
|
1555
1580
|
// Set error message
|
|
1556
1581
|
this.errorMessage = undefined;
|
|
1557
1582
|
if (!this.valid) {
|
|
1558
|
-
this.
|
|
1583
|
+
const inputError = this.getInputError();
|
|
1584
|
+
// required
|
|
1585
|
+
if (inputError === InputError$1.REQUIRED) {
|
|
1586
|
+
this.errorMessage = this.messages.errors[inputError];
|
|
1587
|
+
}
|
|
1588
|
+
// min, max & minMax
|
|
1589
|
+
else if ([InputError$1.MIN, InputError$1.MAX, InputError$1.MINMAX].includes(inputError)) {
|
|
1590
|
+
this.errorMessage = this.messages.errors.date[inputError].replace('{min}', localeDate(this.min, this.locale)).replace('{max}', localeDate(this.max, this.locale));
|
|
1591
|
+
}
|
|
1592
|
+
// wrong date format
|
|
1593
|
+
// element.validity.badInput is default error message
|
|
1594
|
+
else {
|
|
1595
|
+
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));
|
|
1596
|
+
}
|
|
1559
1597
|
}
|
|
1560
1598
|
};
|
|
1561
1599
|
}
|
|
1562
1600
|
validateValue(newValue) {
|
|
1563
|
-
if (newValue !== undefined && (typeof newValue !== 'string' || !dateRegExp.test(newValue))) {
|
|
1601
|
+
if (newValue !== undefined && newValue !== null && (typeof newValue !== 'string' || !dateRegExp.test(newValue))) {
|
|
1564
1602
|
throw new Error("<mg-input-date> props 'value' doesn't match pattern: yyyy-mm-dd");
|
|
1565
1603
|
}
|
|
1566
1604
|
else {
|
|
1567
1605
|
this.valueChange.emit(this.value);
|
|
1568
1606
|
}
|
|
1569
1607
|
}
|
|
1608
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
1609
|
+
if (this.input !== undefined) {
|
|
1610
|
+
this.input[prop] = newValue;
|
|
1611
|
+
this.checkValidity();
|
|
1612
|
+
if (this.hasDisplayedError) {
|
|
1613
|
+
this.setErrorMessage();
|
|
1614
|
+
this.hasDisplayedError = false;
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1570
1618
|
validateMinMax(newValue) {
|
|
1571
1619
|
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)))) {
|
|
1572
1620
|
throw new Error("<mg-input-date> props 'min/max' doesn't match pattern: yyyy-mm-dd");
|
|
@@ -1579,8 +1627,8 @@ const MgInputDate = class {
|
|
|
1579
1627
|
*/
|
|
1580
1628
|
async displayError() {
|
|
1581
1629
|
this.checkValidity();
|
|
1582
|
-
this.
|
|
1583
|
-
this.
|
|
1630
|
+
this.setErrorMessage();
|
|
1631
|
+
this.hasDisplayedError = this.invalid;
|
|
1584
1632
|
}
|
|
1585
1633
|
/*************
|
|
1586
1634
|
* Lifecycle *
|
|
@@ -1612,11 +1660,17 @@ const MgInputDate = class {
|
|
|
1612
1660
|
* @returns {HTMLElement} HTML Element
|
|
1613
1661
|
*/
|
|
1614
1662
|
render() {
|
|
1615
|
-
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 =>
|
|
1663
|
+
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 => {
|
|
1664
|
+
if (el !== null)
|
|
1665
|
+
this.input = el;
|
|
1666
|
+
} })));
|
|
1616
1667
|
}
|
|
1617
1668
|
get element() { return getElement(this); }
|
|
1618
1669
|
static get watchers() { return {
|
|
1619
1670
|
"value": ["validateValue"],
|
|
1671
|
+
"required": ["handleValidityChange"],
|
|
1672
|
+
"readonly": ["handleValidityChange"],
|
|
1673
|
+
"disabled": ["handleValidityChange"],
|
|
1620
1674
|
"min": ["validateMinMax"],
|
|
1621
1675
|
"max": ["validateMinMax"]
|
|
1622
1676
|
}; }
|
|
@@ -1635,15 +1689,15 @@ var InputError;
|
|
|
1635
1689
|
InputError["REQUIRED"] = "required";
|
|
1636
1690
|
})(InputError || (InputError = {}));
|
|
1637
1691
|
|
|
1638
|
-
const mgInputNumericCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{width:100%}.mg-input.mg-input--width-16 .mg-input__box{width:21rem}.mg-input.mg-input--width-4 .mg-input__box{width:7rem}.mg-input.mg-input--width-2 .mg-input__box{width:5rem}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input .mg-input__box{text-align:var(--mg-inputs-text-align, right)}";
|
|
1692
|
+
const mgInputNumericCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full.mg-input--label-on-top .mg-input__box{width:100%}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{max-width:100%}.mg-input:not(.mg-input--label-on-top) .mg-input__box{width:100%;max-width:calc(17.7rem + var(--mg-inputs-spacer) * 2);min-width:5rem}.mg-input.mg-input--width-16 .mg-input__input-container{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input{width:100%;max-width:21rem}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box{max-width:21rem;min-width:100%}.mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box{max-width:7rem}.mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box{max-width:5rem}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input .mg-input__box{text-align:var(--mg-inputs-text-align, right)}";
|
|
1639
1693
|
|
|
1640
1694
|
const MgInputNumeric = class {
|
|
1641
1695
|
constructor(hostRef) {
|
|
1642
1696
|
registerInstance(this, hostRef);
|
|
1643
1697
|
this.valueChange = createEvent(this, "value-change", 7);
|
|
1644
1698
|
this.inputValid = createEvent(this, "input-valid", 7);
|
|
1645
|
-
//
|
|
1646
|
-
this.
|
|
1699
|
+
// hasDisplayedError (triggered by blur event)
|
|
1700
|
+
this.hasDisplayedError = false;
|
|
1647
1701
|
/**
|
|
1648
1702
|
* Input name
|
|
1649
1703
|
* If not set the value equals the identifier
|
|
@@ -1699,8 +1753,8 @@ const MgInputNumeric = class {
|
|
|
1699
1753
|
this.handleInput = () => {
|
|
1700
1754
|
// Check validity
|
|
1701
1755
|
this.checkValidity();
|
|
1702
|
-
if (this.
|
|
1703
|
-
this.
|
|
1756
|
+
if (this.hasDisplayedError) {
|
|
1757
|
+
this.setErrorMessage();
|
|
1704
1758
|
}
|
|
1705
1759
|
this.value = this.input.value;
|
|
1706
1760
|
};
|
|
@@ -1728,40 +1782,27 @@ const MgInputNumeric = class {
|
|
|
1728
1782
|
* @returns {void}
|
|
1729
1783
|
*/
|
|
1730
1784
|
this.checkValidity = () => {
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
this.invalid = !validity;
|
|
1736
|
-
//Send event
|
|
1737
|
-
this.inputValid.emit(validity);
|
|
1738
|
-
}
|
|
1785
|
+
this.valid = this.readonly || this.disabled || this.getInputError() === null;
|
|
1786
|
+
this.invalid = !this.valid;
|
|
1787
|
+
// We need to send valid event even if it is the same value
|
|
1788
|
+
this.inputValid.emit(this.valid);
|
|
1739
1789
|
};
|
|
1740
1790
|
/**
|
|
1741
|
-
* Set error message
|
|
1791
|
+
* Set input error message
|
|
1742
1792
|
*
|
|
1743
1793
|
* @returns {void}
|
|
1744
1794
|
*/
|
|
1745
1795
|
this.setErrorMessage = () => {
|
|
1746
|
-
const inputError = this.getInputError();
|
|
1747
|
-
if (inputError === InputError.REQUIRED) {
|
|
1748
|
-
this.errorMessage = this.messages.errors[inputError];
|
|
1749
|
-
}
|
|
1750
|
-
else {
|
|
1751
|
-
this.errorMessage = this.messages.errors.numeric[inputError].replace('{min}', `${this.formatValue(this.min)}`).replace('{max}', `${this.formatValue(this.max)}`);
|
|
1752
|
-
}
|
|
1753
|
-
};
|
|
1754
|
-
/**
|
|
1755
|
-
* Check input errors
|
|
1756
|
-
*
|
|
1757
|
-
* @returns {void}
|
|
1758
|
-
*/
|
|
1759
|
-
this.checkError = () => {
|
|
1760
1796
|
// Set error message
|
|
1761
1797
|
this.errorMessage = undefined;
|
|
1762
|
-
// Update class
|
|
1763
1798
|
if (!this.valid) {
|
|
1764
|
-
this.
|
|
1799
|
+
const inputError = this.getInputError();
|
|
1800
|
+
if (inputError === InputError.REQUIRED) {
|
|
1801
|
+
this.errorMessage = this.messages.errors[inputError];
|
|
1802
|
+
}
|
|
1803
|
+
else {
|
|
1804
|
+
this.errorMessage = this.messages.errors.numeric[inputError].replace('{min}', `${this.formatValue(this.min)}`).replace('{max}', `${this.formatValue(this.max)}`);
|
|
1805
|
+
}
|
|
1765
1806
|
}
|
|
1766
1807
|
};
|
|
1767
1808
|
/**
|
|
@@ -1771,7 +1812,7 @@ const MgInputNumeric = class {
|
|
|
1771
1812
|
*/
|
|
1772
1813
|
this.getInputError = () => {
|
|
1773
1814
|
let inputError = null;
|
|
1774
|
-
if (this.input === undefined)
|
|
1815
|
+
if (this.input === undefined || this.input === null)
|
|
1775
1816
|
return inputError;
|
|
1776
1817
|
// required
|
|
1777
1818
|
if (!this.input.checkValidity() && this.input.validity.valueMissing) {
|
|
@@ -1838,6 +1879,16 @@ const MgInputNumeric = class {
|
|
|
1838
1879
|
this.readonlyValue = this.numericValue !== null ? this.formatValue(this.numericValue) : '';
|
|
1839
1880
|
}
|
|
1840
1881
|
}
|
|
1882
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
1883
|
+
if (this.input !== undefined) {
|
|
1884
|
+
this.input[prop] = newValue;
|
|
1885
|
+
this.checkValidity();
|
|
1886
|
+
if (this.hasDisplayedError) {
|
|
1887
|
+
this.setErrorMessage();
|
|
1888
|
+
this.hasDisplayedError = false;
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1841
1892
|
validateType(newValue) {
|
|
1842
1893
|
if (!types.includes(newValue)) {
|
|
1843
1894
|
throw new Error(`<mg-input-numeric> prop "type" must be one of : ${types.join(', ')}`);
|
|
@@ -1860,8 +1911,8 @@ const MgInputNumeric = class {
|
|
|
1860
1911
|
*/
|
|
1861
1912
|
async displayError() {
|
|
1862
1913
|
this.checkValidity();
|
|
1863
|
-
this.
|
|
1864
|
-
this.
|
|
1914
|
+
this.setErrorMessage();
|
|
1915
|
+
this.hasDisplayedError = this.invalid;
|
|
1865
1916
|
}
|
|
1866
1917
|
/**
|
|
1867
1918
|
* Displayed value in input
|
|
@@ -1904,11 +1955,17 @@ const MgInputNumeric = class {
|
|
|
1904
1955
|
* @returns {HTMLElement} HTML Element
|
|
1905
1956
|
*/
|
|
1906
1957
|
render() {
|
|
1907
|
-
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 =>
|
|
1958
|
+
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 => {
|
|
1959
|
+
if (el !== null)
|
|
1960
|
+
this.input = el;
|
|
1961
|
+
} }), h("slot", { name: "append-input" })));
|
|
1908
1962
|
}
|
|
1909
1963
|
get element() { return getElement(this); }
|
|
1910
1964
|
static get watchers() { return {
|
|
1911
1965
|
"value": ["validateValue"],
|
|
1966
|
+
"required": ["handleValidityChange"],
|
|
1967
|
+
"readonly": ["handleValidityChange"],
|
|
1968
|
+
"disabled": ["handleValidityChange"],
|
|
1912
1969
|
"type": ["validateType"],
|
|
1913
1970
|
"integerLength": ["validateIntegerLength"],
|
|
1914
1971
|
"decimalLength": ["validateDecimalLength"]
|
|
@@ -1916,15 +1973,15 @@ const MgInputNumeric = class {
|
|
|
1916
1973
|
};
|
|
1917
1974
|
MgInputNumeric.style = mgInputNumericCss;
|
|
1918
1975
|
|
|
1919
|
-
const mgInputPasswordCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{width:100%}.mg-input.mg-input--width-16 .mg-input__box{width:21rem}.mg-input.mg-input--width-4 .mg-input__box{width:7rem}.mg-input.mg-input--width-2 .mg-input__box{width:5rem}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}";
|
|
1976
|
+
const mgInputPasswordCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full.mg-input--label-on-top .mg-input__box{width:100%}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{max-width:100%}.mg-input:not(.mg-input--label-on-top) .mg-input__box{width:100%;max-width:calc(17.7rem + var(--mg-inputs-spacer) * 2);min-width:5rem}.mg-input.mg-input--width-16 .mg-input__input-container{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input{width:100%;max-width:21rem}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box{max-width:21rem;min-width:100%}.mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box{max-width:7rem}.mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box{max-width:5rem}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}";
|
|
1920
1977
|
|
|
1921
1978
|
const MgInputPassword = class {
|
|
1922
1979
|
constructor(hostRef) {
|
|
1923
1980
|
registerInstance(this, hostRef);
|
|
1924
1981
|
this.valueChange = createEvent(this, "value-change", 7);
|
|
1925
1982
|
this.inputValid = createEvent(this, "input-valid", 7);
|
|
1926
|
-
//
|
|
1927
|
-
this.
|
|
1983
|
+
// hasDisplayedError (triggered by blur event)
|
|
1984
|
+
this.hasDisplayedError = false;
|
|
1928
1985
|
/**
|
|
1929
1986
|
* Input name
|
|
1930
1987
|
* If not set the value equals the identifier
|
|
@@ -1959,8 +2016,8 @@ const MgInputPassword = class {
|
|
|
1959
2016
|
*/
|
|
1960
2017
|
this.handleInput = () => {
|
|
1961
2018
|
this.checkValidity();
|
|
1962
|
-
if (this.
|
|
1963
|
-
this.
|
|
2019
|
+
if (this.hasDisplayedError) {
|
|
2020
|
+
this.setErrorMessage();
|
|
1964
2021
|
}
|
|
1965
2022
|
this.value = this.input.value;
|
|
1966
2023
|
};
|
|
@@ -1974,19 +2031,16 @@ const MgInputPassword = class {
|
|
|
1974
2031
|
* Check if input is valid
|
|
1975
2032
|
*/
|
|
1976
2033
|
this.checkValidity = () => {
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
//Send event
|
|
1983
|
-
this.inputValid.emit(validity);
|
|
1984
|
-
}
|
|
2034
|
+
var _a;
|
|
2035
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
|
|
2036
|
+
this.invalid = !this.valid;
|
|
2037
|
+
// We need to send valid event even if it is the same value
|
|
2038
|
+
this.inputValid.emit(this.valid);
|
|
1985
2039
|
};
|
|
1986
2040
|
/**
|
|
1987
|
-
*
|
|
2041
|
+
* Set input error message
|
|
1988
2042
|
*/
|
|
1989
|
-
this.
|
|
2043
|
+
this.setErrorMessage = () => {
|
|
1990
2044
|
// Set error message
|
|
1991
2045
|
this.errorMessage = undefined;
|
|
1992
2046
|
// required
|
|
@@ -1998,6 +2052,16 @@ const MgInputPassword = class {
|
|
|
1998
2052
|
handleValue(newValue) {
|
|
1999
2053
|
this.valueChange.emit(newValue);
|
|
2000
2054
|
}
|
|
2055
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
2056
|
+
if (this.input !== undefined) {
|
|
2057
|
+
this.input[prop] = newValue;
|
|
2058
|
+
this.checkValidity();
|
|
2059
|
+
if (this.hasDisplayedError) {
|
|
2060
|
+
this.setErrorMessage();
|
|
2061
|
+
this.hasDisplayedError = false;
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2001
2065
|
/**
|
|
2002
2066
|
* Public method to display errors
|
|
2003
2067
|
*
|
|
@@ -2005,8 +2069,8 @@ const MgInputPassword = class {
|
|
|
2005
2069
|
*/
|
|
2006
2070
|
async displayError() {
|
|
2007
2071
|
this.checkValidity();
|
|
2008
|
-
this.
|
|
2009
|
-
this.
|
|
2072
|
+
this.setErrorMessage();
|
|
2073
|
+
this.hasDisplayedError = this.invalid;
|
|
2010
2074
|
}
|
|
2011
2075
|
/*************
|
|
2012
2076
|
* Lifecycle *
|
|
@@ -2032,11 +2096,17 @@ const MgInputPassword = class {
|
|
|
2032
2096
|
* @returns {HTMLElement} HTML Element
|
|
2033
2097
|
*/
|
|
2034
2098
|
render() {
|
|
2035
|
-
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 =>
|
|
2099
|
+
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 => {
|
|
2100
|
+
if (el !== null)
|
|
2101
|
+
this.input = el;
|
|
2102
|
+
} })));
|
|
2036
2103
|
}
|
|
2037
2104
|
get element() { return getElement(this); }
|
|
2038
2105
|
static get watchers() { return {
|
|
2039
|
-
"value": ["handleValue"]
|
|
2106
|
+
"value": ["handleValue"],
|
|
2107
|
+
"required": ["handleValidityChange"],
|
|
2108
|
+
"readonly": ["handleValidityChange"],
|
|
2109
|
+
"disabled": ["handleValidityChange"]
|
|
2040
2110
|
}; }
|
|
2041
2111
|
};
|
|
2042
2112
|
MgInputPassword.style = mgInputPasswordCss;
|
|
@@ -2060,6 +2130,8 @@ const MgInputRadio = class {
|
|
|
2060
2130
|
************/
|
|
2061
2131
|
// HTML selector
|
|
2062
2132
|
this.inputs = [];
|
|
2133
|
+
// hasDisplayedError (triggered by blur event)
|
|
2134
|
+
this.hasDisplayedError = false;
|
|
2063
2135
|
/**
|
|
2064
2136
|
* Input name
|
|
2065
2137
|
* If not set the value equals the identifier
|
|
@@ -2110,7 +2182,7 @@ const MgInputRadio = class {
|
|
|
2110
2182
|
*/
|
|
2111
2183
|
this.handleBlur = () => {
|
|
2112
2184
|
this.checkValidity();
|
|
2113
|
-
this.
|
|
2185
|
+
this.setErrorMessage();
|
|
2114
2186
|
};
|
|
2115
2187
|
/**
|
|
2116
2188
|
* Check if input is valid
|
|
@@ -2118,21 +2190,17 @@ const MgInputRadio = class {
|
|
|
2118
2190
|
* @returns {void}
|
|
2119
2191
|
*/
|
|
2120
2192
|
this.checkValidity = () => {
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
this.invalid = !validity;
|
|
2126
|
-
//Send event
|
|
2127
|
-
this.inputValid.emit(validity);
|
|
2128
|
-
}
|
|
2193
|
+
this.valid = this.readonly || this.disabled || this.getInvalidElement() === undefined;
|
|
2194
|
+
this.invalid = !this.valid;
|
|
2195
|
+
// We need to send valid event even if it is the same value
|
|
2196
|
+
this.inputValid.emit(this.valid);
|
|
2129
2197
|
};
|
|
2130
2198
|
/**
|
|
2131
|
-
*
|
|
2199
|
+
* Set input error message
|
|
2132
2200
|
*
|
|
2133
2201
|
* @returns {void}
|
|
2134
2202
|
*/
|
|
2135
|
-
this.
|
|
2203
|
+
this.setErrorMessage = () => {
|
|
2136
2204
|
const invalidElement = this.getInvalidElement();
|
|
2137
2205
|
// Set error message
|
|
2138
2206
|
this.errorMessage = undefined;
|
|
@@ -2145,7 +2213,7 @@ const MgInputRadio = class {
|
|
|
2145
2213
|
*
|
|
2146
2214
|
* @returns {HTMLInputElement} element
|
|
2147
2215
|
*/
|
|
2148
|
-
this.getInvalidElement = () => this.inputs.find((
|
|
2216
|
+
this.getInvalidElement = () => this.inputs.find((input) => !input.disabled && !input.readOnly && !input.checkValidity());
|
|
2149
2217
|
}
|
|
2150
2218
|
handleValue(newValue) {
|
|
2151
2219
|
this.valueChange.emit(newValue);
|
|
@@ -2167,6 +2235,16 @@ const MgInputRadio = class {
|
|
|
2167
2235
|
throw new Error('<mg-input-radio> prop "items" is required and all items must be the same type, string or RadioOption.');
|
|
2168
2236
|
}
|
|
2169
2237
|
}
|
|
2238
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
2239
|
+
this.inputs.forEach(input => {
|
|
2240
|
+
input[prop] = newValue;
|
|
2241
|
+
});
|
|
2242
|
+
this.checkValidity();
|
|
2243
|
+
if (this.hasDisplayedError) {
|
|
2244
|
+
this.setErrorMessage();
|
|
2245
|
+
this.hasDisplayedError = false;
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2170
2248
|
/**
|
|
2171
2249
|
* Public method to display errors
|
|
2172
2250
|
*
|
|
@@ -2174,7 +2252,8 @@ const MgInputRadio = class {
|
|
|
2174
2252
|
*/
|
|
2175
2253
|
async displayError() {
|
|
2176
2254
|
this.checkValidity();
|
|
2177
|
-
this.
|
|
2255
|
+
this.setErrorMessage();
|
|
2256
|
+
this.hasDisplayedError = this.invalid;
|
|
2178
2257
|
}
|
|
2179
2258
|
/*************
|
|
2180
2259
|
* Lifecycle *
|
|
@@ -2202,17 +2281,23 @@ const MgInputRadio = class {
|
|
|
2202
2281
|
* @returns {HTMLElement} HTML Element
|
|
2203
2282
|
*/
|
|
2204
2283
|
render() {
|
|
2205
|
-
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 =>
|
|
2284
|
+
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 => {
|
|
2285
|
+
if (el !== null)
|
|
2286
|
+
this.inputs[index] = el;
|
|
2287
|
+
} }), h("label", { htmlFor: this.identifier + '_' + index }, input.title)))))));
|
|
2206
2288
|
}
|
|
2207
2289
|
get element() { return getElement(this); }
|
|
2208
2290
|
static get watchers() { return {
|
|
2209
2291
|
"value": ["handleValue"],
|
|
2210
|
-
"items": ["validateItems"]
|
|
2292
|
+
"items": ["validateItems"],
|
|
2293
|
+
"required": ["handleValidityChange"],
|
|
2294
|
+
"readonly": ["handleValidityChange"],
|
|
2295
|
+
"disabled": ["handleValidityChange"]
|
|
2211
2296
|
}; }
|
|
2212
2297
|
};
|
|
2213
2298
|
MgInputRadio.style = mgInputRadioCss;
|
|
2214
2299
|
|
|
2215
|
-
const mgInputSelectCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{width:100%}.mg-input.mg-input--width-16 .mg-input__box{width:21rem}.mg-input.mg-input--width-4 .mg-input__box{width:7rem}.mg-input.mg-input--width-2 .mg-input__box{width:5rem}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input__box{width:100%;padding-top:0;padding-bottom:0;padding-right:1rem}";
|
|
2300
|
+
const mgInputSelectCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full.mg-input--label-on-top .mg-input__box{width:100%}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{max-width:100%}.mg-input:not(.mg-input--label-on-top) .mg-input__box{width:100%;max-width:calc(17.7rem + var(--mg-inputs-spacer) * 2);min-width:5rem}.mg-input.mg-input--width-16 .mg-input__input-container{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input{width:100%;max-width:21rem}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box{max-width:21rem;min-width:100%}.mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box{max-width:7rem}.mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box{max-width:5rem}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input__box{width:100%;padding-top:0;padding-bottom:0;padding-right:1rem}.mg-input.mg-input--select:not(.mg-input--label-on-top) .mg-input__box{max-width:unset}";
|
|
2216
2301
|
|
|
2217
2302
|
/**
|
|
2218
2303
|
* Check if item is a well configured option
|
|
@@ -2255,8 +2340,8 @@ const MgInputSelect = class {
|
|
|
2255
2340
|
registerInstance(this, hostRef);
|
|
2256
2341
|
this.valueChange = createEvent(this, "value-change", 7);
|
|
2257
2342
|
this.inputValid = createEvent(this, "input-valid", 7);
|
|
2258
|
-
//
|
|
2259
|
-
this.
|
|
2343
|
+
// hasDisplayedError (triggered by blur event)
|
|
2344
|
+
this.hasDisplayedError = false;
|
|
2260
2345
|
/**
|
|
2261
2346
|
* Input name
|
|
2262
2347
|
* If not set the value equals the identifier
|
|
@@ -2295,8 +2380,8 @@ const MgInputSelect = class {
|
|
|
2295
2380
|
*/
|
|
2296
2381
|
this.handleInput = () => {
|
|
2297
2382
|
this.checkValidity();
|
|
2298
|
-
if (this.
|
|
2299
|
-
this.
|
|
2383
|
+
if (this.hasDisplayedError) {
|
|
2384
|
+
this.setErrorMessage();
|
|
2300
2385
|
}
|
|
2301
2386
|
if (this.input.value !== '') {
|
|
2302
2387
|
this.value = allItemsAreString(this.items) ? this.input.value : this.items.find(item => item.title === this.input.value).value;
|
|
@@ -2315,19 +2400,16 @@ const MgInputSelect = class {
|
|
|
2315
2400
|
* Check if input is valid
|
|
2316
2401
|
*/
|
|
2317
2402
|
this.checkValidity = () => {
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
//Send event
|
|
2324
|
-
this.inputValid.emit(validity);
|
|
2325
|
-
}
|
|
2403
|
+
var _a;
|
|
2404
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
|
|
2405
|
+
this.invalid = !this.valid;
|
|
2406
|
+
// We need to send valid event even if it is the same value
|
|
2407
|
+
this.inputValid.emit(this.valid);
|
|
2326
2408
|
};
|
|
2327
2409
|
/**
|
|
2328
|
-
*
|
|
2410
|
+
* Set input error message
|
|
2329
2411
|
*/
|
|
2330
|
-
this.
|
|
2412
|
+
this.setErrorMessage = () => {
|
|
2331
2413
|
// Set error message
|
|
2332
2414
|
this.errorMessage = undefined;
|
|
2333
2415
|
if (!this.valid && this.input.validity.valueMissing) {
|
|
@@ -2366,6 +2448,16 @@ const MgInputSelect = class {
|
|
|
2366
2448
|
throw new Error('<mg-input-select> prop "items" is required and all items must be the same type, string or Option.');
|
|
2367
2449
|
}
|
|
2368
2450
|
}
|
|
2451
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
2452
|
+
if (this.input !== undefined) {
|
|
2453
|
+
this.input[prop] = newValue;
|
|
2454
|
+
this.checkValidity();
|
|
2455
|
+
if (this.hasDisplayedError) {
|
|
2456
|
+
this.setErrorMessage();
|
|
2457
|
+
this.hasDisplayedError = false;
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2369
2461
|
/**
|
|
2370
2462
|
* Public method to display errors
|
|
2371
2463
|
*
|
|
@@ -2373,8 +2465,8 @@ const MgInputSelect = class {
|
|
|
2373
2465
|
*/
|
|
2374
2466
|
async displayError() {
|
|
2375
2467
|
this.checkValidity();
|
|
2376
|
-
this.
|
|
2377
|
-
this.
|
|
2468
|
+
this.setErrorMessage();
|
|
2469
|
+
this.hasDisplayedError = this.invalid;
|
|
2378
2470
|
}
|
|
2379
2471
|
/*************
|
|
2380
2472
|
* Lifecycle *
|
|
@@ -2406,18 +2498,24 @@ const MgInputSelect = class {
|
|
|
2406
2498
|
* @returns {HTMLElement} HTML Element
|
|
2407
2499
|
*/
|
|
2408
2500
|
render() {
|
|
2409
|
-
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 =>
|
|
2501
|
+
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 => {
|
|
2502
|
+
if (el !== null)
|
|
2503
|
+
this.input = el;
|
|
2504
|
+
} }, (!this.placeholderHide || !this.valueExist) && ( // In case passed value does not match any option we display the placeholder
|
|
2410
2505
|
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))))));
|
|
2411
2506
|
}
|
|
2412
2507
|
get element() { return getElement(this); }
|
|
2413
2508
|
static get watchers() { return {
|
|
2414
2509
|
"value": ["handleValue"],
|
|
2415
|
-
"items": ["validateItems"]
|
|
2510
|
+
"items": ["validateItems"],
|
|
2511
|
+
"required": ["handleValidityChange"],
|
|
2512
|
+
"readonly": ["handleValidityChange"],
|
|
2513
|
+
"disabled": ["handleValidityChange"]
|
|
2416
2514
|
}; }
|
|
2417
2515
|
};
|
|
2418
2516
|
MgInputSelect.style = mgInputSelectCss;
|
|
2419
2517
|
|
|
2420
|
-
const mgInputTextCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{width:100%}.mg-input.mg-input--width-16 .mg-input__box{width:21rem}.mg-input.mg-input--width-4 .mg-input__box{width:7rem}.mg-input.mg-input--width-2 .mg-input__box{width:5rem}.mg-input mg-character-left{opacity:0.6;font-size:1.1rem}.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__help-text,.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__error{margin-top:0}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input.mg-input--has-icon .mg-input__with-character-left>mg-icon{position:absolute;top:50%;left:var(--mg-inputs-spacer);color:var(--mg-inputs-color);transform:translateY(-50%)}.mg-input.mg-input--has-icon .mg-input__with-character-left .mg-input__box{padding-left:calc(var(--mg-icon-regular-size) + var(--mg-inputs-spacer) * 2)}.mg-input__with-character-left{position:relative;display:inline-flex}.mg-input--width-full .mg-input__with-character-left{width:100%}.mg-input.is-focused .mg-input__with-character-left .mg-input__box{padding-right:calc(var(--mg-character-left-message-length) * 1ch + 0.8rem)}.mg-input__with-character-left mg-character-left{position:absolute;display:none;top:50%;right:1rem;opacity:0.6;transform:translateY(-50%);font-size:1.1rem}.mg-input.is-focused .mg-input__with-character-left mg-character-left{display:block}";
|
|
2518
|
+
const mgInputTextCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full.mg-input--label-on-top .mg-input__box{width:100%}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{max-width:100%}.mg-input:not(.mg-input--label-on-top) .mg-input__box{width:100%;max-width:calc(17.7rem + var(--mg-inputs-spacer) * 2);min-width:5rem}.mg-input.mg-input--width-16 .mg-input__input-container{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input{width:100%;max-width:21rem}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box{max-width:21rem;min-width:100%}.mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box{max-width:7rem}.mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box{max-width:5rem}.mg-input mg-character-left{opacity:0.6;font-size:1.1rem}.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__help-text,.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__error{margin-top:0}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input.mg-input--has-icon .mg-input__with-character-left>mg-icon{position:absolute;top:50%;left:var(--mg-inputs-spacer);color:var(--mg-inputs-color);transform:translateY(-50%)}.mg-input.mg-input--has-icon .mg-input__with-character-left .mg-input__box{padding-left:calc(var(--mg-icon-regular-size) + var(--mg-inputs-spacer) * 2)}.mg-input__with-character-left{position:relative;display:inline-flex}.mg-input--width-full .mg-input__with-character-left{width:100%}.mg-input.is-focused .mg-input__with-character-left .mg-input__box{padding-right:calc(var(--mg-character-left-message-length) * 1ch + 0.8rem)}.mg-input__with-character-left mg-character-left{position:absolute;display:none;top:50%;right:1rem;opacity:0.6;transform:translateY(-50%);font-size:1.1rem}.mg-input.is-focused .mg-input__with-character-left mg-character-left{display:block}";
|
|
2421
2519
|
|
|
2422
2520
|
const MgInputText = class {
|
|
2423
2521
|
constructor(hostRef) {
|
|
@@ -2427,12 +2525,12 @@ const MgInputText = class {
|
|
|
2427
2525
|
/************
|
|
2428
2526
|
* Internal *
|
|
2429
2527
|
************/
|
|
2430
|
-
//
|
|
2528
|
+
// Classes
|
|
2431
2529
|
this.classFocus = 'is-focused';
|
|
2432
2530
|
this.classIsInputGroupAppend = 'mg-input--is-input-group-append';
|
|
2433
2531
|
this.classHasIcon = 'mg-input--has-icon';
|
|
2434
|
-
//
|
|
2435
|
-
this.
|
|
2532
|
+
// hasDisplayedError (triggered by blur event)
|
|
2533
|
+
this.hasDisplayedError = false;
|
|
2436
2534
|
/**
|
|
2437
2535
|
* Input name
|
|
2438
2536
|
* If not set the value equals the identifier
|
|
@@ -2481,8 +2579,8 @@ const MgInputText = class {
|
|
|
2481
2579
|
*/
|
|
2482
2580
|
this.handleInput = () => {
|
|
2483
2581
|
this.checkValidity();
|
|
2484
|
-
if (this.
|
|
2485
|
-
this.
|
|
2582
|
+
if (this.hasDisplayedError) {
|
|
2583
|
+
this.setErrorMessage();
|
|
2486
2584
|
}
|
|
2487
2585
|
this.value = this.input.value;
|
|
2488
2586
|
};
|
|
@@ -2513,21 +2611,18 @@ const MgInputText = class {
|
|
|
2513
2611
|
* @returns {void}
|
|
2514
2612
|
*/
|
|
2515
2613
|
this.checkValidity = () => {
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
//Send event
|
|
2522
|
-
this.inputValid.emit(validity);
|
|
2523
|
-
}
|
|
2614
|
+
var _a;
|
|
2615
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
|
|
2616
|
+
this.invalid = !this.valid;
|
|
2617
|
+
// We need to send valid event even if it is the same value
|
|
2618
|
+
this.inputValid.emit(this.valid);
|
|
2524
2619
|
};
|
|
2525
2620
|
/**
|
|
2526
|
-
*
|
|
2621
|
+
* Set input error message
|
|
2527
2622
|
*
|
|
2528
2623
|
* @returns {void}
|
|
2529
2624
|
*/
|
|
2530
|
-
this.
|
|
2625
|
+
this.setErrorMessage = () => {
|
|
2531
2626
|
// Set error message
|
|
2532
2627
|
this.errorMessage = undefined;
|
|
2533
2628
|
// Does not match pattern
|
|
@@ -2540,7 +2635,7 @@ const MgInputText = class {
|
|
|
2540
2635
|
}
|
|
2541
2636
|
};
|
|
2542
2637
|
/**
|
|
2543
|
-
* Validate
|
|
2638
|
+
* Validate pattern configuration
|
|
2544
2639
|
*
|
|
2545
2640
|
* @returns {void}
|
|
2546
2641
|
*/
|
|
@@ -2579,6 +2674,16 @@ const MgInputText = class {
|
|
|
2579
2674
|
this.classList.delete(this.classHasIcon);
|
|
2580
2675
|
}
|
|
2581
2676
|
}
|
|
2677
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
2678
|
+
if (this.input !== undefined) {
|
|
2679
|
+
this.input[prop] = newValue;
|
|
2680
|
+
this.checkValidity();
|
|
2681
|
+
if (this.hasDisplayedError) {
|
|
2682
|
+
this.setErrorMessage();
|
|
2683
|
+
this.hasDisplayedError = false;
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2582
2687
|
/**
|
|
2583
2688
|
* Public method to play input focus
|
|
2584
2689
|
*
|
|
@@ -2594,8 +2699,8 @@ const MgInputText = class {
|
|
|
2594
2699
|
*/
|
|
2595
2700
|
async displayError() {
|
|
2596
2701
|
this.checkValidity();
|
|
2597
|
-
this.
|
|
2598
|
-
this.
|
|
2702
|
+
this.setErrorMessage();
|
|
2703
|
+
this.hasDisplayedError = this.invalid;
|
|
2599
2704
|
}
|
|
2600
2705
|
/*************
|
|
2601
2706
|
* Lifecycle *
|
|
@@ -2630,17 +2735,23 @@ const MgInputText = class {
|
|
|
2630
2735
|
'--mg-character-left-message-length': (this.displayCharacterLeft
|
|
2631
2736
|
? (this.maxlength - (this.value || '').length).toString().length + this.maxlength.toString().length + 1
|
|
2632
2737
|
: 0).toString(),
|
|
2633
|
-
} }, this.icon !== undefined && h("mg-icon", { icon: this.icon }), h("input", { type: this.type, class: "mg-input__box", value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, maxlength: this.maxlength, disabled: this.disabled, required: this.required, pattern: this.pattern, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el =>
|
|
2738
|
+
} }, this.icon !== undefined && h("mg-icon", { icon: this.icon }), h("input", { type: this.type, class: "mg-input__box", value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, maxlength: this.maxlength, disabled: this.disabled, required: this.required, pattern: this.pattern, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el => {
|
|
2739
|
+
if (el !== null)
|
|
2740
|
+
this.input = el;
|
|
2741
|
+
} }), this.displayCharacterLeft && this.maxlength > 0 && (h("mg-character-left", { identifier: this.characterLeftId, characters: this.value, maxlength: this.maxlength }))), h("slot", { name: "append-input" })));
|
|
2634
2742
|
}
|
|
2635
2743
|
get element() { return getElement(this); }
|
|
2636
2744
|
static get watchers() { return {
|
|
2637
2745
|
"value": ["handleValue"],
|
|
2638
|
-
"icon": ["validateIcon"]
|
|
2746
|
+
"icon": ["validateIcon"],
|
|
2747
|
+
"required": ["handleValidityChange"],
|
|
2748
|
+
"readonly": ["handleValidityChange"],
|
|
2749
|
+
"disabled": ["handleValidityChange"]
|
|
2639
2750
|
}; }
|
|
2640
2751
|
};
|
|
2641
2752
|
MgInputText.style = mgInputTextCss;
|
|
2642
2753
|
|
|
2643
|
-
const mgInputTextareaCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{width:100%}.mg-input.mg-input--width-16 .mg-input__box{width:21rem}.mg-input.mg-input--width-4 .mg-input__box{width:7rem}.mg-input.mg-input--width-2 .mg-input__box{width:5rem}.mg-input mg-character-left{opacity:0.6;font-size:1.1rem}.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__help-text,.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__error{margin-top:0}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input .mg-input__box{display:block;height:auto;resize:none}.mg-input .mg-input__box.mg-input__box--resizable{resize:both}.mg-input .mg-input__box.mg-input__box--resizable-horizontal{resize:horizontal}.mg-input .mg-input__box.mg-input__box--resizable-vertical{resize:vertical}.mg-input__with-character-left{width:100%}.mg-input__with-character-left mg-character-left{display:block;visibility:hidden;margin-top:0.2rem;text-align:end}.mg-input.is-focused .mg-input__with-character-left mg-character-left{visibility:visible}@-moz-document url-prefix(){.mg-input__box{overflow-x:hidden}}";
|
|
2754
|
+
const mgInputTextareaCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full.mg-input--label-on-top .mg-input__box{width:100%}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{max-width:100%}.mg-input:not(.mg-input--label-on-top) .mg-input__box{width:100%;max-width:calc(17.7rem + var(--mg-inputs-spacer) * 2);min-width:5rem}.mg-input.mg-input--width-16 .mg-input__input-container{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input{width:100%;max-width:21rem}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box{max-width:21rem;min-width:100%}.mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box{max-width:7rem}.mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box{max-width:5rem}.mg-input mg-character-left{opacity:0.6;font-size:1.1rem}.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__help-text,.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__error{margin-top:0}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input .mg-input__box{display:block;height:auto;resize:none}.mg-input .mg-input__box.mg-input__box--resizable{resize:both}.mg-input .mg-input__box.mg-input__box--resizable-horizontal{resize:horizontal}.mg-input .mg-input__box.mg-input__box--resizable-vertical{resize:vertical}.mg-input__with-character-left{width:100%}.mg-input__with-character-left mg-character-left{display:block;visibility:hidden;margin-top:0.2rem;text-align:end}.mg-input.is-focused .mg-input__with-character-left mg-character-left{visibility:visible}@-moz-document url-prefix(){.mg-input__box{overflow-x:hidden}}";
|
|
2644
2755
|
|
|
2645
2756
|
const MgInputTextarea = class {
|
|
2646
2757
|
constructor(hostRef) {
|
|
@@ -2650,11 +2761,11 @@ const MgInputTextarea = class {
|
|
|
2650
2761
|
/************
|
|
2651
2762
|
* Internal *
|
|
2652
2763
|
************/
|
|
2653
|
-
//
|
|
2764
|
+
// Classes
|
|
2654
2765
|
this.classFocus = 'is-focused';
|
|
2655
2766
|
this.classHasDisplayCharacterLeft = 'mg-input--has-display-character-left';
|
|
2656
|
-
//
|
|
2657
|
-
this.
|
|
2767
|
+
// hasDisplayedError (triggered by blur event)
|
|
2768
|
+
this.hasDisplayedError = false;
|
|
2658
2769
|
/**
|
|
2659
2770
|
* Input name
|
|
2660
2771
|
* If not set the value equals the identifier
|
|
@@ -2704,9 +2815,9 @@ const MgInputTextarea = class {
|
|
|
2704
2815
|
* Handle input event
|
|
2705
2816
|
*/
|
|
2706
2817
|
this.handleInput = () => {
|
|
2707
|
-
if (this.
|
|
2818
|
+
if (this.hasDisplayedError) {
|
|
2708
2819
|
this.checkValidity();
|
|
2709
|
-
this.
|
|
2820
|
+
this.setErrorMessage();
|
|
2710
2821
|
}
|
|
2711
2822
|
this.value = this.input.value;
|
|
2712
2823
|
};
|
|
@@ -2738,19 +2849,16 @@ const MgInputTextarea = class {
|
|
|
2738
2849
|
* Check if input is valid
|
|
2739
2850
|
*/
|
|
2740
2851
|
this.checkValidity = () => {
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
//Send event
|
|
2747
|
-
this.inputValid.emit(validity);
|
|
2748
|
-
}
|
|
2852
|
+
var _a;
|
|
2853
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined && this.input.checkValidity() && this.getPatternValidity());
|
|
2854
|
+
this.invalid = !this.valid;
|
|
2855
|
+
// We need to send valid event even if it is the same value
|
|
2856
|
+
this.inputValid.emit(this.valid);
|
|
2749
2857
|
};
|
|
2750
2858
|
/**
|
|
2751
|
-
*
|
|
2859
|
+
* Set input error message
|
|
2752
2860
|
*/
|
|
2753
|
-
this.
|
|
2861
|
+
this.setErrorMessage = () => {
|
|
2754
2862
|
// Set error message
|
|
2755
2863
|
this.errorMessage = undefined;
|
|
2756
2864
|
// Does not match pattern
|
|
@@ -2778,6 +2886,16 @@ const MgInputTextarea = class {
|
|
|
2778
2886
|
this.checkValidity();
|
|
2779
2887
|
this.valueChange.emit(newValue);
|
|
2780
2888
|
}
|
|
2889
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
2890
|
+
if (this.input !== undefined) {
|
|
2891
|
+
this.input[prop] = newValue;
|
|
2892
|
+
this.checkValidity();
|
|
2893
|
+
if (this.hasDisplayedError) {
|
|
2894
|
+
this.setErrorMessage();
|
|
2895
|
+
this.hasDisplayedError = false;
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
}
|
|
2781
2899
|
validateDisplayCharacterLeft(newValue) {
|
|
2782
2900
|
if (newValue) {
|
|
2783
2901
|
this.classList.add(this.classHasDisplayCharacterLeft);
|
|
@@ -2793,8 +2911,8 @@ const MgInputTextarea = class {
|
|
|
2793
2911
|
*/
|
|
2794
2912
|
async displayError() {
|
|
2795
2913
|
this.checkValidity();
|
|
2796
|
-
this.
|
|
2797
|
-
this.
|
|
2914
|
+
this.setErrorMessage();
|
|
2915
|
+
this.hasDisplayedError = this.invalid;
|
|
2798
2916
|
}
|
|
2799
2917
|
/*************
|
|
2800
2918
|
* Lifecycle *
|
|
@@ -2829,11 +2947,17 @@ const MgInputTextarea = class {
|
|
|
2829
2947
|
'mg-input__box--resizable': this.resizable === 'both',
|
|
2830
2948
|
'mg-input__box--resizable-horizontal': this.resizable === 'horizontal',
|
|
2831
2949
|
'mg-input__box--resizable-vertical': this.resizable === 'vertical',
|
|
2832
|
-
}, 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 =>
|
|
2950
|
+
}, 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 => {
|
|
2951
|
+
if (el !== null)
|
|
2952
|
+
this.input = el;
|
|
2953
|
+
} }), this.displayCharacterLeft && this.maxlength > 0 && (h("mg-character-left", { identifier: this.characterLeftId, characters: this.value, maxlength: this.maxlength })))));
|
|
2833
2954
|
}
|
|
2834
2955
|
get element() { return getElement(this); }
|
|
2835
2956
|
static get watchers() { return {
|
|
2836
2957
|
"value": ["handleValue"],
|
|
2958
|
+
"required": ["handleValidityChange"],
|
|
2959
|
+
"readonly": ["handleValidityChange"],
|
|
2960
|
+
"disabled": ["handleValidityChange"],
|
|
2837
2961
|
"displayCharacterLeft": ["validateDisplayCharacterLeft"]
|
|
2838
2962
|
}; }
|
|
2839
2963
|
};
|
|
@@ -2906,7 +3030,7 @@ const MgInputToggle = class {
|
|
|
2906
3030
|
/************
|
|
2907
3031
|
* Internal *
|
|
2908
3032
|
************/
|
|
2909
|
-
//
|
|
3033
|
+
// Classes
|
|
2910
3034
|
this.classReadonly = 'mg-input--toggle-readonly';
|
|
2911
3035
|
this.classDisabled = 'mg-input--toggle-disabled';
|
|
2912
3036
|
this.classIsActive = 'mg-input--toggle-is-active';
|
|
@@ -3089,6 +3213,368 @@ const MgInputToggle = class {
|
|
|
3089
3213
|
};
|
|
3090
3214
|
MgInputToggle.style = mgInputToggleCss;
|
|
3091
3215
|
|
|
3216
|
+
/**
|
|
3217
|
+
* Menu direction type
|
|
3218
|
+
*/
|
|
3219
|
+
var Direction;
|
|
3220
|
+
(function (Direction) {
|
|
3221
|
+
Direction["VERTICAL"] = "vertical";
|
|
3222
|
+
Direction["HORIZONTAL"] = "horizontal";
|
|
3223
|
+
})(Direction || (Direction = {}));
|
|
3224
|
+
|
|
3225
|
+
const mgMenuCss = ":host{display:flex;background-color:hsl(var(--mg-menu-background-color-hsl, var(--color-light)))}:host(.mg-menu--vertical){flex-direction:column;height:100%;overflow-y:auto}";
|
|
3226
|
+
|
|
3227
|
+
const MgMenu = class {
|
|
3228
|
+
constructor(hostRef) {
|
|
3229
|
+
registerInstance(this, hostRef);
|
|
3230
|
+
/************
|
|
3231
|
+
* Internal *
|
|
3232
|
+
************/
|
|
3233
|
+
this.name = 'mg-menu';
|
|
3234
|
+
this.focusedMenuItem = 0;
|
|
3235
|
+
/**
|
|
3236
|
+
* Component display direction. Default: "horizontal"
|
|
3237
|
+
*/
|
|
3238
|
+
this.direction = Direction.HORIZONTAL;
|
|
3239
|
+
/**
|
|
3240
|
+
* Component classes
|
|
3241
|
+
*/
|
|
3242
|
+
this.classList = new ClassList([this.name]);
|
|
3243
|
+
/**
|
|
3244
|
+
* Close matching menu-item
|
|
3245
|
+
*
|
|
3246
|
+
* @param {HTMLMgMenuItemElement} item menu-item to close
|
|
3247
|
+
* @param {boolean} condition addionnal condition
|
|
3248
|
+
* @returns {void}
|
|
3249
|
+
*/
|
|
3250
|
+
this.closeMenuItem = (item, condition) => {
|
|
3251
|
+
if (!this.isChildMenu && condition) {
|
|
3252
|
+
item.expanded = false;
|
|
3253
|
+
}
|
|
3254
|
+
};
|
|
3255
|
+
/**
|
|
3256
|
+
* Store menu-items on component init and add listeners
|
|
3257
|
+
*/
|
|
3258
|
+
this.initMenuItems = () => {
|
|
3259
|
+
// store all menu-items
|
|
3260
|
+
this.menuItems = Array.from(this.element.children).filter(child => child.nodeName === 'MG-MENU-ITEM');
|
|
3261
|
+
// add listeners on menu item and edit index
|
|
3262
|
+
this.menuItems.forEach((item, menuItemIndex) => {
|
|
3263
|
+
['click', 'focus'].forEach(trigger => {
|
|
3264
|
+
(item.shadowRoot.querySelector('button') || item.shadowRoot.querySelector('a')).addEventListener(trigger, (event) => {
|
|
3265
|
+
event.preventDefault();
|
|
3266
|
+
event.stopPropagation();
|
|
3267
|
+
this.focusedMenuItem = menuItemIndex;
|
|
3268
|
+
// reset expanded on previous active menu item
|
|
3269
|
+
this.menuItems.forEach((item, index) => {
|
|
3270
|
+
this.closeMenuItem(item, index !== this.focusedMenuItem);
|
|
3271
|
+
});
|
|
3272
|
+
});
|
|
3273
|
+
});
|
|
3274
|
+
});
|
|
3275
|
+
};
|
|
3276
|
+
}
|
|
3277
|
+
validateLabel(newValue) {
|
|
3278
|
+
if (newValue === undefined) {
|
|
3279
|
+
throw new Error(`<${this.name}> prop "label" is required.`);
|
|
3280
|
+
}
|
|
3281
|
+
}
|
|
3282
|
+
validateDirection(newValue) {
|
|
3283
|
+
if (newValue === Direction.VERTICAL) {
|
|
3284
|
+
this.classList.add(`${this.name}--${Direction.VERTICAL}`);
|
|
3285
|
+
}
|
|
3286
|
+
else if (newValue === Direction.HORIZONTAL) {
|
|
3287
|
+
this.classList.add(`${this.name}--${Direction.HORIZONTAL}`);
|
|
3288
|
+
}
|
|
3289
|
+
else {
|
|
3290
|
+
throw new Error(`<${this.name}> prop "direction" must be one of : ${Direction.HORIZONTAL}, ${Direction.VERTICAL}.`);
|
|
3291
|
+
}
|
|
3292
|
+
}
|
|
3293
|
+
/*************
|
|
3294
|
+
* Lifecycle *
|
|
3295
|
+
*************/
|
|
3296
|
+
/**
|
|
3297
|
+
* Validate props
|
|
3298
|
+
*
|
|
3299
|
+
* @returns {void}
|
|
3300
|
+
*/
|
|
3301
|
+
componentWillLoad() {
|
|
3302
|
+
this.validateDirection(this.direction);
|
|
3303
|
+
this.validateLabel(this.label);
|
|
3304
|
+
}
|
|
3305
|
+
/**
|
|
3306
|
+
* Check if component slots configuration
|
|
3307
|
+
*
|
|
3308
|
+
* @returns {ReturnType<typeof setTimeout>} timeout
|
|
3309
|
+
*/
|
|
3310
|
+
componentDidLoad() {
|
|
3311
|
+
this.initMenuItems();
|
|
3312
|
+
// update props and states after componentDidLoad hook
|
|
3313
|
+
// return a promise to process action only in the FIRST render().
|
|
3314
|
+
// https://stenciljs.com/docs/component-lifecycle#componentwillload
|
|
3315
|
+
return setTimeout(() => {
|
|
3316
|
+
this.isChildMenu = this.element.closest('mg-menu-item') !== null;
|
|
3317
|
+
// click outside management for child vertical menu
|
|
3318
|
+
if (!this.isChildMenu && this.direction === Direction.HORIZONTAL) {
|
|
3319
|
+
document.addEventListener('click', (event) => {
|
|
3320
|
+
if (event.target.closest('mg-menu') === null) {
|
|
3321
|
+
this.menuItems.forEach(item => {
|
|
3322
|
+
this.closeMenuItem(item, this.direction === Direction.HORIZONTAL);
|
|
3323
|
+
});
|
|
3324
|
+
}
|
|
3325
|
+
});
|
|
3326
|
+
}
|
|
3327
|
+
}, 0);
|
|
3328
|
+
}
|
|
3329
|
+
/**
|
|
3330
|
+
* Render
|
|
3331
|
+
*
|
|
3332
|
+
* @returns {HTMLElement} HTML Element
|
|
3333
|
+
*/
|
|
3334
|
+
render() {
|
|
3335
|
+
return (h(Host, { role: this.isChildMenu ? 'menu' : 'menubar', "aria-label": this.label, classList: this.classList.join() }, h("slot", null)));
|
|
3336
|
+
}
|
|
3337
|
+
get element() { return getElement(this); }
|
|
3338
|
+
static get watchers() { return {
|
|
3339
|
+
"label": ["validateLabel"],
|
|
3340
|
+
"direction": ["validateDirection"]
|
|
3341
|
+
}; }
|
|
3342
|
+
};
|
|
3343
|
+
MgMenu.style = mgMenuCss;
|
|
3344
|
+
|
|
3345
|
+
/**
|
|
3346
|
+
* Available menu-item positions
|
|
3347
|
+
*/
|
|
3348
|
+
var ElementPosition;
|
|
3349
|
+
(function (ElementPosition) {
|
|
3350
|
+
ElementPosition["FIRST"] = "first";
|
|
3351
|
+
ElementPosition["LAST"] = "last";
|
|
3352
|
+
})(ElementPosition || (ElementPosition = {}));
|
|
3353
|
+
/**
|
|
3354
|
+
* Available menu item status
|
|
3355
|
+
*/
|
|
3356
|
+
var Status$1;
|
|
3357
|
+
(function (Status) {
|
|
3358
|
+
Status["VISIBLE"] = "visible";
|
|
3359
|
+
Status["HIDDEN"] = "hidden";
|
|
3360
|
+
Status["DISABLED"] = "disabled";
|
|
3361
|
+
Status["ACTIVE"] = "active";
|
|
3362
|
+
})(Status$1 || (Status$1 = {}));
|
|
3363
|
+
/**
|
|
3364
|
+
* List of all possibles sizes
|
|
3365
|
+
*/
|
|
3366
|
+
const sizes$1 = ['regular', 'medium', 'large'];
|
|
3367
|
+
|
|
3368
|
+
const mgMenuItemCss = ".mg-menu-item.mg-menu-item--size-regular .mg-menu-item__navigation-button,.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-regular{padding:1rem 2rem}.mg-menu-item.mg-menu-item--size-regular .mg-menu-item__navigation-button,.mg-menu-item.mg-menu-item--size-regular .mg-menu-item__navigation-button ::slotted([slot=label]),.mg-menu-item.mg-menu-item--size-regular .mg-menu-item__navigation-button ::slotted([slot=metadata]),.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-regular,.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-regular ::slotted([slot=label]),.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-regular ::slotted([slot=metadata]){font-size:1.3rem}.mg-menu-item.mg-menu-item--size-regular .mg-menu-item__navigation-button.mg-menu-item__navigation-button--horizontal,.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-regular.mg-menu-item__navigation-button--horizontal{padding-bottom:calc(1rem - 0.3rem)}.mg-menu-item.mg-menu-item--size-regular .mg-menu-item__navigation-button.mg-menu-item__navigation-button--vertical,.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-regular.mg-menu-item__navigation-button--vertical{padding-left:calc(2rem - 0.3rem)}.mg-menu-item.mg-menu-item--size-medium .mg-menu-item__navigation-button,.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-medium{padding:1.5rem 3rem}.mg-menu-item.mg-menu-item--size-medium .mg-menu-item__navigation-button,.mg-menu-item.mg-menu-item--size-medium .mg-menu-item__navigation-button ::slotted([slot=label]),.mg-menu-item.mg-menu-item--size-medium .mg-menu-item__navigation-button ::slotted([slot=metadata]),.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-medium,.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-medium ::slotted([slot=label]),.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-medium ::slotted([slot=metadata]){font-size:1.5rem}.mg-menu-item.mg-menu-item--size-medium .mg-menu-item__navigation-button.mg-menu-item__navigation-button--horizontal,.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-medium.mg-menu-item__navigation-button--horizontal{padding-bottom:calc(1.5rem - 0.3rem)}.mg-menu-item.mg-menu-item--size-medium .mg-menu-item__navigation-button.mg-menu-item__navigation-button--vertical,.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-medium.mg-menu-item__navigation-button--vertical{padding-left:calc(3rem - 0.3rem)}.mg-menu-item.mg-menu-item--size-large .mg-menu-item__navigation-button,.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-large{padding:2.5rem 4rem}.mg-menu-item.mg-menu-item--size-large .mg-menu-item__navigation-button,.mg-menu-item.mg-menu-item--size-large .mg-menu-item__navigation-button ::slotted([slot=label]),.mg-menu-item.mg-menu-item--size-large .mg-menu-item__navigation-button ::slotted([slot=metadata]),.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-large,.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-large ::slotted([slot=label]),.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-large ::slotted([slot=metadata]){font-size:1.5rem}.mg-menu-item.mg-menu-item--size-large .mg-menu-item__navigation-button.mg-menu-item__navigation-button--horizontal,.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-large.mg-menu-item__navigation-button--horizontal{padding-bottom:calc(2.5rem - 0.3rem)}.mg-menu-item.mg-menu-item--size-large .mg-menu-item__navigation-button.mg-menu-item__navigation-button--vertical,.mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-large.mg-menu-item__navigation-button--vertical{padding-left:calc(4rem - 0.3rem)}.mg-menu-item__navigation-button{display:flex;align-items:center;column-gap:1rem;background-color:unset;border:none;font-family:var(--font-family);color:hsl(var(--mg-menu-item-color-hsl, var(--color-dark)));line-height:var(--line-height);text-decoration:none;cursor:pointer}.mg-menu-item__navigation-button:disabled,.mg-menu-item__navigation-button--disabled{cursor:default;opacity:30%}.mg-menu-item__navigation-button:focus-visible{z-index:10}.mg-menu-item__navigation-button:hover:not(.mg-menu-item__navigation-button--disabled),.mg-menu-item__navigation-button:focus:not(.mg-menu-item__navigation-button--disabled){background-color:hsla(var(--mg-menu-item-focused-background-color-hsl), 10%)}.mg-menu-item__navigation-button.mg-menu-item__navigation-button--active{color:hsl(var(--mg-menu-item-color-active-hsl));font-weight:700}.mg-menu-item__navigation-button.mg-menu-item__navigation-button--active.mg-menu-item__navigation-button--horizontal{border-bottom-color:hsl(var(--mg-menu-item-border-color-active-hsl))}.mg-menu-item__navigation-button.mg-menu-item__navigation-button--active.mg-menu-item__navigation-button--vertical{border-left-color:hsl(var(--mg-menu-item-border-color-active-hsl))}.mg-menu-item__navigation-button.mg-menu-item__navigation-button--hidden{display:none}.mg-menu-item__navigation-button.mg-menu-item__navigation-button--horizontal{border-bottom:0.3rem solid transparent}.mg-menu-item__navigation-button.mg-menu-item__navigation-button--vertical{border-left:0.3rem solid transparent}:host(.mg-menu-item--vertical[data-level=\"1\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-regular{padding-left:calc(1 * 2rem - 0.3rem)}:host([data-level=\"1\"]) .mg-menu-item__collapse-container{z-index:calc(1 * 10)}:host(.mg-menu-item--vertical[data-level=\"2\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-regular{padding-left:calc(2 * 2rem - 0.3rem)}:host([data-level=\"2\"]) .mg-menu-item__collapse-container{z-index:calc(2 * 10)}:host(.mg-menu-item--vertical[data-level=\"3\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-regular{padding-left:calc(3 * 2rem - 0.3rem)}:host([data-level=\"3\"]) .mg-menu-item__collapse-container{z-index:calc(3 * 10)}:host(.mg-menu-item--vertical[data-level=\"4\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-regular{padding-left:calc(4 * 2rem - 0.3rem)}:host([data-level=\"4\"]) .mg-menu-item__collapse-container{z-index:calc(4 * 10)}:host(.mg-menu-item--vertical[data-level=\"5\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-regular{padding-left:calc(5 * 2rem - 0.3rem)}:host([data-level=\"5\"]) .mg-menu-item__collapse-container{z-index:calc(5 * 10)}:host(.mg-menu-item--vertical[data-level=\"6\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-regular{padding-left:calc(6 * 2rem - 0.3rem)}:host([data-level=\"6\"]) .mg-menu-item__collapse-container{z-index:calc(6 * 10)}:host(.mg-menu-item--vertical[data-level=\"1\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-medium{padding-left:calc(1 * 3rem - 0.3rem)}:host([data-level=\"1\"]) .mg-menu-item__collapse-container{z-index:calc(1 * 10)}:host(.mg-menu-item--vertical[data-level=\"2\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-medium{padding-left:calc(2 * 3rem - 0.3rem)}:host([data-level=\"2\"]) .mg-menu-item__collapse-container{z-index:calc(2 * 10)}:host(.mg-menu-item--vertical[data-level=\"3\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-medium{padding-left:calc(3 * 3rem - 0.3rem)}:host([data-level=\"3\"]) .mg-menu-item__collapse-container{z-index:calc(3 * 10)}:host(.mg-menu-item--vertical[data-level=\"4\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-medium{padding-left:calc(4 * 3rem - 0.3rem)}:host([data-level=\"4\"]) .mg-menu-item__collapse-container{z-index:calc(4 * 10)}:host(.mg-menu-item--vertical[data-level=\"5\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-medium{padding-left:calc(5 * 3rem - 0.3rem)}:host([data-level=\"5\"]) .mg-menu-item__collapse-container{z-index:calc(5 * 10)}:host(.mg-menu-item--vertical[data-level=\"6\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-medium{padding-left:calc(6 * 3rem - 0.3rem)}:host([data-level=\"6\"]) .mg-menu-item__collapse-container{z-index:calc(6 * 10)}:host(.mg-menu-item--vertical[data-level=\"1\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-large{padding-left:calc(1 * 4rem - 0.3rem)}:host([data-level=\"1\"]) .mg-menu-item__collapse-container{z-index:calc(1 * 10)}:host(.mg-menu-item--vertical[data-level=\"2\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-large{padding-left:calc(2 * 4rem - 0.3rem)}:host([data-level=\"2\"]) .mg-menu-item__collapse-container{z-index:calc(2 * 10)}:host(.mg-menu-item--vertical[data-level=\"3\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-large{padding-left:calc(3 * 4rem - 0.3rem)}:host([data-level=\"3\"]) .mg-menu-item__collapse-container{z-index:calc(3 * 10)}:host(.mg-menu-item--vertical[data-level=\"4\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-large{padding-left:calc(4 * 4rem - 0.3rem)}:host([data-level=\"4\"]) .mg-menu-item__collapse-container{z-index:calc(4 * 10)}:host(.mg-menu-item--vertical[data-level=\"5\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-large{padding-left:calc(5 * 4rem - 0.3rem)}:host([data-level=\"5\"]) .mg-menu-item__collapse-container{z-index:calc(5 * 10)}:host(.mg-menu-item--vertical[data-level=\"6\"]) .mg-menu-item__navigation-button.mg-menu-item__navigation-button--size-large{padding-left:calc(6 * 4rem - 0.3rem)}:host([data-level=\"6\"]) .mg-menu-item__collapse-container{z-index:calc(6 * 10)}:host{position:relative;display:flex}:host(.mg-menu-item--last) .mg-menu-item__collapse-container{left:unset;right:0}:host(.mg-menu-item--vertical){flex-direction:column}:host(.mg-menu-item--vertical) .mg-menu-item__collapse-container{left:unset;top:unset;position:unset;width:unset}:host(.mg-menu-item--vertical) .mg-menu-item-chevron{margin-left:auto}:host(.mg-menu-item--horizontal) .mg-menu-item__collapse-container.mg-menu-item__collapse-container--first-level{box-shadow:var(--box-shadow);background-color:hsl(var(--color-light))}:host(.mg-menu-item--horizontal) .mg-menu-item__collapse-container.mg-menu-item__collapse-container--first-level ::slotted(mg-menu){padding:1rem 0}.mg-menu-item{max-width:var(--mg-menu-item-navigation-button-max-width)}.mg-menu-item__collapse-container{position:absolute;top:100%;left:0;width:max-content;z-index:10}.mg-menu-item__navigation-button-center{min-width:0}.mg-menu-item__navigation-button-text-content{width:100%;display:flex}.mg-menu-item__navigation-button-text-content ::slotted([slot=information]){margin-left:1rem}.mg-menu-item__navigation-button-chevron{margin-left:auto;transition:200ms}.mg-menu-item__navigation-button-chevron--rotate.mg-menu-item__navigation-button-chevron{transform:rotate(180deg)}::slotted([slot=label]),::slotted([slot=metadata]){display:block;text-align:left;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}";
|
|
3369
|
+
|
|
3370
|
+
const MgMenuItem = class {
|
|
3371
|
+
constructor(hostRef) {
|
|
3372
|
+
registerInstance(this, hostRef);
|
|
3373
|
+
/************
|
|
3374
|
+
* Internal *
|
|
3375
|
+
************/
|
|
3376
|
+
this.name = 'mg-menu-item';
|
|
3377
|
+
this.navigationButton = `${this.name}__navigation-button`;
|
|
3378
|
+
/**
|
|
3379
|
+
* Define menu-item status. Default: "visible"
|
|
3380
|
+
*/
|
|
3381
|
+
this.status = Status$1.VISIBLE;
|
|
3382
|
+
/**
|
|
3383
|
+
* Define menu-item size. Default: "large".
|
|
3384
|
+
*/
|
|
3385
|
+
this.size = 'large';
|
|
3386
|
+
/**
|
|
3387
|
+
* Define menu-item content expanded. Default: false.
|
|
3388
|
+
*/
|
|
3389
|
+
this.expanded = false;
|
|
3390
|
+
/************
|
|
3391
|
+
* States *
|
|
3392
|
+
************/
|
|
3393
|
+
/**
|
|
3394
|
+
* Component classes
|
|
3395
|
+
*/
|
|
3396
|
+
this.classList = new ClassList([this.name]);
|
|
3397
|
+
/**
|
|
3398
|
+
* Component button classes
|
|
3399
|
+
*/
|
|
3400
|
+
this.navigationButtonClassList = new ClassList([this.navigationButton]);
|
|
3401
|
+
/**
|
|
3402
|
+
* Does component have children. Default: false.
|
|
3403
|
+
*/
|
|
3404
|
+
this.hasChildren = false;
|
|
3405
|
+
/************
|
|
3406
|
+
* Methods *
|
|
3407
|
+
************/
|
|
3408
|
+
/**
|
|
3409
|
+
* Toggle expanded prop value
|
|
3410
|
+
*
|
|
3411
|
+
* @returns {void}
|
|
3412
|
+
*/
|
|
3413
|
+
this.toggleExpanded = () => {
|
|
3414
|
+
this.expanded = !this.expanded;
|
|
3415
|
+
};
|
|
3416
|
+
/**
|
|
3417
|
+
* Does an HTMLElement contain child with given Status
|
|
3418
|
+
*
|
|
3419
|
+
* @param {HTMLElement} element to parse
|
|
3420
|
+
* @param {MgMenuItem['status']} status to check
|
|
3421
|
+
* @returns {boolean} true if element with status is found
|
|
3422
|
+
*/
|
|
3423
|
+
this.hasChildElementStatus = (element, status) => element.querySelector(`${this.name}[status="${status}"]`) !== null;
|
|
3424
|
+
/**
|
|
3425
|
+
* Is component contextual direction match the given direction
|
|
3426
|
+
*
|
|
3427
|
+
* @param {MgMenuItem['direction']} direction in parent menu
|
|
3428
|
+
* @returns {boolean} true is direction match the direction propertie
|
|
3429
|
+
*/
|
|
3430
|
+
this.isdirection = (direction) => this.direction === direction;
|
|
3431
|
+
/************
|
|
3432
|
+
* Handlers *
|
|
3433
|
+
************/
|
|
3434
|
+
/**
|
|
3435
|
+
* Handle interacrtive element click
|
|
3436
|
+
*
|
|
3437
|
+
* @param {MouseEvent} event click on element
|
|
3438
|
+
* @returns {void}
|
|
3439
|
+
*/
|
|
3440
|
+
this.handleElementCLick = (event) => {
|
|
3441
|
+
event.preventDefault();
|
|
3442
|
+
if (this.hasChildren)
|
|
3443
|
+
this.toggleExpanded();
|
|
3444
|
+
};
|
|
3445
|
+
}
|
|
3446
|
+
validateStatus(newValue, oldValue) {
|
|
3447
|
+
if (oldValue !== undefined) {
|
|
3448
|
+
this.navigationButtonClassList.delete(`${this.navigationButton}--${oldValue}`);
|
|
3449
|
+
}
|
|
3450
|
+
this.navigationButtonClassList.add(`${this.navigationButton}--${newValue}`);
|
|
3451
|
+
}
|
|
3452
|
+
validateSize(newValue, oldValue) {
|
|
3453
|
+
if (!sizes$1.includes(newValue)) {
|
|
3454
|
+
throw new Error(`<${this.name}> prop "size" must be one of : ${sizes$1.join(', ')}.`);
|
|
3455
|
+
}
|
|
3456
|
+
this.navigationButtonClassList.delete(`${this.navigationButton}--size-${oldValue}`);
|
|
3457
|
+
this.navigationButtonClassList.add(`${this.navigationButton}--size-${newValue}`);
|
|
3458
|
+
}
|
|
3459
|
+
validateExpanded(newValue) {
|
|
3460
|
+
if (typeof newValue !== 'boolean')
|
|
3461
|
+
throw new Error(`<${this.name}> prop "expanded" must be a boolean.`);
|
|
3462
|
+
// if menu-item has sub-menu we have to apply some updates:
|
|
3463
|
+
if (this.hasChildren) {
|
|
3464
|
+
const subItems = Array.from(this.element.querySelectorAll(this.name));
|
|
3465
|
+
if (!newValue) {
|
|
3466
|
+
// - when main menu item is NOT expanded we need NOT expanded sub-items and NOT expanded sub-content
|
|
3467
|
+
subItems.forEach(item => {
|
|
3468
|
+
item.expanded = false;
|
|
3469
|
+
});
|
|
3470
|
+
}
|
|
3471
|
+
else if (newValue && this.hasChildElementStatus(this.element, Status$1.ACTIVE)) {
|
|
3472
|
+
// - when expanded and contain an active item parents are expended too
|
|
3473
|
+
subItems.forEach(item => {
|
|
3474
|
+
if (this.hasChildElementStatus(item, Status$1.ACTIVE)) {
|
|
3475
|
+
item.expanded = true;
|
|
3476
|
+
}
|
|
3477
|
+
});
|
|
3478
|
+
}
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3481
|
+
validateHasChildren(newValue) {
|
|
3482
|
+
if (newValue && this.element.href !== undefined) {
|
|
3483
|
+
throw new Error(`<${this.name}> prop "href" is unauthorizied when element is a parent.`);
|
|
3484
|
+
}
|
|
3485
|
+
}
|
|
3486
|
+
/*************
|
|
3487
|
+
* Lifecycle *
|
|
3488
|
+
*************/
|
|
3489
|
+
/**
|
|
3490
|
+
* Validate props
|
|
3491
|
+
*
|
|
3492
|
+
* @returns {void}
|
|
3493
|
+
*/
|
|
3494
|
+
componentWillLoad() {
|
|
3495
|
+
// has children items that is NOT [slot="illustration"] || [slot="information"] element
|
|
3496
|
+
// we store only matching elements
|
|
3497
|
+
this.hasChildren = Array.from(this.element.children).filter(child => !['illustration', 'information', 'label', 'metadata'].includes(child.getAttribute('slot'))).length > 0;
|
|
3498
|
+
// Validate props
|
|
3499
|
+
this.validateSize(this.size);
|
|
3500
|
+
this.validateStatus(this.status);
|
|
3501
|
+
this.validateExpanded(this.expanded);
|
|
3502
|
+
}
|
|
3503
|
+
/**
|
|
3504
|
+
* Check if component slots configuration
|
|
3505
|
+
*
|
|
3506
|
+
* @returns {ReturnType<typeof setTimeout>} timeout
|
|
3507
|
+
*/
|
|
3508
|
+
componentDidLoad() {
|
|
3509
|
+
// slot title AND metadata validation
|
|
3510
|
+
// add title on label AND metada slots due to text-overflow on these element
|
|
3511
|
+
if (Array.from(this.element.children).find(child => child.getAttribute('slot') === 'label') === undefined)
|
|
3512
|
+
throw new Error(`<${this.name}> slot "label" is required.`);
|
|
3513
|
+
['label', 'metadata'].forEach(slot => {
|
|
3514
|
+
Array.from(this.element.querySelectorAll(`[slot="${slot}"]`)).forEach(element => {
|
|
3515
|
+
if (element.textContent.trim().length < 1)
|
|
3516
|
+
throw new Error(`<${this.name}> slot "${slot}" must have text content.`);
|
|
3517
|
+
if (element.getAttribute('title') === null)
|
|
3518
|
+
element.setAttribute('title', element.textContent);
|
|
3519
|
+
});
|
|
3520
|
+
});
|
|
3521
|
+
// update props and states after componentDidLoad hook
|
|
3522
|
+
// return a promise to process action only in the FIRST render().
|
|
3523
|
+
// https://stenciljs.com/docs/component-lifecycle#componentwillload
|
|
3524
|
+
return setTimeout(() => {
|
|
3525
|
+
var _a, _b;
|
|
3526
|
+
// define menu-item context states
|
|
3527
|
+
if (this.element.parentElement.nodeName === 'MG-MENU') {
|
|
3528
|
+
this.direction = this.element.parentElement.direction;
|
|
3529
|
+
}
|
|
3530
|
+
this.isInMainMenu = this.element.parentElement.className.includes('mg-menu-item') === false;
|
|
3531
|
+
const hasNextMenuItem = ((_a = this.element.nextElementSibling) === null || _a === void 0 ? void 0 : _a.nodeName) === 'MG-MENU-ITEM';
|
|
3532
|
+
const hasPreviousMenuItem = ((_b = this.element.previousElementSibling) === null || _b === void 0 ? void 0 : _b.nodeName) === 'MG-MENU-ITEM';
|
|
3533
|
+
// manage last menu item
|
|
3534
|
+
if (!hasNextMenuItem && hasPreviousMenuItem && this.isdirection(Direction.HORIZONTAL)) {
|
|
3535
|
+
this.classList.add(`${this.name}--${ElementPosition.LAST}`);
|
|
3536
|
+
}
|
|
3537
|
+
// when main menu item contain an active item it will get the active style
|
|
3538
|
+
// AND if item is in vertical menu it will be expanded
|
|
3539
|
+
if (this.isInMainMenu && this.hasChildElementStatus(this.element, Status$1.ACTIVE)) {
|
|
3540
|
+
this.status = Status$1.ACTIVE;
|
|
3541
|
+
this.expanded = this.direction === Direction.VERTICAL;
|
|
3542
|
+
}
|
|
3543
|
+
// manage menu items style depending to parent menu horientation
|
|
3544
|
+
this.classList.add(`${this.name}--${this.direction}`);
|
|
3545
|
+
this.navigationButtonClassList.add(`${this.navigationButton}--${this.direction}`);
|
|
3546
|
+
// manage child items level
|
|
3547
|
+
const childItems = Array.from(this.element.querySelectorAll('mg-menu-item'));
|
|
3548
|
+
childItems.forEach(item => {
|
|
3549
|
+
if (this.direction === Direction.VERTICAL) {
|
|
3550
|
+
const itemLevel = Number(item.getAttribute('data-level')) || 1;
|
|
3551
|
+
item.setAttribute('data-level', `${itemLevel + 1}`);
|
|
3552
|
+
}
|
|
3553
|
+
});
|
|
3554
|
+
}, 0);
|
|
3555
|
+
}
|
|
3556
|
+
/**
|
|
3557
|
+
* Render
|
|
3558
|
+
*
|
|
3559
|
+
* @returns {HTMLElement} HTML Element
|
|
3560
|
+
*/
|
|
3561
|
+
render() {
|
|
3562
|
+
const TagName = this.href !== undefined ? 'a' : 'button';
|
|
3563
|
+
return (h(Host, { role: "menuitem", "aria-haspopup": this.hasChildren.toString(), class: this.classList.join() }, h(TagName, { href: this.href, class: this.navigationButtonClassList.join(), tabindex: [Status$1.DISABLED, Status$1.HIDDEN].includes(this.status) ? -1 : 0, disabled: this.status === Status$1.DISABLED, "aria-expanded": this.hasChildren && this.expanded.toString(), "aria-current": this.status === Status$1.ACTIVE && 'page', onClick: this.handleElementCLick }, h("slot", { name: "illustration" }), h("div", { class: `${this.navigationButton}-center` }, h("div", { class: `${this.navigationButton}-text-content` }, h("slot", { name: "label" }), h("slot", { name: "information" })), h("slot", { name: "metadata" })), this.hasChildren && this.href === undefined && (h("span", { class: {
|
|
3564
|
+
[`${this.navigationButton}-chevron`]: true,
|
|
3565
|
+
[`${this.navigationButton}-chevron--rotate`]: this.expanded === true,
|
|
3566
|
+
} }, h("mg-icon", { icon: "chevron-down" })))), h("div", { class: { [`${this.name}__collapse-container`]: true, [`${this.name}__collapse-container--first-level`]: this.isInMainMenu && this.isdirection(Direction.HORIZONTAL) }, hidden: !this.expanded }, h("slot", null))));
|
|
3567
|
+
}
|
|
3568
|
+
get element() { return getElement(this); }
|
|
3569
|
+
static get watchers() { return {
|
|
3570
|
+
"status": ["validateStatus"],
|
|
3571
|
+
"size": ["validateSize"],
|
|
3572
|
+
"expanded": ["validateExpanded"],
|
|
3573
|
+
"hasChildren": ["validateHasChildren"]
|
|
3574
|
+
}; }
|
|
3575
|
+
};
|
|
3576
|
+
MgMenuItem.style = mgMenuItemCss;
|
|
3577
|
+
|
|
3092
3578
|
/**
|
|
3093
3579
|
* List of all possibles message variants
|
|
3094
3580
|
*/
|
|
@@ -3104,7 +3590,7 @@ const MgMessage = class {
|
|
|
3104
3590
|
/************
|
|
3105
3591
|
* Internal *
|
|
3106
3592
|
************/
|
|
3107
|
-
//
|
|
3593
|
+
// Classes
|
|
3108
3594
|
this.classHide = 'mg-message--hide';
|
|
3109
3595
|
// IDs
|
|
3110
3596
|
this.closeButtonId = '';
|
|
@@ -3382,10 +3868,6 @@ const MgModal = class {
|
|
|
3382
3868
|
*/
|
|
3383
3869
|
componentDidLoad() {
|
|
3384
3870
|
new MutationObserver(mutationList => {
|
|
3385
|
-
/*
|
|
3386
|
-
TODO find a way to cover this callback
|
|
3387
|
-
*/
|
|
3388
|
-
/* istanbul ignore next */
|
|
3389
3871
|
if (mutationList.some(mutation => mutation.attributeName === 'aria-hidden' && mutation.target.ariaHidden === null)) {
|
|
3390
3872
|
this.setFocus();
|
|
3391
3873
|
}
|
|
@@ -5675,6 +6157,9 @@ const MgPopover = class {
|
|
|
5675
6157
|
};
|
|
5676
6158
|
MgPopover.style = mgPopoverCss;
|
|
5677
6159
|
|
|
6160
|
+
/**
|
|
6161
|
+
* Available tabs items status
|
|
6162
|
+
*/
|
|
5678
6163
|
var Status;
|
|
5679
6164
|
(function (Status) {
|
|
5680
6165
|
Status["VISIBLE"] = "visible";
|
|
@@ -5687,7 +6172,7 @@ var Status;
|
|
|
5687
6172
|
*/
|
|
5688
6173
|
const sizes = ['regular', 'large'];
|
|
5689
6174
|
|
|
5690
|
-
const mgTabsCss = ".mg-tabs.mg-tabs--size-regular .mg-tabs__navigation-button{padding:calc(1rem
|
|
6175
|
+
const mgTabsCss = ".mg-tabs.mg-tabs--size-regular .mg-tabs__navigation-button,.mg-tabs__navigation-button.mg-tabs__navigation-button--size-regular{padding:1rem 2rem}.mg-tabs.mg-tabs--size-regular .mg-tabs__navigation-button,.mg-tabs.mg-tabs--size-regular .mg-tabs__navigation-button ::slotted([slot=label]),.mg-tabs.mg-tabs--size-regular .mg-tabs__navigation-button ::slotted([slot=metadata]),.mg-tabs__navigation-button.mg-tabs__navigation-button--size-regular,.mg-tabs__navigation-button.mg-tabs__navigation-button--size-regular ::slotted([slot=label]),.mg-tabs__navigation-button.mg-tabs__navigation-button--size-regular ::slotted([slot=metadata]){font-size:1.3rem}.mg-tabs.mg-tabs--size-regular .mg-tabs__navigation-button.mg-tabs__navigation-button--horizontal,.mg-tabs__navigation-button.mg-tabs__navigation-button--size-regular.mg-tabs__navigation-button--horizontal{padding-bottom:calc(1rem - 0.3rem)}.mg-tabs.mg-tabs--size-regular .mg-tabs__navigation-button.mg-tabs__navigation-button--vertical,.mg-tabs__navigation-button.mg-tabs__navigation-button--size-regular.mg-tabs__navigation-button--vertical{padding-left:calc(2rem - 0.3rem)}.mg-tabs.mg-tabs--size-large .mg-tabs__navigation-button,.mg-tabs__navigation-button.mg-tabs__navigation-button--size-large{padding:1.5rem 3rem}.mg-tabs.mg-tabs--size-large .mg-tabs__navigation-button,.mg-tabs.mg-tabs--size-large .mg-tabs__navigation-button ::slotted([slot=label]),.mg-tabs.mg-tabs--size-large .mg-tabs__navigation-button ::slotted([slot=metadata]),.mg-tabs__navigation-button.mg-tabs__navigation-button--size-large,.mg-tabs__navigation-button.mg-tabs__navigation-button--size-large ::slotted([slot=label]),.mg-tabs__navigation-button.mg-tabs__navigation-button--size-large ::slotted([slot=metadata]){font-size:1.5rem}.mg-tabs.mg-tabs--size-large .mg-tabs__navigation-button.mg-tabs__navigation-button--horizontal,.mg-tabs__navigation-button.mg-tabs__navigation-button--size-large.mg-tabs__navigation-button--horizontal{padding-bottom:calc(1.5rem - 0.3rem)}.mg-tabs.mg-tabs--size-large .mg-tabs__navigation-button.mg-tabs__navigation-button--vertical,.mg-tabs__navigation-button.mg-tabs__navigation-button--size-large.mg-tabs__navigation-button--vertical{padding-left:calc(3rem - 0.3rem)}.mg-tabs__navigation-button{display:flex;align-items:center;column-gap:1rem;background-color:unset;border:none;font-family:var(--font-family);color:hsl(var(--mg-tabs-color-hsl, var(--color-dark)));line-height:var(--line-height);text-decoration:none;cursor:pointer}.mg-tabs__navigation-button:disabled,.mg-tabs__navigation-button--disabled{cursor:default;opacity:30%}.mg-tabs__navigation-button:focus-visible{z-index:10}.mg-tabs__navigation-button:hover:not(.mg-tabs__navigation-button--disabled),.mg-tabs__navigation-button:focus:not(.mg-tabs__navigation-button--disabled){background-color:hsla(var(--mg-tabs-focused-background-color-hsl), 10%)}.mg-tabs__navigation-button.mg-tabs__navigation-button--active{color:hsl(var(--mg-tabs-color-active-hsl));font-weight:700}.mg-tabs__navigation-button.mg-tabs__navigation-button--active.mg-tabs__navigation-button--horizontal{border-bottom-color:hsl(var(--mg-tabs-border-color-active-hsl))}.mg-tabs__navigation-button.mg-tabs__navigation-button--active.mg-tabs__navigation-button--vertical{border-left-color:hsl(var(--mg-tabs-border-color-active-hsl))}.mg-tabs__navigation-button.mg-tabs__navigation-button--hidden{display:none}.mg-tabs__navigation-button.mg-tabs__navigation-button--horizontal{border-bottom:0.3rem solid transparent}.mg-tabs__navigation-button.mg-tabs__navigation-button--vertical{border-left:0.3rem solid transparent}.mg-tabs__header{display:flex;flex-direction:row;flex-wrap:wrap}.mg-tabs__content-container:focus-visible{outline:none}.mg-tabs__navigation-button-text{flex:0 0 content}";
|
|
5691
6176
|
|
|
5692
6177
|
/**
|
|
5693
6178
|
* type TabItem validation function
|
|
@@ -5875,10 +6360,11 @@ const MgTabs = class {
|
|
|
5875
6360
|
render() {
|
|
5876
6361
|
return (h("div", { class: this.classList.join() }, h("header", { role: "tablist", "aria-label": this.label, class: "mg-tabs__header" }, this.tabs.map((tab, index) => (h("button", { role: "tab", id: this.getElementId(this.identifier, index), class: {
|
|
5877
6362
|
[`${this.buttonTabBaseClass}`]: true,
|
|
6363
|
+
[`${this.buttonTabBaseClass}--horizontal`]: true,
|
|
5878
6364
|
[`${this.getNavigationButtonClass(Status.ACTIVE)}`]: this.tabHasGivenStatus(tab, Status.ACTIVE),
|
|
5879
6365
|
[`${this.getNavigationButtonClass(Status.DISABLED)}`]: this.tabHasGivenStatus(tab, Status.DISABLED),
|
|
5880
6366
|
[`${this.getNavigationButtonClass(Status.HIDDEN)}`]: this.tabHasGivenStatus(tab, Status.HIDDEN),
|
|
5881
|
-
}, tabindex: this.tabHasGivenStatus(tab, Status.ACTIVE) ? 0 : -1, "aria-selected": this.tabHasGivenStatus(tab, Status.ACTIVE).toString(), "aria-controls": this.getElementId(this.tabPanel, index), onClick: this.handleClick, onKeyDown: this.handleKeydown, "data-index": this.getTabIndex(index), disabled: this.tabHasGivenStatus(tab, Status.DISABLED) }, tab.icon !== undefined && h("mg-icon", { icon: tab.icon }), tab.label, tab.badge !== undefined && h("mg-badge", { variant:
|
|
6367
|
+
}, tabindex: this.tabHasGivenStatus(tab, Status.ACTIVE) ? 0 : -1, "aria-selected": this.tabHasGivenStatus(tab, Status.ACTIVE).toString(), "aria-controls": this.getElementId(this.tabPanel, index), onClick: this.handleClick, onKeyDown: this.handleKeydown, "data-index": this.getTabIndex(index), disabled: this.tabHasGivenStatus(tab, Status.DISABLED) }, tab.icon !== undefined && h("mg-icon", { icon: tab.icon }), tab.label, tab.badge !== undefined && h("mg-badge", { variant: tab.status !== Status.ACTIVE ? 'primary' : 'info', value: tab.badge.value, label: tab.badge.label }))))), this.tabs.map((tab, index) => (h("article", { role: "tabpanel", id: this.getElementId(this.tabPanel, index), hidden: !this.tabHasGivenStatus(tab, Status.ACTIVE), "aria-labelledby": this.getElementId(this.identifier, index), tabindex: this.tabHasGivenStatus(tab, Status.ACTIVE) ? 0 : -1, class: "mg-tabs__content-container" }, h("slot", { name: this.getElementId('tab_content', index) }))))));
|
|
5882
6368
|
}
|
|
5883
6369
|
get element() { return getElement(this); }
|
|
5884
6370
|
static get watchers() { return {
|
|
@@ -5903,7 +6389,7 @@ const MgTag = class {
|
|
|
5903
6389
|
/************
|
|
5904
6390
|
* Internal *
|
|
5905
6391
|
************/
|
|
5906
|
-
//
|
|
6392
|
+
// Classes
|
|
5907
6393
|
this.classOutline = `mg-tag--outline`;
|
|
5908
6394
|
/**************
|
|
5909
6395
|
* Decorators *
|
|
@@ -6161,4 +6647,4 @@ const MgTooltip = class {
|
|
|
6161
6647
|
};
|
|
6162
6648
|
MgTooltip.style = mgTooltipCss;
|
|
6163
6649
|
|
|
6164
|
-
export { MgBadge as mg_badge, MgButton as mg_button, MgCard as mg_card, MgCharacterLeft as mg_character_left, MgDetails as mg_details, MgDivider as mg_divider, MgForm as mg_form, MgIcon as mg_icon, MgIllustratedMessage as mg_illustrated_message, MgInputCheckbox as mg_input_checkbox, MgInputDate as mg_input_date, MgInputNumeric as mg_input_numeric, MgInputPassword as mg_input_password, MgInputRadio as mg_input_radio, MgInputSelect as mg_input_select, MgInputText as mg_input_text, MgInputTextarea as mg_input_textarea, MgInputTitle as mg_input_title, MgInputToggle as mg_input_toggle, MgMessage as mg_message, MgModal as mg_modal, MgPagination as mg_pagination, MgPanel as mg_panel, MgPopover as mg_popover, MgTabs as mg_tabs, MgTag as mg_tag, MgTooltip as mg_tooltip };
|
|
6650
|
+
export { MgBadge as mg_badge, MgButton as mg_button, MgCard as mg_card, MgCharacterLeft as mg_character_left, MgDetails as mg_details, MgDivider as mg_divider, MgForm as mg_form, MgIcon as mg_icon, MgIllustratedMessage as mg_illustrated_message, MgInputCheckbox as mg_input_checkbox, MgInputDate as mg_input_date, MgInputNumeric as mg_input_numeric, MgInputPassword as mg_input_password, MgInputRadio as mg_input_radio, MgInputSelect as mg_input_select, MgInputText as mg_input_text, MgInputTextarea as mg_input_textarea, MgInputTitle as mg_input_title, MgInputToggle as mg_input_toggle, MgMenu as mg_menu, MgMenuItem as mg_menu_item, MgMessage as mg_message, MgModal as mg_modal, MgPagination as mg_pagination, MgPanel as mg_panel, MgPopover as mg_popover, MgTabs as mg_tabs, MgTag as mg_tag, MgTooltip as mg_tooltip };
|