@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
|
@@ -106,7 +106,7 @@ const MgBadge = class {
|
|
|
106
106
|
/************
|
|
107
107
|
* Internal *
|
|
108
108
|
************/
|
|
109
|
-
//
|
|
109
|
+
// Classes
|
|
110
110
|
this.classOutline = `mg-badge--outline`;
|
|
111
111
|
/**
|
|
112
112
|
* Define button variant
|
|
@@ -233,7 +233,7 @@ const MgButton = class {
|
|
|
233
233
|
}
|
|
234
234
|
};
|
|
235
235
|
/**
|
|
236
|
-
* Handle
|
|
236
|
+
* Handle onKeydown event
|
|
237
237
|
*
|
|
238
238
|
* @param {KeyboardEvent} event keyboard event
|
|
239
239
|
* @returns {void}
|
|
@@ -248,7 +248,7 @@ const MgButton = class {
|
|
|
248
248
|
}
|
|
249
249
|
};
|
|
250
250
|
/**
|
|
251
|
-
* Handle
|
|
251
|
+
* Handle onKeyup event
|
|
252
252
|
*
|
|
253
253
|
* @param {KeyboardEvent} event keyboard event
|
|
254
254
|
* @returns {void}
|
|
@@ -331,7 +331,7 @@ const MgButton = class {
|
|
|
331
331
|
* @returns {HTMLElement} html element
|
|
332
332
|
*/
|
|
333
333
|
render() {
|
|
334
|
-
return (index.h(index.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,
|
|
334
|
+
return (index.h(index.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 }, index.h("div", { class: this.classList.join(), id: this.identifier }, this.loading && index.h("mg-icon", { icon: "loader", spin: true }), index.h("div", { class: "mg-button__content" }, index.h("slot", null)))));
|
|
335
335
|
}
|
|
336
336
|
get element() { return index.getElement(this); }
|
|
337
337
|
static get watchers() { return {
|
|
@@ -493,7 +493,9 @@ const messages = { en, fr };
|
|
|
493
493
|
*/
|
|
494
494
|
const getLocale = (element) => {
|
|
495
495
|
var _a;
|
|
496
|
-
|
|
496
|
+
// validate locale
|
|
497
|
+
const closestLang = Intl.NumberFormat.supportedLocalesOf((_a = element.closest('[lang]')) === null || _a === void 0 ? void 0 : _a.lang);
|
|
498
|
+
return closestLang.length > 0 ? closestLang[0] : navigator.language || defaultLocale;
|
|
497
499
|
};
|
|
498
500
|
/**
|
|
499
501
|
* Get Intl object
|
|
@@ -650,6 +652,8 @@ const MgForm = class {
|
|
|
650
652
|
index.registerInstance(this, hostRef);
|
|
651
653
|
this.formValid = index.createEvent(this, "form-valid", 7);
|
|
652
654
|
this.formSubmit = index.createEvent(this, "form-submit", 7);
|
|
655
|
+
// Classes
|
|
656
|
+
this.classAllRequired = 'mg-form--all-required';
|
|
653
657
|
/**
|
|
654
658
|
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
655
659
|
* If not set, it will be created.
|
|
@@ -679,17 +683,24 @@ const MgForm = class {
|
|
|
679
683
|
* @returns {void}
|
|
680
684
|
*/
|
|
681
685
|
this.setRequiredMessage = () => {
|
|
682
|
-
//
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
//
|
|
686
|
-
if
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
686
|
+
// init required message
|
|
687
|
+
this.requiredMessage = null;
|
|
688
|
+
this.classList.delete(this.classAllRequired);
|
|
689
|
+
// If the form is disabled or readonly none of them are required
|
|
690
|
+
// Check if all fields are not editable (readonly or disabled)
|
|
691
|
+
if (!this.disabled && !this.readonly && !this.mgInputs.every(input => input.disabled || input.readonly)) {
|
|
692
|
+
// Get required fields
|
|
693
|
+
const requiredInputs = this.mgInputs.filter(input => input.required && !input.disabled && !input.readonly);
|
|
694
|
+
// All fields are required
|
|
695
|
+
// mg-input-toggle can not be required
|
|
696
|
+
if (requiredInputs.length > 0 && requiredInputs.length === this.mgInputs.filter(input => input.nodeName !== 'MG-INPUT-TOGGLE').length) {
|
|
697
|
+
this.requiredMessage = this.messages.form.allRequired;
|
|
698
|
+
this.classList.add(this.classAllRequired);
|
|
699
|
+
}
|
|
700
|
+
// Some fields are required
|
|
701
|
+
else if (requiredInputs.length > 0) {
|
|
702
|
+
this.requiredMessage = this.messages.form.required;
|
|
703
|
+
}
|
|
693
704
|
}
|
|
694
705
|
};
|
|
695
706
|
/**
|
|
@@ -698,15 +709,46 @@ const MgForm = class {
|
|
|
698
709
|
* @returns {void}
|
|
699
710
|
*/
|
|
700
711
|
this.checkValidity = () => {
|
|
701
|
-
|
|
702
|
-
this.
|
|
703
|
-
this.
|
|
704
|
-
this.
|
|
712
|
+
// Update required on input event
|
|
713
|
+
this.setRequiredMessage();
|
|
714
|
+
this.valid = !this.mgInputs.some(input => input.invalid);
|
|
715
|
+
this.invalid = !this.valid;
|
|
716
|
+
// We need to send valid event if it is the same value
|
|
717
|
+
this.formValid.emit(this.valid);
|
|
705
718
|
};
|
|
719
|
+
/**
|
|
720
|
+
* Handle Form Submit
|
|
721
|
+
*
|
|
722
|
+
* @param {SubmitEvent} event submit event
|
|
723
|
+
* @returns {void}
|
|
724
|
+
*/
|
|
706
725
|
this.handleFormSubmit = (event) => {
|
|
707
726
|
event.preventDefault();
|
|
708
727
|
this.formSubmit.emit();
|
|
709
728
|
};
|
|
729
|
+
/**
|
|
730
|
+
* Set mgInputs
|
|
731
|
+
*
|
|
732
|
+
* @returns {void}
|
|
733
|
+
*/
|
|
734
|
+
this.setMgInputs = () => {
|
|
735
|
+
// Get slotted mgInputs
|
|
736
|
+
this.mgInputs = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-INPUT-'));
|
|
737
|
+
// Set inputs readonly or disabled based on form configuration
|
|
738
|
+
// Othewise listen to events
|
|
739
|
+
this.mgInputs.map(input => {
|
|
740
|
+
if (this.readonly)
|
|
741
|
+
input.readonly = true;
|
|
742
|
+
else if (this.disabled)
|
|
743
|
+
input.disabled = true;
|
|
744
|
+
else
|
|
745
|
+
input.addEventListener('input-valid', this.checkValidity);
|
|
746
|
+
});
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
handleAttributeChange() {
|
|
750
|
+
this.setMgInputs();
|
|
751
|
+
this.setRequiredMessage();
|
|
710
752
|
}
|
|
711
753
|
/**
|
|
712
754
|
* Public method to display errors
|
|
@@ -732,26 +774,18 @@ const MgForm = class {
|
|
|
732
774
|
componentWillLoad() {
|
|
733
775
|
// Get locales
|
|
734
776
|
this.messages = initLocales(this.element).messages;
|
|
735
|
-
// Get slotted mgInputs
|
|
736
|
-
this.mgInputs = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-INPUT-'));
|
|
737
777
|
// Get slotted mgButtons
|
|
738
|
-
this.mgButtons = Array.from(this.element.querySelectorAll('
|
|
778
|
+
this.mgButtons = Array.from(this.element.querySelectorAll('mg-button'));
|
|
739
779
|
// Set button form identifier
|
|
740
780
|
this.mgButtons.forEach(mgButton => {
|
|
741
781
|
mgButton.setAttribute('form', this.identifier);
|
|
742
782
|
});
|
|
783
|
+
// Set mgInputs
|
|
784
|
+
this.setMgInputs();
|
|
743
785
|
// Define required message
|
|
744
786
|
this.setRequiredMessage();
|
|
745
787
|
// Check validity when slotted mgInputs are ready
|
|
746
788
|
Promise.all(this.mgInputs.map(async (input) => {
|
|
747
|
-
// Set inputs readonly or disabled based on form configuration
|
|
748
|
-
// Othewise listen to events
|
|
749
|
-
if (this.readonly)
|
|
750
|
-
input.readonly = true;
|
|
751
|
-
else if (this.disabled)
|
|
752
|
-
input.disabled = true;
|
|
753
|
-
else
|
|
754
|
-
input.addEventListener('input-valid', this.checkValidity);
|
|
755
789
|
try {
|
|
756
790
|
await input.componentOnReady();
|
|
757
791
|
}
|
|
@@ -774,6 +808,10 @@ const MgForm = class {
|
|
|
774
808
|
});
|
|
775
809
|
}
|
|
776
810
|
});
|
|
811
|
+
// Update mgInputs when mgForm content change
|
|
812
|
+
new MutationObserver(() => {
|
|
813
|
+
this.setMgInputs();
|
|
814
|
+
}).observe(this.element, { childList: true });
|
|
777
815
|
}
|
|
778
816
|
/**
|
|
779
817
|
* Render
|
|
@@ -784,6 +822,10 @@ const MgForm = class {
|
|
|
784
822
|
return (index.h("form", { class: this.classList.join(), id: this.identifier, name: this.name, ref: el => (this.form = el), onSubmit: this.handleFormSubmit }, this.requiredMessage && index.h("p", { innerHTML: this.requiredMessage }), index.h("slot", null), !this.readonly && !this.disabled && index.h("slot", { name: "actions" })));
|
|
785
823
|
}
|
|
786
824
|
get element() { return index.getElement(this); }
|
|
825
|
+
static get watchers() { return {
|
|
826
|
+
"readonly": ["handleAttributeChange"],
|
|
827
|
+
"disabled": ["handleAttributeChange"]
|
|
828
|
+
}; }
|
|
787
829
|
};
|
|
788
830
|
MgForm.style = mgFormCss;
|
|
789
831
|
|
|
@@ -946,7 +988,7 @@ const icons = {
|
|
|
946
988
|
/**
|
|
947
989
|
* List of all possibles sizes
|
|
948
990
|
*/
|
|
949
|
-
const sizes$
|
|
991
|
+
const sizes$2 = ['small', 'regular', 'large', 'extra-large'];
|
|
950
992
|
/**
|
|
951
993
|
* List of all possibles variants
|
|
952
994
|
*/
|
|
@@ -988,8 +1030,8 @@ const MgIcon = class {
|
|
|
988
1030
|
}
|
|
989
1031
|
}
|
|
990
1032
|
validateSize(newValue, oldValue) {
|
|
991
|
-
if (!sizes$
|
|
992
|
-
throw new Error(`<mg-icon> prop "size" must be one of : ${sizes$
|
|
1033
|
+
if (!sizes$2.includes(newValue)) {
|
|
1034
|
+
throw new Error(`<mg-icon> prop "size" must be one of : ${sizes$2.join(', ')}`);
|
|
993
1035
|
}
|
|
994
1036
|
else {
|
|
995
1037
|
if (oldValue !== undefined) {
|
|
@@ -1172,15 +1214,6 @@ const MgInput = (props, children, utils) => {
|
|
|
1172
1214
|
if (typeof props.errorMessage === 'string' && props.errorMessage !== '') {
|
|
1173
1215
|
ariaDescribedbyIDs.add(helpTextErrorId);
|
|
1174
1216
|
}
|
|
1175
|
-
/**
|
|
1176
|
-
* Update input(s) in children
|
|
1177
|
-
*/
|
|
1178
|
-
if (props.readonly) {
|
|
1179
|
-
children = children.filter(child => child.$name$ === 'append-input');
|
|
1180
|
-
}
|
|
1181
|
-
else {
|
|
1182
|
-
children = applyAriadescribedBy(children, ariaDescribedbyIDs, utils);
|
|
1183
|
-
}
|
|
1184
1217
|
/**
|
|
1185
1218
|
* Return template
|
|
1186
1219
|
*
|
|
@@ -1206,19 +1239,20 @@ const MgInput = (props, children, utils) => {
|
|
|
1206
1239
|
index.h("mg-icon", { icon: "info-circle" })));
|
|
1207
1240
|
/**
|
|
1208
1241
|
* Get input title (label) node
|
|
1242
|
+
* Display asterisk only if not disabled and not readonly
|
|
1209
1243
|
*
|
|
1210
1244
|
* @returns {VNode[]} mg-input-title
|
|
1211
1245
|
*/
|
|
1212
|
-
const getInputTitle = () => (index.h("mg-input-title", { identifier: props.identifier, class: props.labelHide ? 'sr-only' : undefined, required: props.required && !props.disabled, "is-legend": props.isFieldset }, props.label));
|
|
1246
|
+
const getInputTitle = () => (index.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));
|
|
1213
1247
|
return (index.h(TagName, { class: props.classList.join() },
|
|
1214
1248
|
props.labelOnTop ? (index.h("div", { class: "mg-input__title" },
|
|
1215
1249
|
getInputTitle(),
|
|
1216
1250
|
!props.readonly && props.tooltip && getTooltip())) : (getInputTitle()),
|
|
1217
1251
|
props.readonly ? (index.h("div", { class: "mg-input__input-container" },
|
|
1218
1252
|
index.h("strong", null, props.readonlyValue || props.value),
|
|
1219
|
-
children)) : (index.h("div", { class: "mg-input__input-container" },
|
|
1253
|
+
children.filter(child => child.$name$ === 'append-input'))) : (index.h("div", { class: "mg-input__input-container" },
|
|
1220
1254
|
index.h("div", { class: { 'mg-input__input': true, 'mg-input__input--has-error': props.errorMessage !== undefined } },
|
|
1221
|
-
children,
|
|
1255
|
+
applyAriadescribedBy(children, ariaDescribedbyIDs, utils),
|
|
1222
1256
|
!props.labelOnTop && props.tooltip && getTooltip()),
|
|
1223
1257
|
props.helpText && index.h("div", { id: helpTextId, class: "mg-input__help-text", innerHTML: props.helpText }),
|
|
1224
1258
|
props.errorMessage && !props.readonly && !props.disabled && (index.h("div", { id: helpTextErrorId, class: "mg-input__error", innerHTML: props.errorMessage, "aria-live": "assertive" }))))));
|
|
@@ -1243,6 +1277,8 @@ const MgInputCheckbox = class {
|
|
|
1243
1277
|
************/
|
|
1244
1278
|
// HTML selector
|
|
1245
1279
|
this.inputs = [];
|
|
1280
|
+
// hasDisplayedError (triggered by blur event)
|
|
1281
|
+
this.hasDisplayedError = false;
|
|
1246
1282
|
/**
|
|
1247
1283
|
* Input name
|
|
1248
1284
|
* If not set the value equals the identifier
|
|
@@ -1297,25 +1333,27 @@ const MgInputCheckbox = class {
|
|
|
1297
1333
|
this.handleBlur = () => {
|
|
1298
1334
|
// Check validity
|
|
1299
1335
|
this.checkValidity();
|
|
1300
|
-
this.
|
|
1336
|
+
this.setErrorMessage();
|
|
1301
1337
|
};
|
|
1338
|
+
/**
|
|
1339
|
+
* get invalid element
|
|
1340
|
+
*
|
|
1341
|
+
* @returns {HTMLInputElement} element
|
|
1342
|
+
*/
|
|
1343
|
+
this.getInvalidElement = () => this.inputs.find((input) => input !== null && !input.disabled && !input.checkValidity());
|
|
1302
1344
|
/**
|
|
1303
1345
|
* Check if input is valid
|
|
1304
1346
|
*/
|
|
1305
1347
|
this.checkValidity = () => {
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
this.invalid = !validity;
|
|
1311
|
-
//Send event
|
|
1312
|
-
this.inputValid.emit(validity);
|
|
1313
|
-
}
|
|
1348
|
+
this.valid = this.readonly || this.disabled || this.getInvalidElement() === undefined;
|
|
1349
|
+
this.invalid = !this.valid;
|
|
1350
|
+
// We need to send valid event even if it is the same value
|
|
1351
|
+
this.inputValid.emit(this.valid);
|
|
1314
1352
|
};
|
|
1315
1353
|
/**
|
|
1316
|
-
*
|
|
1354
|
+
* Set input error message
|
|
1317
1355
|
*/
|
|
1318
|
-
this.
|
|
1356
|
+
this.setErrorMessage = () => {
|
|
1319
1357
|
const invalidElement = this.getInvalidElement();
|
|
1320
1358
|
// Set error message
|
|
1321
1359
|
this.errorMessage = undefined;
|
|
@@ -1323,12 +1361,6 @@ const MgInputCheckbox = class {
|
|
|
1323
1361
|
this.errorMessage = this.messages.errors.required;
|
|
1324
1362
|
}
|
|
1325
1363
|
};
|
|
1326
|
-
/**
|
|
1327
|
-
* get invalid element
|
|
1328
|
-
*
|
|
1329
|
-
* @returns {HTMLInputElement} element
|
|
1330
|
-
*/
|
|
1331
|
-
this.getInvalidElement = () => this.inputs.find((element) => !element.disabled && !element.checkValidity());
|
|
1332
1364
|
}
|
|
1333
1365
|
validateValue(newValue) {
|
|
1334
1366
|
if (newValue && newValue.every(item => isCheckboxItem(item))) {
|
|
@@ -1344,6 +1376,16 @@ const MgInputCheckbox = class {
|
|
|
1344
1376
|
throw new Error('<mg-input-checkbox> prop "value" is required and all values must be the same type, CheckboxItem.');
|
|
1345
1377
|
}
|
|
1346
1378
|
}
|
|
1379
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
1380
|
+
this.inputs.forEach(input => {
|
|
1381
|
+
input[prop] = newValue;
|
|
1382
|
+
});
|
|
1383
|
+
this.checkValidity();
|
|
1384
|
+
if (this.hasDisplayedError) {
|
|
1385
|
+
this.setErrorMessage();
|
|
1386
|
+
this.hasDisplayedError = false;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1347
1389
|
/**
|
|
1348
1390
|
* Public method to display errors
|
|
1349
1391
|
*
|
|
@@ -1351,7 +1393,8 @@ const MgInputCheckbox = class {
|
|
|
1351
1393
|
*/
|
|
1352
1394
|
async displayError() {
|
|
1353
1395
|
this.checkValidity();
|
|
1354
|
-
this.
|
|
1396
|
+
this.setErrorMessage();
|
|
1397
|
+
this.hasDisplayedError = this.invalid;
|
|
1355
1398
|
}
|
|
1356
1399
|
/*************
|
|
1357
1400
|
* Lifecycle *
|
|
@@ -1379,15 +1422,21 @@ const MgInputCheckbox = class {
|
|
|
1379
1422
|
* @returns {HTMLElement} HTML Element
|
|
1380
1423
|
*/
|
|
1381
1424
|
render() {
|
|
1382
|
-
return (index.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
|
|
1425
|
+
return (index.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 }, index.h("ul", { class: { 'mg-input__input-group-container': true, 'mg-input__input-group-container--vertical': this.inputVerticalList } }, this.checkboxItems
|
|
1383
1426
|
.filter(item => {
|
|
1384
1427
|
return !this.readonly || item.value;
|
|
1385
1428
|
})
|
|
1386
|
-
.map(input => (index.h("li", { class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } }, index.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 =>
|
|
1429
|
+
.map((input, index$1) => (index.h("li", { class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } }, index.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 => {
|
|
1430
|
+
if (el !== null)
|
|
1431
|
+
this.inputs[index$1] = el;
|
|
1432
|
+
} }), index.h("label", { htmlFor: input.id }, input.title)))))));
|
|
1387
1433
|
}
|
|
1388
1434
|
get element() { return index.getElement(this); }
|
|
1389
1435
|
static get watchers() { return {
|
|
1390
|
-
"value": ["validateValue"]
|
|
1436
|
+
"value": ["validateValue"],
|
|
1437
|
+
"required": ["handleValidityChange"],
|
|
1438
|
+
"readonly": ["handleValidityChange"],
|
|
1439
|
+
"disabled": ["handleValidityChange"]
|
|
1391
1440
|
}; }
|
|
1392
1441
|
};
|
|
1393
1442
|
MgInputCheckbox.style = mgInputCheckboxCss;
|
|
@@ -1446,8 +1495,8 @@ const MgInputDate = class {
|
|
|
1446
1495
|
index.registerInstance(this, hostRef);
|
|
1447
1496
|
this.valueChange = index.createEvent(this, "value-change", 7);
|
|
1448
1497
|
this.inputValid = index.createEvent(this, "input-valid", 7);
|
|
1449
|
-
//
|
|
1450
|
-
this.
|
|
1498
|
+
// hasDisplayedError (triggered by blur event)
|
|
1499
|
+
this.hasDisplayedError = false;
|
|
1451
1500
|
/**
|
|
1452
1501
|
* Input name
|
|
1453
1502
|
* If not set the value equals the identifier
|
|
@@ -1478,8 +1527,8 @@ const MgInputDate = class {
|
|
|
1478
1527
|
*/
|
|
1479
1528
|
this.handleInput = () => {
|
|
1480
1529
|
this.checkValidity();
|
|
1481
|
-
if (this.
|
|
1482
|
-
this.
|
|
1530
|
+
if (this.hasDisplayedError) {
|
|
1531
|
+
this.setErrorMessage();
|
|
1483
1532
|
}
|
|
1484
1533
|
this.value = this.input.value;
|
|
1485
1534
|
};
|
|
@@ -1493,14 +1542,11 @@ const MgInputDate = class {
|
|
|
1493
1542
|
* Check if input is valid
|
|
1494
1543
|
*/
|
|
1495
1544
|
this.checkValidity = () => {
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
//Send event
|
|
1502
|
-
this.inputValid.emit(validity);
|
|
1503
|
-
}
|
|
1545
|
+
var _a;
|
|
1546
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
|
|
1547
|
+
this.invalid = !this.valid;
|
|
1548
|
+
// We need to send valid event even if it is the same value
|
|
1549
|
+
this.inputValid.emit(this.valid);
|
|
1504
1550
|
};
|
|
1505
1551
|
/**
|
|
1506
1552
|
* get input error code
|
|
@@ -1529,48 +1575,50 @@ const MgInputDate = class {
|
|
|
1529
1575
|
return inputError;
|
|
1530
1576
|
};
|
|
1531
1577
|
/**
|
|
1532
|
-
*
|
|
1578
|
+
* Check input errors
|
|
1533
1579
|
*
|
|
1534
1580
|
* @returns {void}
|
|
1535
1581
|
*/
|
|
1536
1582
|
this.setErrorMessage = () => {
|
|
1537
1583
|
var _a;
|
|
1538
|
-
const inputError = this.getInputError();
|
|
1539
|
-
// required
|
|
1540
|
-
if (inputError === InputError$1.REQUIRED) {
|
|
1541
|
-
this.errorMessage = this.messages.errors[inputError];
|
|
1542
|
-
}
|
|
1543
|
-
// min, max & minMax
|
|
1544
|
-
else if ([InputError$1.MIN, InputError$1.MAX, InputError$1.MINMAX].includes(inputError)) {
|
|
1545
|
-
this.errorMessage = this.messages.errors.date[inputError].replace('{min}', localeDate(this.min, this.locale)).replace('{max}', localeDate(this.max, this.locale));
|
|
1546
|
-
}
|
|
1547
|
-
// wrong date format
|
|
1548
|
-
// element.validity.badInput is default error message
|
|
1549
|
-
else {
|
|
1550
|
-
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));
|
|
1551
|
-
}
|
|
1552
|
-
};
|
|
1553
|
-
/**
|
|
1554
|
-
* Check input errors
|
|
1555
|
-
*
|
|
1556
|
-
* @returns {void}
|
|
1557
|
-
*/
|
|
1558
|
-
this.checkError = () => {
|
|
1559
1584
|
// Set error message
|
|
1560
1585
|
this.errorMessage = undefined;
|
|
1561
1586
|
if (!this.valid) {
|
|
1562
|
-
this.
|
|
1587
|
+
const inputError = this.getInputError();
|
|
1588
|
+
// required
|
|
1589
|
+
if (inputError === InputError$1.REQUIRED) {
|
|
1590
|
+
this.errorMessage = this.messages.errors[inputError];
|
|
1591
|
+
}
|
|
1592
|
+
// min, max & minMax
|
|
1593
|
+
else if ([InputError$1.MIN, InputError$1.MAX, InputError$1.MINMAX].includes(inputError)) {
|
|
1594
|
+
this.errorMessage = this.messages.errors.date[inputError].replace('{min}', localeDate(this.min, this.locale)).replace('{max}', localeDate(this.max, this.locale));
|
|
1595
|
+
}
|
|
1596
|
+
// wrong date format
|
|
1597
|
+
// element.validity.badInput is default error message
|
|
1598
|
+
else {
|
|
1599
|
+
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));
|
|
1600
|
+
}
|
|
1563
1601
|
}
|
|
1564
1602
|
};
|
|
1565
1603
|
}
|
|
1566
1604
|
validateValue(newValue) {
|
|
1567
|
-
if (newValue !== undefined && (typeof newValue !== 'string' || !dateRegExp.test(newValue))) {
|
|
1605
|
+
if (newValue !== undefined && newValue !== null && (typeof newValue !== 'string' || !dateRegExp.test(newValue))) {
|
|
1568
1606
|
throw new Error("<mg-input-date> props 'value' doesn't match pattern: yyyy-mm-dd");
|
|
1569
1607
|
}
|
|
1570
1608
|
else {
|
|
1571
1609
|
this.valueChange.emit(this.value);
|
|
1572
1610
|
}
|
|
1573
1611
|
}
|
|
1612
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
1613
|
+
if (this.input !== undefined) {
|
|
1614
|
+
this.input[prop] = newValue;
|
|
1615
|
+
this.checkValidity();
|
|
1616
|
+
if (this.hasDisplayedError) {
|
|
1617
|
+
this.setErrorMessage();
|
|
1618
|
+
this.hasDisplayedError = false;
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1574
1622
|
validateMinMax(newValue) {
|
|
1575
1623
|
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)))) {
|
|
1576
1624
|
throw new Error("<mg-input-date> props 'min/max' doesn't match pattern: yyyy-mm-dd");
|
|
@@ -1583,8 +1631,8 @@ const MgInputDate = class {
|
|
|
1583
1631
|
*/
|
|
1584
1632
|
async displayError() {
|
|
1585
1633
|
this.checkValidity();
|
|
1586
|
-
this.
|
|
1587
|
-
this.
|
|
1634
|
+
this.setErrorMessage();
|
|
1635
|
+
this.hasDisplayedError = this.invalid;
|
|
1588
1636
|
}
|
|
1589
1637
|
/*************
|
|
1590
1638
|
* Lifecycle *
|
|
@@ -1616,11 +1664,17 @@ const MgInputDate = class {
|
|
|
1616
1664
|
* @returns {HTMLElement} HTML Element
|
|
1617
1665
|
*/
|
|
1618
1666
|
render() {
|
|
1619
|
-
return (index.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 }, index.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 =>
|
|
1667
|
+
return (index.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 }, index.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 => {
|
|
1668
|
+
if (el !== null)
|
|
1669
|
+
this.input = el;
|
|
1670
|
+
} })));
|
|
1620
1671
|
}
|
|
1621
1672
|
get element() { return index.getElement(this); }
|
|
1622
1673
|
static get watchers() { return {
|
|
1623
1674
|
"value": ["validateValue"],
|
|
1675
|
+
"required": ["handleValidityChange"],
|
|
1676
|
+
"readonly": ["handleValidityChange"],
|
|
1677
|
+
"disabled": ["handleValidityChange"],
|
|
1624
1678
|
"min": ["validateMinMax"],
|
|
1625
1679
|
"max": ["validateMinMax"]
|
|
1626
1680
|
}; }
|
|
@@ -1639,15 +1693,15 @@ var InputError;
|
|
|
1639
1693
|
InputError["REQUIRED"] = "required";
|
|
1640
1694
|
})(InputError || (InputError = {}));
|
|
1641
1695
|
|
|
1642
|
-
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)}";
|
|
1696
|
+
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)}";
|
|
1643
1697
|
|
|
1644
1698
|
const MgInputNumeric = class {
|
|
1645
1699
|
constructor(hostRef) {
|
|
1646
1700
|
index.registerInstance(this, hostRef);
|
|
1647
1701
|
this.valueChange = index.createEvent(this, "value-change", 7);
|
|
1648
1702
|
this.inputValid = index.createEvent(this, "input-valid", 7);
|
|
1649
|
-
//
|
|
1650
|
-
this.
|
|
1703
|
+
// hasDisplayedError (triggered by blur event)
|
|
1704
|
+
this.hasDisplayedError = false;
|
|
1651
1705
|
/**
|
|
1652
1706
|
* Input name
|
|
1653
1707
|
* If not set the value equals the identifier
|
|
@@ -1703,8 +1757,8 @@ const MgInputNumeric = class {
|
|
|
1703
1757
|
this.handleInput = () => {
|
|
1704
1758
|
// Check validity
|
|
1705
1759
|
this.checkValidity();
|
|
1706
|
-
if (this.
|
|
1707
|
-
this.
|
|
1760
|
+
if (this.hasDisplayedError) {
|
|
1761
|
+
this.setErrorMessage();
|
|
1708
1762
|
}
|
|
1709
1763
|
this.value = this.input.value;
|
|
1710
1764
|
};
|
|
@@ -1732,40 +1786,27 @@ const MgInputNumeric = class {
|
|
|
1732
1786
|
* @returns {void}
|
|
1733
1787
|
*/
|
|
1734
1788
|
this.checkValidity = () => {
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
this.invalid = !validity;
|
|
1740
|
-
//Send event
|
|
1741
|
-
this.inputValid.emit(validity);
|
|
1742
|
-
}
|
|
1789
|
+
this.valid = this.readonly || this.disabled || this.getInputError() === null;
|
|
1790
|
+
this.invalid = !this.valid;
|
|
1791
|
+
// We need to send valid event even if it is the same value
|
|
1792
|
+
this.inputValid.emit(this.valid);
|
|
1743
1793
|
};
|
|
1744
1794
|
/**
|
|
1745
|
-
* Set error message
|
|
1795
|
+
* Set input error message
|
|
1746
1796
|
*
|
|
1747
1797
|
* @returns {void}
|
|
1748
1798
|
*/
|
|
1749
1799
|
this.setErrorMessage = () => {
|
|
1750
|
-
const inputError = this.getInputError();
|
|
1751
|
-
if (inputError === InputError.REQUIRED) {
|
|
1752
|
-
this.errorMessage = this.messages.errors[inputError];
|
|
1753
|
-
}
|
|
1754
|
-
else {
|
|
1755
|
-
this.errorMessage = this.messages.errors.numeric[inputError].replace('{min}', `${this.formatValue(this.min)}`).replace('{max}', `${this.formatValue(this.max)}`);
|
|
1756
|
-
}
|
|
1757
|
-
};
|
|
1758
|
-
/**
|
|
1759
|
-
* Check input errors
|
|
1760
|
-
*
|
|
1761
|
-
* @returns {void}
|
|
1762
|
-
*/
|
|
1763
|
-
this.checkError = () => {
|
|
1764
1800
|
// Set error message
|
|
1765
1801
|
this.errorMessage = undefined;
|
|
1766
|
-
// Update class
|
|
1767
1802
|
if (!this.valid) {
|
|
1768
|
-
this.
|
|
1803
|
+
const inputError = this.getInputError();
|
|
1804
|
+
if (inputError === InputError.REQUIRED) {
|
|
1805
|
+
this.errorMessage = this.messages.errors[inputError];
|
|
1806
|
+
}
|
|
1807
|
+
else {
|
|
1808
|
+
this.errorMessage = this.messages.errors.numeric[inputError].replace('{min}', `${this.formatValue(this.min)}`).replace('{max}', `${this.formatValue(this.max)}`);
|
|
1809
|
+
}
|
|
1769
1810
|
}
|
|
1770
1811
|
};
|
|
1771
1812
|
/**
|
|
@@ -1775,7 +1816,7 @@ const MgInputNumeric = class {
|
|
|
1775
1816
|
*/
|
|
1776
1817
|
this.getInputError = () => {
|
|
1777
1818
|
let inputError = null;
|
|
1778
|
-
if (this.input === undefined)
|
|
1819
|
+
if (this.input === undefined || this.input === null)
|
|
1779
1820
|
return inputError;
|
|
1780
1821
|
// required
|
|
1781
1822
|
if (!this.input.checkValidity() && this.input.validity.valueMissing) {
|
|
@@ -1842,6 +1883,16 @@ const MgInputNumeric = class {
|
|
|
1842
1883
|
this.readonlyValue = this.numericValue !== null ? this.formatValue(this.numericValue) : '';
|
|
1843
1884
|
}
|
|
1844
1885
|
}
|
|
1886
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
1887
|
+
if (this.input !== undefined) {
|
|
1888
|
+
this.input[prop] = newValue;
|
|
1889
|
+
this.checkValidity();
|
|
1890
|
+
if (this.hasDisplayedError) {
|
|
1891
|
+
this.setErrorMessage();
|
|
1892
|
+
this.hasDisplayedError = false;
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1845
1896
|
validateType(newValue) {
|
|
1846
1897
|
if (!types.includes(newValue)) {
|
|
1847
1898
|
throw new Error(`<mg-input-numeric> prop "type" must be one of : ${types.join(', ')}`);
|
|
@@ -1864,8 +1915,8 @@ const MgInputNumeric = class {
|
|
|
1864
1915
|
*/
|
|
1865
1916
|
async displayError() {
|
|
1866
1917
|
this.checkValidity();
|
|
1867
|
-
this.
|
|
1868
|
-
this.
|
|
1918
|
+
this.setErrorMessage();
|
|
1919
|
+
this.hasDisplayedError = this.invalid;
|
|
1869
1920
|
}
|
|
1870
1921
|
/**
|
|
1871
1922
|
* Displayed value in input
|
|
@@ -1908,11 +1959,17 @@ const MgInputNumeric = class {
|
|
|
1908
1959
|
* @returns {HTMLElement} HTML Element
|
|
1909
1960
|
*/
|
|
1910
1961
|
render() {
|
|
1911
|
-
return (index.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 }, index.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 =>
|
|
1962
|
+
return (index.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 }, index.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 => {
|
|
1963
|
+
if (el !== null)
|
|
1964
|
+
this.input = el;
|
|
1965
|
+
} }), index.h("slot", { name: "append-input" })));
|
|
1912
1966
|
}
|
|
1913
1967
|
get element() { return index.getElement(this); }
|
|
1914
1968
|
static get watchers() { return {
|
|
1915
1969
|
"value": ["validateValue"],
|
|
1970
|
+
"required": ["handleValidityChange"],
|
|
1971
|
+
"readonly": ["handleValidityChange"],
|
|
1972
|
+
"disabled": ["handleValidityChange"],
|
|
1916
1973
|
"type": ["validateType"],
|
|
1917
1974
|
"integerLength": ["validateIntegerLength"],
|
|
1918
1975
|
"decimalLength": ["validateDecimalLength"]
|
|
@@ -1920,15 +1977,15 @@ const MgInputNumeric = class {
|
|
|
1920
1977
|
};
|
|
1921
1978
|
MgInputNumeric.style = mgInputNumericCss;
|
|
1922
1979
|
|
|
1923
|
-
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}";
|
|
1980
|
+
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}";
|
|
1924
1981
|
|
|
1925
1982
|
const MgInputPassword = class {
|
|
1926
1983
|
constructor(hostRef) {
|
|
1927
1984
|
index.registerInstance(this, hostRef);
|
|
1928
1985
|
this.valueChange = index.createEvent(this, "value-change", 7);
|
|
1929
1986
|
this.inputValid = index.createEvent(this, "input-valid", 7);
|
|
1930
|
-
//
|
|
1931
|
-
this.
|
|
1987
|
+
// hasDisplayedError (triggered by blur event)
|
|
1988
|
+
this.hasDisplayedError = false;
|
|
1932
1989
|
/**
|
|
1933
1990
|
* Input name
|
|
1934
1991
|
* If not set the value equals the identifier
|
|
@@ -1963,8 +2020,8 @@ const MgInputPassword = class {
|
|
|
1963
2020
|
*/
|
|
1964
2021
|
this.handleInput = () => {
|
|
1965
2022
|
this.checkValidity();
|
|
1966
|
-
if (this.
|
|
1967
|
-
this.
|
|
2023
|
+
if (this.hasDisplayedError) {
|
|
2024
|
+
this.setErrorMessage();
|
|
1968
2025
|
}
|
|
1969
2026
|
this.value = this.input.value;
|
|
1970
2027
|
};
|
|
@@ -1978,19 +2035,16 @@ const MgInputPassword = class {
|
|
|
1978
2035
|
* Check if input is valid
|
|
1979
2036
|
*/
|
|
1980
2037
|
this.checkValidity = () => {
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
//Send event
|
|
1987
|
-
this.inputValid.emit(validity);
|
|
1988
|
-
}
|
|
2038
|
+
var _a;
|
|
2039
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
|
|
2040
|
+
this.invalid = !this.valid;
|
|
2041
|
+
// We need to send valid event even if it is the same value
|
|
2042
|
+
this.inputValid.emit(this.valid);
|
|
1989
2043
|
};
|
|
1990
2044
|
/**
|
|
1991
|
-
*
|
|
2045
|
+
* Set input error message
|
|
1992
2046
|
*/
|
|
1993
|
-
this.
|
|
2047
|
+
this.setErrorMessage = () => {
|
|
1994
2048
|
// Set error message
|
|
1995
2049
|
this.errorMessage = undefined;
|
|
1996
2050
|
// required
|
|
@@ -2002,6 +2056,16 @@ const MgInputPassword = class {
|
|
|
2002
2056
|
handleValue(newValue) {
|
|
2003
2057
|
this.valueChange.emit(newValue);
|
|
2004
2058
|
}
|
|
2059
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
2060
|
+
if (this.input !== undefined) {
|
|
2061
|
+
this.input[prop] = newValue;
|
|
2062
|
+
this.checkValidity();
|
|
2063
|
+
if (this.hasDisplayedError) {
|
|
2064
|
+
this.setErrorMessage();
|
|
2065
|
+
this.hasDisplayedError = false;
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2005
2069
|
/**
|
|
2006
2070
|
* Public method to display errors
|
|
2007
2071
|
*
|
|
@@ -2009,8 +2073,8 @@ const MgInputPassword = class {
|
|
|
2009
2073
|
*/
|
|
2010
2074
|
async displayError() {
|
|
2011
2075
|
this.checkValidity();
|
|
2012
|
-
this.
|
|
2013
|
-
this.
|
|
2076
|
+
this.setErrorMessage();
|
|
2077
|
+
this.hasDisplayedError = this.invalid;
|
|
2014
2078
|
}
|
|
2015
2079
|
/*************
|
|
2016
2080
|
* Lifecycle *
|
|
@@ -2036,11 +2100,17 @@ const MgInputPassword = class {
|
|
|
2036
2100
|
* @returns {HTMLElement} HTML Element
|
|
2037
2101
|
*/
|
|
2038
2102
|
render() {
|
|
2039
|
-
return (index.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 }, index.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 =>
|
|
2103
|
+
return (index.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 }, index.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 => {
|
|
2104
|
+
if (el !== null)
|
|
2105
|
+
this.input = el;
|
|
2106
|
+
} })));
|
|
2040
2107
|
}
|
|
2041
2108
|
get element() { return index.getElement(this); }
|
|
2042
2109
|
static get watchers() { return {
|
|
2043
|
-
"value": ["handleValue"]
|
|
2110
|
+
"value": ["handleValue"],
|
|
2111
|
+
"required": ["handleValidityChange"],
|
|
2112
|
+
"readonly": ["handleValidityChange"],
|
|
2113
|
+
"disabled": ["handleValidityChange"]
|
|
2044
2114
|
}; }
|
|
2045
2115
|
};
|
|
2046
2116
|
MgInputPassword.style = mgInputPasswordCss;
|
|
@@ -2064,6 +2134,8 @@ const MgInputRadio = class {
|
|
|
2064
2134
|
************/
|
|
2065
2135
|
// HTML selector
|
|
2066
2136
|
this.inputs = [];
|
|
2137
|
+
// hasDisplayedError (triggered by blur event)
|
|
2138
|
+
this.hasDisplayedError = false;
|
|
2067
2139
|
/**
|
|
2068
2140
|
* Input name
|
|
2069
2141
|
* If not set the value equals the identifier
|
|
@@ -2114,7 +2186,7 @@ const MgInputRadio = class {
|
|
|
2114
2186
|
*/
|
|
2115
2187
|
this.handleBlur = () => {
|
|
2116
2188
|
this.checkValidity();
|
|
2117
|
-
this.
|
|
2189
|
+
this.setErrorMessage();
|
|
2118
2190
|
};
|
|
2119
2191
|
/**
|
|
2120
2192
|
* Check if input is valid
|
|
@@ -2122,21 +2194,17 @@ const MgInputRadio = class {
|
|
|
2122
2194
|
* @returns {void}
|
|
2123
2195
|
*/
|
|
2124
2196
|
this.checkValidity = () => {
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
this.invalid = !validity;
|
|
2130
|
-
//Send event
|
|
2131
|
-
this.inputValid.emit(validity);
|
|
2132
|
-
}
|
|
2197
|
+
this.valid = this.readonly || this.disabled || this.getInvalidElement() === undefined;
|
|
2198
|
+
this.invalid = !this.valid;
|
|
2199
|
+
// We need to send valid event even if it is the same value
|
|
2200
|
+
this.inputValid.emit(this.valid);
|
|
2133
2201
|
};
|
|
2134
2202
|
/**
|
|
2135
|
-
*
|
|
2203
|
+
* Set input error message
|
|
2136
2204
|
*
|
|
2137
2205
|
* @returns {void}
|
|
2138
2206
|
*/
|
|
2139
|
-
this.
|
|
2207
|
+
this.setErrorMessage = () => {
|
|
2140
2208
|
const invalidElement = this.getInvalidElement();
|
|
2141
2209
|
// Set error message
|
|
2142
2210
|
this.errorMessage = undefined;
|
|
@@ -2149,7 +2217,7 @@ const MgInputRadio = class {
|
|
|
2149
2217
|
*
|
|
2150
2218
|
* @returns {HTMLInputElement} element
|
|
2151
2219
|
*/
|
|
2152
|
-
this.getInvalidElement = () => this.inputs.find((
|
|
2220
|
+
this.getInvalidElement = () => this.inputs.find((input) => !input.disabled && !input.readOnly && !input.checkValidity());
|
|
2153
2221
|
}
|
|
2154
2222
|
handleValue(newValue) {
|
|
2155
2223
|
this.valueChange.emit(newValue);
|
|
@@ -2171,6 +2239,16 @@ const MgInputRadio = class {
|
|
|
2171
2239
|
throw new Error('<mg-input-radio> prop "items" is required and all items must be the same type, string or RadioOption.');
|
|
2172
2240
|
}
|
|
2173
2241
|
}
|
|
2242
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
2243
|
+
this.inputs.forEach(input => {
|
|
2244
|
+
input[prop] = newValue;
|
|
2245
|
+
});
|
|
2246
|
+
this.checkValidity();
|
|
2247
|
+
if (this.hasDisplayedError) {
|
|
2248
|
+
this.setErrorMessage();
|
|
2249
|
+
this.hasDisplayedError = false;
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2174
2252
|
/**
|
|
2175
2253
|
* Public method to display errors
|
|
2176
2254
|
*
|
|
@@ -2178,7 +2256,8 @@ const MgInputRadio = class {
|
|
|
2178
2256
|
*/
|
|
2179
2257
|
async displayError() {
|
|
2180
2258
|
this.checkValidity();
|
|
2181
|
-
this.
|
|
2259
|
+
this.setErrorMessage();
|
|
2260
|
+
this.hasDisplayedError = this.invalid;
|
|
2182
2261
|
}
|
|
2183
2262
|
/*************
|
|
2184
2263
|
* Lifecycle *
|
|
@@ -2206,17 +2285,23 @@ const MgInputRadio = class {
|
|
|
2206
2285
|
* @returns {HTMLElement} HTML Element
|
|
2207
2286
|
*/
|
|
2208
2287
|
render() {
|
|
2209
|
-
return (index.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 }, index.h("ul", { class: { 'mg-input__input-group-container': true, 'mg-input__input-group-container--vertical': this.inputVerticalList } }, this.options.map((input, index$1) => (index.h("li", { class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } }, index.h("input", { type: "radio", id: this.identifier + '_' + index$1, name: this.identifier, value: index$1, checked: JSON.stringify(this.value) === JSON.stringify(this.options[index$1].value), disabled: this.disabled || input.disabled, required: this.required, onBlur: this.handleBlur, onInput: this.handleInput, ref: el =>
|
|
2288
|
+
return (index.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 }, index.h("ul", { class: { 'mg-input__input-group-container': true, 'mg-input__input-group-container--vertical': this.inputVerticalList } }, this.options.map((input, index$1) => (index.h("li", { class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } }, index.h("input", { type: "radio", id: this.identifier + '_' + index$1, name: this.identifier, value: index$1, checked: JSON.stringify(this.value) === JSON.stringify(this.options[index$1].value), disabled: this.disabled || input.disabled, required: this.required, onBlur: this.handleBlur, onInput: this.handleInput, ref: el => {
|
|
2289
|
+
if (el !== null)
|
|
2290
|
+
this.inputs[index$1] = el;
|
|
2291
|
+
} }), index.h("label", { htmlFor: this.identifier + '_' + index$1 }, input.title)))))));
|
|
2210
2292
|
}
|
|
2211
2293
|
get element() { return index.getElement(this); }
|
|
2212
2294
|
static get watchers() { return {
|
|
2213
2295
|
"value": ["handleValue"],
|
|
2214
|
-
"items": ["validateItems"]
|
|
2296
|
+
"items": ["validateItems"],
|
|
2297
|
+
"required": ["handleValidityChange"],
|
|
2298
|
+
"readonly": ["handleValidityChange"],
|
|
2299
|
+
"disabled": ["handleValidityChange"]
|
|
2215
2300
|
}; }
|
|
2216
2301
|
};
|
|
2217
2302
|
MgInputRadio.style = mgInputRadioCss;
|
|
2218
2303
|
|
|
2219
|
-
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}";
|
|
2304
|
+
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}";
|
|
2220
2305
|
|
|
2221
2306
|
/**
|
|
2222
2307
|
* Check if item is a well configured option
|
|
@@ -2259,8 +2344,8 @@ const MgInputSelect = class {
|
|
|
2259
2344
|
index.registerInstance(this, hostRef);
|
|
2260
2345
|
this.valueChange = index.createEvent(this, "value-change", 7);
|
|
2261
2346
|
this.inputValid = index.createEvent(this, "input-valid", 7);
|
|
2262
|
-
//
|
|
2263
|
-
this.
|
|
2347
|
+
// hasDisplayedError (triggered by blur event)
|
|
2348
|
+
this.hasDisplayedError = false;
|
|
2264
2349
|
/**
|
|
2265
2350
|
* Input name
|
|
2266
2351
|
* If not set the value equals the identifier
|
|
@@ -2299,8 +2384,8 @@ const MgInputSelect = class {
|
|
|
2299
2384
|
*/
|
|
2300
2385
|
this.handleInput = () => {
|
|
2301
2386
|
this.checkValidity();
|
|
2302
|
-
if (this.
|
|
2303
|
-
this.
|
|
2387
|
+
if (this.hasDisplayedError) {
|
|
2388
|
+
this.setErrorMessage();
|
|
2304
2389
|
}
|
|
2305
2390
|
if (this.input.value !== '') {
|
|
2306
2391
|
this.value = allItemsAreString(this.items) ? this.input.value : this.items.find(item => item.title === this.input.value).value;
|
|
@@ -2319,19 +2404,16 @@ const MgInputSelect = class {
|
|
|
2319
2404
|
* Check if input is valid
|
|
2320
2405
|
*/
|
|
2321
2406
|
this.checkValidity = () => {
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
//Send event
|
|
2328
|
-
this.inputValid.emit(validity);
|
|
2329
|
-
}
|
|
2407
|
+
var _a;
|
|
2408
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
|
|
2409
|
+
this.invalid = !this.valid;
|
|
2410
|
+
// We need to send valid event even if it is the same value
|
|
2411
|
+
this.inputValid.emit(this.valid);
|
|
2330
2412
|
};
|
|
2331
2413
|
/**
|
|
2332
|
-
*
|
|
2414
|
+
* Set input error message
|
|
2333
2415
|
*/
|
|
2334
|
-
this.
|
|
2416
|
+
this.setErrorMessage = () => {
|
|
2335
2417
|
// Set error message
|
|
2336
2418
|
this.errorMessage = undefined;
|
|
2337
2419
|
if (!this.valid && this.input.validity.valueMissing) {
|
|
@@ -2370,6 +2452,16 @@ const MgInputSelect = class {
|
|
|
2370
2452
|
throw new Error('<mg-input-select> prop "items" is required and all items must be the same type, string or Option.');
|
|
2371
2453
|
}
|
|
2372
2454
|
}
|
|
2455
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
2456
|
+
if (this.input !== undefined) {
|
|
2457
|
+
this.input[prop] = newValue;
|
|
2458
|
+
this.checkValidity();
|
|
2459
|
+
if (this.hasDisplayedError) {
|
|
2460
|
+
this.setErrorMessage();
|
|
2461
|
+
this.hasDisplayedError = false;
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2373
2465
|
/**
|
|
2374
2466
|
* Public method to display errors
|
|
2375
2467
|
*
|
|
@@ -2377,8 +2469,8 @@ const MgInputSelect = class {
|
|
|
2377
2469
|
*/
|
|
2378
2470
|
async displayError() {
|
|
2379
2471
|
this.checkValidity();
|
|
2380
|
-
this.
|
|
2381
|
-
this.
|
|
2472
|
+
this.setErrorMessage();
|
|
2473
|
+
this.hasDisplayedError = this.invalid;
|
|
2382
2474
|
}
|
|
2383
2475
|
/*************
|
|
2384
2476
|
* Lifecycle *
|
|
@@ -2410,18 +2502,24 @@ const MgInputSelect = class {
|
|
|
2410
2502
|
* @returns {HTMLElement} HTML Element
|
|
2411
2503
|
*/
|
|
2412
2504
|
render() {
|
|
2413
|
-
return (index.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 }, index.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 =>
|
|
2505
|
+
return (index.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 }, index.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 => {
|
|
2506
|
+
if (el !== null)
|
|
2507
|
+
this.input = el;
|
|
2508
|
+
} }, (!this.placeholderHide || !this.valueExist) && ( // In case passed value does not match any option we display the placeholder
|
|
2414
2509
|
index.h("option", { value: "", disabled: this.placeholderDisabled && this.valueExist }, this.placeholder)), this.options.map(option => option.group !== undefined ? (index.h("optgroup", { label: option.group }, option.options.map(optgroup => (index.h("option", { value: optgroup.title, selected: JSON.stringify(this.value) === JSON.stringify(optgroup.value), disabled: optgroup.disabled }, optgroup.title))))) : (index.h("option", { value: option.title, selected: JSON.stringify(this.value) === JSON.stringify(option.value), disabled: option.disabled }, option.title))))));
|
|
2415
2510
|
}
|
|
2416
2511
|
get element() { return index.getElement(this); }
|
|
2417
2512
|
static get watchers() { return {
|
|
2418
2513
|
"value": ["handleValue"],
|
|
2419
|
-
"items": ["validateItems"]
|
|
2514
|
+
"items": ["validateItems"],
|
|
2515
|
+
"required": ["handleValidityChange"],
|
|
2516
|
+
"readonly": ["handleValidityChange"],
|
|
2517
|
+
"disabled": ["handleValidityChange"]
|
|
2420
2518
|
}; }
|
|
2421
2519
|
};
|
|
2422
2520
|
MgInputSelect.style = mgInputSelectCss;
|
|
2423
2521
|
|
|
2424
|
-
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}";
|
|
2522
|
+
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}";
|
|
2425
2523
|
|
|
2426
2524
|
const MgInputText = class {
|
|
2427
2525
|
constructor(hostRef) {
|
|
@@ -2431,12 +2529,12 @@ const MgInputText = class {
|
|
|
2431
2529
|
/************
|
|
2432
2530
|
* Internal *
|
|
2433
2531
|
************/
|
|
2434
|
-
//
|
|
2532
|
+
// Classes
|
|
2435
2533
|
this.classFocus = 'is-focused';
|
|
2436
2534
|
this.classIsInputGroupAppend = 'mg-input--is-input-group-append';
|
|
2437
2535
|
this.classHasIcon = 'mg-input--has-icon';
|
|
2438
|
-
//
|
|
2439
|
-
this.
|
|
2536
|
+
// hasDisplayedError (triggered by blur event)
|
|
2537
|
+
this.hasDisplayedError = false;
|
|
2440
2538
|
/**
|
|
2441
2539
|
* Input name
|
|
2442
2540
|
* If not set the value equals the identifier
|
|
@@ -2485,8 +2583,8 @@ const MgInputText = class {
|
|
|
2485
2583
|
*/
|
|
2486
2584
|
this.handleInput = () => {
|
|
2487
2585
|
this.checkValidity();
|
|
2488
|
-
if (this.
|
|
2489
|
-
this.
|
|
2586
|
+
if (this.hasDisplayedError) {
|
|
2587
|
+
this.setErrorMessage();
|
|
2490
2588
|
}
|
|
2491
2589
|
this.value = this.input.value;
|
|
2492
2590
|
};
|
|
@@ -2517,21 +2615,18 @@ const MgInputText = class {
|
|
|
2517
2615
|
* @returns {void}
|
|
2518
2616
|
*/
|
|
2519
2617
|
this.checkValidity = () => {
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
//Send event
|
|
2526
|
-
this.inputValid.emit(validity);
|
|
2527
|
-
}
|
|
2618
|
+
var _a;
|
|
2619
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
|
|
2620
|
+
this.invalid = !this.valid;
|
|
2621
|
+
// We need to send valid event even if it is the same value
|
|
2622
|
+
this.inputValid.emit(this.valid);
|
|
2528
2623
|
};
|
|
2529
2624
|
/**
|
|
2530
|
-
*
|
|
2625
|
+
* Set input error message
|
|
2531
2626
|
*
|
|
2532
2627
|
* @returns {void}
|
|
2533
2628
|
*/
|
|
2534
|
-
this.
|
|
2629
|
+
this.setErrorMessage = () => {
|
|
2535
2630
|
// Set error message
|
|
2536
2631
|
this.errorMessage = undefined;
|
|
2537
2632
|
// Does not match pattern
|
|
@@ -2544,7 +2639,7 @@ const MgInputText = class {
|
|
|
2544
2639
|
}
|
|
2545
2640
|
};
|
|
2546
2641
|
/**
|
|
2547
|
-
* Validate
|
|
2642
|
+
* Validate pattern configuration
|
|
2548
2643
|
*
|
|
2549
2644
|
* @returns {void}
|
|
2550
2645
|
*/
|
|
@@ -2583,6 +2678,16 @@ const MgInputText = class {
|
|
|
2583
2678
|
this.classList.delete(this.classHasIcon);
|
|
2584
2679
|
}
|
|
2585
2680
|
}
|
|
2681
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
2682
|
+
if (this.input !== undefined) {
|
|
2683
|
+
this.input[prop] = newValue;
|
|
2684
|
+
this.checkValidity();
|
|
2685
|
+
if (this.hasDisplayedError) {
|
|
2686
|
+
this.setErrorMessage();
|
|
2687
|
+
this.hasDisplayedError = false;
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2586
2691
|
/**
|
|
2587
2692
|
* Public method to play input focus
|
|
2588
2693
|
*
|
|
@@ -2598,8 +2703,8 @@ const MgInputText = class {
|
|
|
2598
2703
|
*/
|
|
2599
2704
|
async displayError() {
|
|
2600
2705
|
this.checkValidity();
|
|
2601
|
-
this.
|
|
2602
|
-
this.
|
|
2706
|
+
this.setErrorMessage();
|
|
2707
|
+
this.hasDisplayedError = this.invalid;
|
|
2603
2708
|
}
|
|
2604
2709
|
/*************
|
|
2605
2710
|
* Lifecycle *
|
|
@@ -2634,17 +2739,23 @@ const MgInputText = class {
|
|
|
2634
2739
|
'--mg-character-left-message-length': (this.displayCharacterLeft
|
|
2635
2740
|
? (this.maxlength - (this.value || '').length).toString().length + this.maxlength.toString().length + 1
|
|
2636
2741
|
: 0).toString(),
|
|
2637
|
-
} }, this.icon !== undefined && index.h("mg-icon", { icon: this.icon }), index.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 =>
|
|
2742
|
+
} }, this.icon !== undefined && index.h("mg-icon", { icon: this.icon }), index.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 => {
|
|
2743
|
+
if (el !== null)
|
|
2744
|
+
this.input = el;
|
|
2745
|
+
} }), this.displayCharacterLeft && this.maxlength > 0 && (index.h("mg-character-left", { identifier: this.characterLeftId, characters: this.value, maxlength: this.maxlength }))), index.h("slot", { name: "append-input" })));
|
|
2638
2746
|
}
|
|
2639
2747
|
get element() { return index.getElement(this); }
|
|
2640
2748
|
static get watchers() { return {
|
|
2641
2749
|
"value": ["handleValue"],
|
|
2642
|
-
"icon": ["validateIcon"]
|
|
2750
|
+
"icon": ["validateIcon"],
|
|
2751
|
+
"required": ["handleValidityChange"],
|
|
2752
|
+
"readonly": ["handleValidityChange"],
|
|
2753
|
+
"disabled": ["handleValidityChange"]
|
|
2643
2754
|
}; }
|
|
2644
2755
|
};
|
|
2645
2756
|
MgInputText.style = mgInputTextCss;
|
|
2646
2757
|
|
|
2647
|
-
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}}";
|
|
2758
|
+
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}}";
|
|
2648
2759
|
|
|
2649
2760
|
const MgInputTextarea = class {
|
|
2650
2761
|
constructor(hostRef) {
|
|
@@ -2654,11 +2765,11 @@ const MgInputTextarea = class {
|
|
|
2654
2765
|
/************
|
|
2655
2766
|
* Internal *
|
|
2656
2767
|
************/
|
|
2657
|
-
//
|
|
2768
|
+
// Classes
|
|
2658
2769
|
this.classFocus = 'is-focused';
|
|
2659
2770
|
this.classHasDisplayCharacterLeft = 'mg-input--has-display-character-left';
|
|
2660
|
-
//
|
|
2661
|
-
this.
|
|
2771
|
+
// hasDisplayedError (triggered by blur event)
|
|
2772
|
+
this.hasDisplayedError = false;
|
|
2662
2773
|
/**
|
|
2663
2774
|
* Input name
|
|
2664
2775
|
* If not set the value equals the identifier
|
|
@@ -2708,9 +2819,9 @@ const MgInputTextarea = class {
|
|
|
2708
2819
|
* Handle input event
|
|
2709
2820
|
*/
|
|
2710
2821
|
this.handleInput = () => {
|
|
2711
|
-
if (this.
|
|
2822
|
+
if (this.hasDisplayedError) {
|
|
2712
2823
|
this.checkValidity();
|
|
2713
|
-
this.
|
|
2824
|
+
this.setErrorMessage();
|
|
2714
2825
|
}
|
|
2715
2826
|
this.value = this.input.value;
|
|
2716
2827
|
};
|
|
@@ -2742,19 +2853,16 @@ const MgInputTextarea = class {
|
|
|
2742
2853
|
* Check if input is valid
|
|
2743
2854
|
*/
|
|
2744
2855
|
this.checkValidity = () => {
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
//Send event
|
|
2751
|
-
this.inputValid.emit(validity);
|
|
2752
|
-
}
|
|
2856
|
+
var _a;
|
|
2857
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined && this.input.checkValidity() && this.getPatternValidity());
|
|
2858
|
+
this.invalid = !this.valid;
|
|
2859
|
+
// We need to send valid event even if it is the same value
|
|
2860
|
+
this.inputValid.emit(this.valid);
|
|
2753
2861
|
};
|
|
2754
2862
|
/**
|
|
2755
|
-
*
|
|
2863
|
+
* Set input error message
|
|
2756
2864
|
*/
|
|
2757
|
-
this.
|
|
2865
|
+
this.setErrorMessage = () => {
|
|
2758
2866
|
// Set error message
|
|
2759
2867
|
this.errorMessage = undefined;
|
|
2760
2868
|
// Does not match pattern
|
|
@@ -2782,6 +2890,16 @@ const MgInputTextarea = class {
|
|
|
2782
2890
|
this.checkValidity();
|
|
2783
2891
|
this.valueChange.emit(newValue);
|
|
2784
2892
|
}
|
|
2893
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
2894
|
+
if (this.input !== undefined) {
|
|
2895
|
+
this.input[prop] = newValue;
|
|
2896
|
+
this.checkValidity();
|
|
2897
|
+
if (this.hasDisplayedError) {
|
|
2898
|
+
this.setErrorMessage();
|
|
2899
|
+
this.hasDisplayedError = false;
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2785
2903
|
validateDisplayCharacterLeft(newValue) {
|
|
2786
2904
|
if (newValue) {
|
|
2787
2905
|
this.classList.add(this.classHasDisplayCharacterLeft);
|
|
@@ -2797,8 +2915,8 @@ const MgInputTextarea = class {
|
|
|
2797
2915
|
*/
|
|
2798
2916
|
async displayError() {
|
|
2799
2917
|
this.checkValidity();
|
|
2800
|
-
this.
|
|
2801
|
-
this.
|
|
2918
|
+
this.setErrorMessage();
|
|
2919
|
+
this.hasDisplayedError = this.invalid;
|
|
2802
2920
|
}
|
|
2803
2921
|
/*************
|
|
2804
2922
|
* Lifecycle *
|
|
@@ -2833,11 +2951,17 @@ const MgInputTextarea = class {
|
|
|
2833
2951
|
'mg-input__box--resizable': this.resizable === 'both',
|
|
2834
2952
|
'mg-input__box--resizable-horizontal': this.resizable === 'horizontal',
|
|
2835
2953
|
'mg-input__box--resizable-vertical': this.resizable === 'vertical',
|
|
2836
|
-
}, 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 =>
|
|
2954
|
+
}, 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 => {
|
|
2955
|
+
if (el !== null)
|
|
2956
|
+
this.input = el;
|
|
2957
|
+
} }), this.displayCharacterLeft && this.maxlength > 0 && (index.h("mg-character-left", { identifier: this.characterLeftId, characters: this.value, maxlength: this.maxlength })))));
|
|
2837
2958
|
}
|
|
2838
2959
|
get element() { return index.getElement(this); }
|
|
2839
2960
|
static get watchers() { return {
|
|
2840
2961
|
"value": ["handleValue"],
|
|
2962
|
+
"required": ["handleValidityChange"],
|
|
2963
|
+
"readonly": ["handleValidityChange"],
|
|
2964
|
+
"disabled": ["handleValidityChange"],
|
|
2841
2965
|
"displayCharacterLeft": ["validateDisplayCharacterLeft"]
|
|
2842
2966
|
}; }
|
|
2843
2967
|
};
|
|
@@ -2910,7 +3034,7 @@ const MgInputToggle = class {
|
|
|
2910
3034
|
/************
|
|
2911
3035
|
* Internal *
|
|
2912
3036
|
************/
|
|
2913
|
-
//
|
|
3037
|
+
// Classes
|
|
2914
3038
|
this.classReadonly = 'mg-input--toggle-readonly';
|
|
2915
3039
|
this.classDisabled = 'mg-input--toggle-disabled';
|
|
2916
3040
|
this.classIsActive = 'mg-input--toggle-is-active';
|
|
@@ -3093,6 +3217,368 @@ const MgInputToggle = class {
|
|
|
3093
3217
|
};
|
|
3094
3218
|
MgInputToggle.style = mgInputToggleCss;
|
|
3095
3219
|
|
|
3220
|
+
/**
|
|
3221
|
+
* Menu direction type
|
|
3222
|
+
*/
|
|
3223
|
+
var Direction;
|
|
3224
|
+
(function (Direction) {
|
|
3225
|
+
Direction["VERTICAL"] = "vertical";
|
|
3226
|
+
Direction["HORIZONTAL"] = "horizontal";
|
|
3227
|
+
})(Direction || (Direction = {}));
|
|
3228
|
+
|
|
3229
|
+
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}";
|
|
3230
|
+
|
|
3231
|
+
const MgMenu = class {
|
|
3232
|
+
constructor(hostRef) {
|
|
3233
|
+
index.registerInstance(this, hostRef);
|
|
3234
|
+
/************
|
|
3235
|
+
* Internal *
|
|
3236
|
+
************/
|
|
3237
|
+
this.name = 'mg-menu';
|
|
3238
|
+
this.focusedMenuItem = 0;
|
|
3239
|
+
/**
|
|
3240
|
+
* Component display direction. Default: "horizontal"
|
|
3241
|
+
*/
|
|
3242
|
+
this.direction = Direction.HORIZONTAL;
|
|
3243
|
+
/**
|
|
3244
|
+
* Component classes
|
|
3245
|
+
*/
|
|
3246
|
+
this.classList = new ClassList([this.name]);
|
|
3247
|
+
/**
|
|
3248
|
+
* Close matching menu-item
|
|
3249
|
+
*
|
|
3250
|
+
* @param {HTMLMgMenuItemElement} item menu-item to close
|
|
3251
|
+
* @param {boolean} condition addionnal condition
|
|
3252
|
+
* @returns {void}
|
|
3253
|
+
*/
|
|
3254
|
+
this.closeMenuItem = (item, condition) => {
|
|
3255
|
+
if (!this.isChildMenu && condition) {
|
|
3256
|
+
item.expanded = false;
|
|
3257
|
+
}
|
|
3258
|
+
};
|
|
3259
|
+
/**
|
|
3260
|
+
* Store menu-items on component init and add listeners
|
|
3261
|
+
*/
|
|
3262
|
+
this.initMenuItems = () => {
|
|
3263
|
+
// store all menu-items
|
|
3264
|
+
this.menuItems = Array.from(this.element.children).filter(child => child.nodeName === 'MG-MENU-ITEM');
|
|
3265
|
+
// add listeners on menu item and edit index
|
|
3266
|
+
this.menuItems.forEach((item, menuItemIndex) => {
|
|
3267
|
+
['click', 'focus'].forEach(trigger => {
|
|
3268
|
+
(item.shadowRoot.querySelector('button') || item.shadowRoot.querySelector('a')).addEventListener(trigger, (event) => {
|
|
3269
|
+
event.preventDefault();
|
|
3270
|
+
event.stopPropagation();
|
|
3271
|
+
this.focusedMenuItem = menuItemIndex;
|
|
3272
|
+
// reset expanded on previous active menu item
|
|
3273
|
+
this.menuItems.forEach((item, index) => {
|
|
3274
|
+
this.closeMenuItem(item, index !== this.focusedMenuItem);
|
|
3275
|
+
});
|
|
3276
|
+
});
|
|
3277
|
+
});
|
|
3278
|
+
});
|
|
3279
|
+
};
|
|
3280
|
+
}
|
|
3281
|
+
validateLabel(newValue) {
|
|
3282
|
+
if (newValue === undefined) {
|
|
3283
|
+
throw new Error(`<${this.name}> prop "label" is required.`);
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
validateDirection(newValue) {
|
|
3287
|
+
if (newValue === Direction.VERTICAL) {
|
|
3288
|
+
this.classList.add(`${this.name}--${Direction.VERTICAL}`);
|
|
3289
|
+
}
|
|
3290
|
+
else if (newValue === Direction.HORIZONTAL) {
|
|
3291
|
+
this.classList.add(`${this.name}--${Direction.HORIZONTAL}`);
|
|
3292
|
+
}
|
|
3293
|
+
else {
|
|
3294
|
+
throw new Error(`<${this.name}> prop "direction" must be one of : ${Direction.HORIZONTAL}, ${Direction.VERTICAL}.`);
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
/*************
|
|
3298
|
+
* Lifecycle *
|
|
3299
|
+
*************/
|
|
3300
|
+
/**
|
|
3301
|
+
* Validate props
|
|
3302
|
+
*
|
|
3303
|
+
* @returns {void}
|
|
3304
|
+
*/
|
|
3305
|
+
componentWillLoad() {
|
|
3306
|
+
this.validateDirection(this.direction);
|
|
3307
|
+
this.validateLabel(this.label);
|
|
3308
|
+
}
|
|
3309
|
+
/**
|
|
3310
|
+
* Check if component slots configuration
|
|
3311
|
+
*
|
|
3312
|
+
* @returns {ReturnType<typeof setTimeout>} timeout
|
|
3313
|
+
*/
|
|
3314
|
+
componentDidLoad() {
|
|
3315
|
+
this.initMenuItems();
|
|
3316
|
+
// update props and states after componentDidLoad hook
|
|
3317
|
+
// return a promise to process action only in the FIRST render().
|
|
3318
|
+
// https://stenciljs.com/docs/component-lifecycle#componentwillload
|
|
3319
|
+
return setTimeout(() => {
|
|
3320
|
+
this.isChildMenu = this.element.closest('mg-menu-item') !== null;
|
|
3321
|
+
// click outside management for child vertical menu
|
|
3322
|
+
if (!this.isChildMenu && this.direction === Direction.HORIZONTAL) {
|
|
3323
|
+
document.addEventListener('click', (event) => {
|
|
3324
|
+
if (event.target.closest('mg-menu') === null) {
|
|
3325
|
+
this.menuItems.forEach(item => {
|
|
3326
|
+
this.closeMenuItem(item, this.direction === Direction.HORIZONTAL);
|
|
3327
|
+
});
|
|
3328
|
+
}
|
|
3329
|
+
});
|
|
3330
|
+
}
|
|
3331
|
+
}, 0);
|
|
3332
|
+
}
|
|
3333
|
+
/**
|
|
3334
|
+
* Render
|
|
3335
|
+
*
|
|
3336
|
+
* @returns {HTMLElement} HTML Element
|
|
3337
|
+
*/
|
|
3338
|
+
render() {
|
|
3339
|
+
return (index.h(index.Host, { role: this.isChildMenu ? 'menu' : 'menubar', "aria-label": this.label, classList: this.classList.join() }, index.h("slot", null)));
|
|
3340
|
+
}
|
|
3341
|
+
get element() { return index.getElement(this); }
|
|
3342
|
+
static get watchers() { return {
|
|
3343
|
+
"label": ["validateLabel"],
|
|
3344
|
+
"direction": ["validateDirection"]
|
|
3345
|
+
}; }
|
|
3346
|
+
};
|
|
3347
|
+
MgMenu.style = mgMenuCss;
|
|
3348
|
+
|
|
3349
|
+
/**
|
|
3350
|
+
* Available menu-item positions
|
|
3351
|
+
*/
|
|
3352
|
+
var ElementPosition;
|
|
3353
|
+
(function (ElementPosition) {
|
|
3354
|
+
ElementPosition["FIRST"] = "first";
|
|
3355
|
+
ElementPosition["LAST"] = "last";
|
|
3356
|
+
})(ElementPosition || (ElementPosition = {}));
|
|
3357
|
+
/**
|
|
3358
|
+
* Available menu item status
|
|
3359
|
+
*/
|
|
3360
|
+
var Status$1;
|
|
3361
|
+
(function (Status) {
|
|
3362
|
+
Status["VISIBLE"] = "visible";
|
|
3363
|
+
Status["HIDDEN"] = "hidden";
|
|
3364
|
+
Status["DISABLED"] = "disabled";
|
|
3365
|
+
Status["ACTIVE"] = "active";
|
|
3366
|
+
})(Status$1 || (Status$1 = {}));
|
|
3367
|
+
/**
|
|
3368
|
+
* List of all possibles sizes
|
|
3369
|
+
*/
|
|
3370
|
+
const sizes$1 = ['regular', 'medium', 'large'];
|
|
3371
|
+
|
|
3372
|
+
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}";
|
|
3373
|
+
|
|
3374
|
+
const MgMenuItem = class {
|
|
3375
|
+
constructor(hostRef) {
|
|
3376
|
+
index.registerInstance(this, hostRef);
|
|
3377
|
+
/************
|
|
3378
|
+
* Internal *
|
|
3379
|
+
************/
|
|
3380
|
+
this.name = 'mg-menu-item';
|
|
3381
|
+
this.navigationButton = `${this.name}__navigation-button`;
|
|
3382
|
+
/**
|
|
3383
|
+
* Define menu-item status. Default: "visible"
|
|
3384
|
+
*/
|
|
3385
|
+
this.status = Status$1.VISIBLE;
|
|
3386
|
+
/**
|
|
3387
|
+
* Define menu-item size. Default: "large".
|
|
3388
|
+
*/
|
|
3389
|
+
this.size = 'large';
|
|
3390
|
+
/**
|
|
3391
|
+
* Define menu-item content expanded. Default: false.
|
|
3392
|
+
*/
|
|
3393
|
+
this.expanded = false;
|
|
3394
|
+
/************
|
|
3395
|
+
* States *
|
|
3396
|
+
************/
|
|
3397
|
+
/**
|
|
3398
|
+
* Component classes
|
|
3399
|
+
*/
|
|
3400
|
+
this.classList = new ClassList([this.name]);
|
|
3401
|
+
/**
|
|
3402
|
+
* Component button classes
|
|
3403
|
+
*/
|
|
3404
|
+
this.navigationButtonClassList = new ClassList([this.navigationButton]);
|
|
3405
|
+
/**
|
|
3406
|
+
* Does component have children. Default: false.
|
|
3407
|
+
*/
|
|
3408
|
+
this.hasChildren = false;
|
|
3409
|
+
/************
|
|
3410
|
+
* Methods *
|
|
3411
|
+
************/
|
|
3412
|
+
/**
|
|
3413
|
+
* Toggle expanded prop value
|
|
3414
|
+
*
|
|
3415
|
+
* @returns {void}
|
|
3416
|
+
*/
|
|
3417
|
+
this.toggleExpanded = () => {
|
|
3418
|
+
this.expanded = !this.expanded;
|
|
3419
|
+
};
|
|
3420
|
+
/**
|
|
3421
|
+
* Does an HTMLElement contain child with given Status
|
|
3422
|
+
*
|
|
3423
|
+
* @param {HTMLElement} element to parse
|
|
3424
|
+
* @param {MgMenuItem['status']} status to check
|
|
3425
|
+
* @returns {boolean} true if element with status is found
|
|
3426
|
+
*/
|
|
3427
|
+
this.hasChildElementStatus = (element, status) => element.querySelector(`${this.name}[status="${status}"]`) !== null;
|
|
3428
|
+
/**
|
|
3429
|
+
* Is component contextual direction match the given direction
|
|
3430
|
+
*
|
|
3431
|
+
* @param {MgMenuItem['direction']} direction in parent menu
|
|
3432
|
+
* @returns {boolean} true is direction match the direction propertie
|
|
3433
|
+
*/
|
|
3434
|
+
this.isdirection = (direction) => this.direction === direction;
|
|
3435
|
+
/************
|
|
3436
|
+
* Handlers *
|
|
3437
|
+
************/
|
|
3438
|
+
/**
|
|
3439
|
+
* Handle interacrtive element click
|
|
3440
|
+
*
|
|
3441
|
+
* @param {MouseEvent} event click on element
|
|
3442
|
+
* @returns {void}
|
|
3443
|
+
*/
|
|
3444
|
+
this.handleElementCLick = (event) => {
|
|
3445
|
+
event.preventDefault();
|
|
3446
|
+
if (this.hasChildren)
|
|
3447
|
+
this.toggleExpanded();
|
|
3448
|
+
};
|
|
3449
|
+
}
|
|
3450
|
+
validateStatus(newValue, oldValue) {
|
|
3451
|
+
if (oldValue !== undefined) {
|
|
3452
|
+
this.navigationButtonClassList.delete(`${this.navigationButton}--${oldValue}`);
|
|
3453
|
+
}
|
|
3454
|
+
this.navigationButtonClassList.add(`${this.navigationButton}--${newValue}`);
|
|
3455
|
+
}
|
|
3456
|
+
validateSize(newValue, oldValue) {
|
|
3457
|
+
if (!sizes$1.includes(newValue)) {
|
|
3458
|
+
throw new Error(`<${this.name}> prop "size" must be one of : ${sizes$1.join(', ')}.`);
|
|
3459
|
+
}
|
|
3460
|
+
this.navigationButtonClassList.delete(`${this.navigationButton}--size-${oldValue}`);
|
|
3461
|
+
this.navigationButtonClassList.add(`${this.navigationButton}--size-${newValue}`);
|
|
3462
|
+
}
|
|
3463
|
+
validateExpanded(newValue) {
|
|
3464
|
+
if (typeof newValue !== 'boolean')
|
|
3465
|
+
throw new Error(`<${this.name}> prop "expanded" must be a boolean.`);
|
|
3466
|
+
// if menu-item has sub-menu we have to apply some updates:
|
|
3467
|
+
if (this.hasChildren) {
|
|
3468
|
+
const subItems = Array.from(this.element.querySelectorAll(this.name));
|
|
3469
|
+
if (!newValue) {
|
|
3470
|
+
// - when main menu item is NOT expanded we need NOT expanded sub-items and NOT expanded sub-content
|
|
3471
|
+
subItems.forEach(item => {
|
|
3472
|
+
item.expanded = false;
|
|
3473
|
+
});
|
|
3474
|
+
}
|
|
3475
|
+
else if (newValue && this.hasChildElementStatus(this.element, Status$1.ACTIVE)) {
|
|
3476
|
+
// - when expanded and contain an active item parents are expended too
|
|
3477
|
+
subItems.forEach(item => {
|
|
3478
|
+
if (this.hasChildElementStatus(item, Status$1.ACTIVE)) {
|
|
3479
|
+
item.expanded = true;
|
|
3480
|
+
}
|
|
3481
|
+
});
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
}
|
|
3485
|
+
validateHasChildren(newValue) {
|
|
3486
|
+
if (newValue && this.element.href !== undefined) {
|
|
3487
|
+
throw new Error(`<${this.name}> prop "href" is unauthorizied when element is a parent.`);
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
/*************
|
|
3491
|
+
* Lifecycle *
|
|
3492
|
+
*************/
|
|
3493
|
+
/**
|
|
3494
|
+
* Validate props
|
|
3495
|
+
*
|
|
3496
|
+
* @returns {void}
|
|
3497
|
+
*/
|
|
3498
|
+
componentWillLoad() {
|
|
3499
|
+
// has children items that is NOT [slot="illustration"] || [slot="information"] element
|
|
3500
|
+
// we store only matching elements
|
|
3501
|
+
this.hasChildren = Array.from(this.element.children).filter(child => !['illustration', 'information', 'label', 'metadata'].includes(child.getAttribute('slot'))).length > 0;
|
|
3502
|
+
// Validate props
|
|
3503
|
+
this.validateSize(this.size);
|
|
3504
|
+
this.validateStatus(this.status);
|
|
3505
|
+
this.validateExpanded(this.expanded);
|
|
3506
|
+
}
|
|
3507
|
+
/**
|
|
3508
|
+
* Check if component slots configuration
|
|
3509
|
+
*
|
|
3510
|
+
* @returns {ReturnType<typeof setTimeout>} timeout
|
|
3511
|
+
*/
|
|
3512
|
+
componentDidLoad() {
|
|
3513
|
+
// slot title AND metadata validation
|
|
3514
|
+
// add title on label AND metada slots due to text-overflow on these element
|
|
3515
|
+
if (Array.from(this.element.children).find(child => child.getAttribute('slot') === 'label') === undefined)
|
|
3516
|
+
throw new Error(`<${this.name}> slot "label" is required.`);
|
|
3517
|
+
['label', 'metadata'].forEach(slot => {
|
|
3518
|
+
Array.from(this.element.querySelectorAll(`[slot="${slot}"]`)).forEach(element => {
|
|
3519
|
+
if (element.textContent.trim().length < 1)
|
|
3520
|
+
throw new Error(`<${this.name}> slot "${slot}" must have text content.`);
|
|
3521
|
+
if (element.getAttribute('title') === null)
|
|
3522
|
+
element.setAttribute('title', element.textContent);
|
|
3523
|
+
});
|
|
3524
|
+
});
|
|
3525
|
+
// update props and states after componentDidLoad hook
|
|
3526
|
+
// return a promise to process action only in the FIRST render().
|
|
3527
|
+
// https://stenciljs.com/docs/component-lifecycle#componentwillload
|
|
3528
|
+
return setTimeout(() => {
|
|
3529
|
+
var _a, _b;
|
|
3530
|
+
// define menu-item context states
|
|
3531
|
+
if (this.element.parentElement.nodeName === 'MG-MENU') {
|
|
3532
|
+
this.direction = this.element.parentElement.direction;
|
|
3533
|
+
}
|
|
3534
|
+
this.isInMainMenu = this.element.parentElement.className.includes('mg-menu-item') === false;
|
|
3535
|
+
const hasNextMenuItem = ((_a = this.element.nextElementSibling) === null || _a === void 0 ? void 0 : _a.nodeName) === 'MG-MENU-ITEM';
|
|
3536
|
+
const hasPreviousMenuItem = ((_b = this.element.previousElementSibling) === null || _b === void 0 ? void 0 : _b.nodeName) === 'MG-MENU-ITEM';
|
|
3537
|
+
// manage last menu item
|
|
3538
|
+
if (!hasNextMenuItem && hasPreviousMenuItem && this.isdirection(Direction.HORIZONTAL)) {
|
|
3539
|
+
this.classList.add(`${this.name}--${ElementPosition.LAST}`);
|
|
3540
|
+
}
|
|
3541
|
+
// when main menu item contain an active item it will get the active style
|
|
3542
|
+
// AND if item is in vertical menu it will be expanded
|
|
3543
|
+
if (this.isInMainMenu && this.hasChildElementStatus(this.element, Status$1.ACTIVE)) {
|
|
3544
|
+
this.status = Status$1.ACTIVE;
|
|
3545
|
+
this.expanded = this.direction === Direction.VERTICAL;
|
|
3546
|
+
}
|
|
3547
|
+
// manage menu items style depending to parent menu horientation
|
|
3548
|
+
this.classList.add(`${this.name}--${this.direction}`);
|
|
3549
|
+
this.navigationButtonClassList.add(`${this.navigationButton}--${this.direction}`);
|
|
3550
|
+
// manage child items level
|
|
3551
|
+
const childItems = Array.from(this.element.querySelectorAll('mg-menu-item'));
|
|
3552
|
+
childItems.forEach(item => {
|
|
3553
|
+
if (this.direction === Direction.VERTICAL) {
|
|
3554
|
+
const itemLevel = Number(item.getAttribute('data-level')) || 1;
|
|
3555
|
+
item.setAttribute('data-level', `${itemLevel + 1}`);
|
|
3556
|
+
}
|
|
3557
|
+
});
|
|
3558
|
+
}, 0);
|
|
3559
|
+
}
|
|
3560
|
+
/**
|
|
3561
|
+
* Render
|
|
3562
|
+
*
|
|
3563
|
+
* @returns {HTMLElement} HTML Element
|
|
3564
|
+
*/
|
|
3565
|
+
render() {
|
|
3566
|
+
const TagName = this.href !== undefined ? 'a' : 'button';
|
|
3567
|
+
return (index.h(index.Host, { role: "menuitem", "aria-haspopup": this.hasChildren.toString(), class: this.classList.join() }, index.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 }, index.h("slot", { name: "illustration" }), index.h("div", { class: `${this.navigationButton}-center` }, index.h("div", { class: `${this.navigationButton}-text-content` }, index.h("slot", { name: "label" }), index.h("slot", { name: "information" })), index.h("slot", { name: "metadata" })), this.hasChildren && this.href === undefined && (index.h("span", { class: {
|
|
3568
|
+
[`${this.navigationButton}-chevron`]: true,
|
|
3569
|
+
[`${this.navigationButton}-chevron--rotate`]: this.expanded === true,
|
|
3570
|
+
} }, index.h("mg-icon", { icon: "chevron-down" })))), index.h("div", { class: { [`${this.name}__collapse-container`]: true, [`${this.name}__collapse-container--first-level`]: this.isInMainMenu && this.isdirection(Direction.HORIZONTAL) }, hidden: !this.expanded }, index.h("slot", null))));
|
|
3571
|
+
}
|
|
3572
|
+
get element() { return index.getElement(this); }
|
|
3573
|
+
static get watchers() { return {
|
|
3574
|
+
"status": ["validateStatus"],
|
|
3575
|
+
"size": ["validateSize"],
|
|
3576
|
+
"expanded": ["validateExpanded"],
|
|
3577
|
+
"hasChildren": ["validateHasChildren"]
|
|
3578
|
+
}; }
|
|
3579
|
+
};
|
|
3580
|
+
MgMenuItem.style = mgMenuItemCss;
|
|
3581
|
+
|
|
3096
3582
|
/**
|
|
3097
3583
|
* List of all possibles message variants
|
|
3098
3584
|
*/
|
|
@@ -3108,7 +3594,7 @@ const MgMessage = class {
|
|
|
3108
3594
|
/************
|
|
3109
3595
|
* Internal *
|
|
3110
3596
|
************/
|
|
3111
|
-
//
|
|
3597
|
+
// Classes
|
|
3112
3598
|
this.classHide = 'mg-message--hide';
|
|
3113
3599
|
// IDs
|
|
3114
3600
|
this.closeButtonId = '';
|
|
@@ -3386,10 +3872,6 @@ const MgModal = class {
|
|
|
3386
3872
|
*/
|
|
3387
3873
|
componentDidLoad() {
|
|
3388
3874
|
new MutationObserver(mutationList => {
|
|
3389
|
-
/*
|
|
3390
|
-
TODO find a way to cover this callback
|
|
3391
|
-
*/
|
|
3392
|
-
/* istanbul ignore next */
|
|
3393
3875
|
if (mutationList.some(mutation => mutation.attributeName === 'aria-hidden' && mutation.target.ariaHidden === null)) {
|
|
3394
3876
|
this.setFocus();
|
|
3395
3877
|
}
|
|
@@ -5679,6 +6161,9 @@ const MgPopover = class {
|
|
|
5679
6161
|
};
|
|
5680
6162
|
MgPopover.style = mgPopoverCss;
|
|
5681
6163
|
|
|
6164
|
+
/**
|
|
6165
|
+
* Available tabs items status
|
|
6166
|
+
*/
|
|
5682
6167
|
var Status;
|
|
5683
6168
|
(function (Status) {
|
|
5684
6169
|
Status["VISIBLE"] = "visible";
|
|
@@ -5691,7 +6176,7 @@ var Status;
|
|
|
5691
6176
|
*/
|
|
5692
6177
|
const sizes = ['regular', 'large'];
|
|
5693
6178
|
|
|
5694
|
-
const mgTabsCss = ".mg-tabs.mg-tabs--size-regular .mg-tabs__navigation-button{padding:calc(1rem
|
|
6179
|
+
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}";
|
|
5695
6180
|
|
|
5696
6181
|
/**
|
|
5697
6182
|
* type TabItem validation function
|
|
@@ -5879,10 +6364,11 @@ const MgTabs = class {
|
|
|
5879
6364
|
render() {
|
|
5880
6365
|
return (index.h("div", { class: this.classList.join() }, index.h("header", { role: "tablist", "aria-label": this.label, class: "mg-tabs__header" }, this.tabs.map((tab, index$1) => (index.h("button", { role: "tab", id: this.getElementId(this.identifier, index$1), class: {
|
|
5881
6366
|
[`${this.buttonTabBaseClass}`]: true,
|
|
6367
|
+
[`${this.buttonTabBaseClass}--horizontal`]: true,
|
|
5882
6368
|
[`${this.getNavigationButtonClass(Status.ACTIVE)}`]: this.tabHasGivenStatus(tab, Status.ACTIVE),
|
|
5883
6369
|
[`${this.getNavigationButtonClass(Status.DISABLED)}`]: this.tabHasGivenStatus(tab, Status.DISABLED),
|
|
5884
6370
|
[`${this.getNavigationButtonClass(Status.HIDDEN)}`]: this.tabHasGivenStatus(tab, Status.HIDDEN),
|
|
5885
|
-
}, tabindex: this.tabHasGivenStatus(tab, Status.ACTIVE) ? 0 : -1, "aria-selected": this.tabHasGivenStatus(tab, Status.ACTIVE).toString(), "aria-controls": this.getElementId(this.tabPanel, index$1), onClick: this.handleClick, onKeyDown: this.handleKeydown, "data-index": this.getTabIndex(index$1), disabled: this.tabHasGivenStatus(tab, Status.DISABLED) }, tab.icon !== undefined && index.h("mg-icon", { icon: tab.icon }), tab.label, tab.badge !== undefined && index.h("mg-badge", { variant:
|
|
6371
|
+
}, tabindex: this.tabHasGivenStatus(tab, Status.ACTIVE) ? 0 : -1, "aria-selected": this.tabHasGivenStatus(tab, Status.ACTIVE).toString(), "aria-controls": this.getElementId(this.tabPanel, index$1), onClick: this.handleClick, onKeyDown: this.handleKeydown, "data-index": this.getTabIndex(index$1), disabled: this.tabHasGivenStatus(tab, Status.DISABLED) }, tab.icon !== undefined && index.h("mg-icon", { icon: tab.icon }), tab.label, tab.badge !== undefined && index.h("mg-badge", { variant: tab.status !== Status.ACTIVE ? 'primary' : 'info', value: tab.badge.value, label: tab.badge.label }))))), this.tabs.map((tab, index$1) => (index.h("article", { role: "tabpanel", id: this.getElementId(this.tabPanel, index$1), hidden: !this.tabHasGivenStatus(tab, Status.ACTIVE), "aria-labelledby": this.getElementId(this.identifier, index$1), tabindex: this.tabHasGivenStatus(tab, Status.ACTIVE) ? 0 : -1, class: "mg-tabs__content-container" }, index.h("slot", { name: this.getElementId('tab_content', index$1) }))))));
|
|
5886
6372
|
}
|
|
5887
6373
|
get element() { return index.getElement(this); }
|
|
5888
6374
|
static get watchers() { return {
|
|
@@ -5907,7 +6393,7 @@ const MgTag = class {
|
|
|
5907
6393
|
/************
|
|
5908
6394
|
* Internal *
|
|
5909
6395
|
************/
|
|
5910
|
-
//
|
|
6396
|
+
// Classes
|
|
5911
6397
|
this.classOutline = `mg-tag--outline`;
|
|
5912
6398
|
/**************
|
|
5913
6399
|
* Decorators *
|
|
@@ -6184,6 +6670,8 @@ exports.mg_input_text = MgInputText;
|
|
|
6184
6670
|
exports.mg_input_textarea = MgInputTextarea;
|
|
6185
6671
|
exports.mg_input_title = MgInputTitle;
|
|
6186
6672
|
exports.mg_input_toggle = MgInputToggle;
|
|
6673
|
+
exports.mg_menu = MgMenu;
|
|
6674
|
+
exports.mg_menu_item = MgMenuItem;
|
|
6187
6675
|
exports.mg_message = MgMessage;
|
|
6188
6676
|
exports.mg_modal = MgModal;
|
|
6189
6677
|
exports.mg_pagination = MgPagination;
|