@mgdis/mg-components 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/css-shim-629916b0.js +6 -0
- package/dist/cjs/index-369388eb.js +146 -0
- package/dist/cjs/{index-85a4a0b6.js → index-bead7dbd.js} +78 -2
- package/dist/cjs/loader.cjs.js +4 -4
- package/dist/cjs/mg-badge_21.cjs.entry.js +3313 -0
- package/dist/cjs/mg-components.cjs.js +3 -3
- package/dist/cjs/mg-modal.cjs.entry.js +111 -0
- package/dist/cjs/mg-popover.cjs.entry.js +165 -0
- package/dist/cjs/popper-0c3964e7.js +1786 -0
- package/dist/cjs/{shadow-css-8940f82d.js → shadow-css-546083ef.js} +1 -1
- package/dist/collection/collection-manifest.json +4 -1
- package/dist/collection/components/atoms/mg-badge/mg-badge.conf.js +1 -1
- package/dist/collection/components/atoms/mg-badge/mg-badge.js +11 -7
- package/dist/collection/components/atoms/mg-badge/mg-badge.stories.js +3 -0
- package/dist/collection/components/atoms/mg-button/mg-button.css +26 -17
- package/dist/collection/components/atoms/mg-button/mg-button.js +71 -2
- package/dist/collection/components/atoms/mg-button/mg-button.stories.js +5 -0
- package/dist/collection/components/atoms/mg-character-left/mg-character-left.js +12 -1
- package/dist/collection/components/atoms/mg-character-left/mg-character-left.stories.js +8 -0
- package/dist/collection/components/atoms/mg-icon/mg-icon.conf.js +8 -0
- package/dist/collection/components/atoms/mg-icon/mg-icon.css +5 -7
- package/dist/collection/components/atoms/mg-icon/mg-icon.js +11 -1
- package/dist/collection/components/atoms/mg-input-title/mg-input-title.css +4 -4
- package/dist/collection/components/atoms/mg-input-title/mg-input-title.js +14 -3
- package/dist/collection/components/atoms/mg-tag/mg-tag.js +10 -3
- package/dist/collection/components/atoms/mg-tag/mg-tag.stories.js +3 -0
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +9 -0
- package/dist/collection/components/molecules/inputs/MgInput.js +20 -14
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.css +9 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +103 -40
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.stories.js +6 -1
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.css +27 -0
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +125 -56
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.stories.js +6 -1
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.css +27 -0
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +144 -68
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.stories.js +6 -1
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.css +27 -0
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +101 -35
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.stories.js +6 -1
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.css +9 -1
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +115 -37
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.stories.js +6 -1
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.css +28 -1
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +132 -51
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.stories.js +14 -1
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.css +27 -0
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +155 -53
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.stories.js +7 -2
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.css +27 -0
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +108 -42
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.stories.js +7 -2
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.css +4 -1
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +60 -31
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.stories.js +6 -1
- package/dist/collection/components/molecules/mg-form/mg-form.css +15 -0
- package/dist/collection/components/molecules/mg-form/mg-form.js +269 -0
- package/dist/collection/components/molecules/mg-form/mg-form.stories.js +58 -0
- package/dist/collection/components/molecules/mg-message/mg-message.css +1 -1
- package/dist/collection/components/molecules/mg-message/mg-message.js +11 -4
- package/dist/collection/components/molecules/mg-message/mg-message.stories.js +5 -1
- package/dist/collection/components/molecules/mg-modal/mg-modal.css +54 -0
- package/dist/collection/components/molecules/mg-modal/mg-modal.js +233 -0
- package/dist/collection/components/molecules/mg-modal/mg-modal.stories.js +51 -0
- package/dist/collection/components/molecules/mg-pagination/mg-pagination.js +32 -12
- package/dist/collection/components/molecules/mg-pagination/mg-pagination.stories.js +1 -0
- package/dist/collection/components/molecules/mg-panel/mg-panel.css +42 -0
- package/dist/collection/components/molecules/mg-panel/mg-panel.js +255 -0
- package/dist/collection/components/molecules/mg-panel/mg-panel.stories.js +31 -0
- package/dist/collection/components/molecules/mg-popover/mg-popover.css +2 -2
- package/dist/collection/components/molecules/mg-popover/mg-popover.js +19 -4
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.conf.js +4 -1
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.css +14 -3
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +68 -20
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.stories.js +10 -1
- package/dist/collection/stories/messages.stories.js +1 -1
- package/dist/collection/utils/components.utils.js +16 -9
- package/dist/collection/utils/locale.utils.js +6 -3
- package/dist/collection/utils/test.utils.js +27 -15
- package/dist/collection/variables.css +30 -1
- package/dist/collection/variables.scss +30 -1
- package/dist/components/MgInput.js +20 -14
- package/dist/components/components.utils.js +16 -9
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index2.js +22 -12
- package/dist/components/locale.utils.js +6 -3
- package/dist/components/mg-badge2.js +9 -5
- package/dist/components/mg-button2.js +21 -2
- package/dist/components/mg-character-left2.js +12 -1
- package/dist/components/mg-form.d.ts +11 -0
- package/dist/components/mg-form.js +146 -0
- package/dist/components/mg-icon2.js +20 -2
- package/dist/components/mg-input-checkbox.js +65 -36
- package/dist/components/mg-input-date.js +87 -52
- package/dist/components/mg-input-numeric.js +105 -63
- package/dist/components/mg-input-password.js +60 -29
- package/dist/components/mg-input-radio.js +74 -34
- package/dist/components/mg-input-select2.js +89 -46
- package/dist/components/mg-input-text.js +1 -237
- package/dist/components/mg-input-text2.js +288 -0
- package/dist/components/mg-input-textarea.js +67 -36
- package/dist/components/mg-input-title2.js +13 -4
- package/dist/components/mg-input-toggle.js +30 -22
- package/dist/components/mg-message.js +10 -3
- package/dist/components/mg-modal.d.ts +11 -0
- package/dist/components/mg-modal.js +147 -0
- package/dist/components/mg-pagination.js +31 -11
- package/dist/components/mg-panel.d.ts +11 -0
- package/dist/components/mg-panel.js +210 -0
- package/dist/components/mg-popover.js +20 -5
- package/dist/components/mg-tabs.js +43 -11
- package/dist/components/mg-tag.js +8 -1
- package/dist/components/mg-tooltip2.js +9 -0
- package/dist/esm/css-shim-0993aa3b.js +4 -0
- package/dist/esm/{index-e3e84606.js → index-9e877561.js} +78 -2
- package/dist/esm/index-c346f52d.js +139 -0
- package/dist/esm/loader.js +4 -4
- package/dist/esm/mg-badge_21.entry.js +3289 -0
- package/dist/esm/mg-components.js +3 -3
- package/dist/esm/mg-modal.entry.js +107 -0
- package/dist/esm/mg-popover.entry.js +161 -0
- package/dist/esm/polyfills/css-shim.js +1 -1
- package/dist/esm/popper-8874fd6c.js +1784 -0
- package/dist/esm/{shadow-css-5d2d01ce.js → shadow-css-dfa0587f.js} +1 -1
- package/dist/esm-es5/css-shim-0993aa3b.js +1 -0
- package/dist/esm-es5/index-9e877561.js +1 -0
- package/dist/esm-es5/index-c346f52d.js +1 -0
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/mg-badge_21.entry.js +2 -0
- package/dist/esm-es5/mg-components.js +1 -1
- package/dist/esm-es5/mg-modal.entry.js +1 -0
- package/dist/esm-es5/mg-popover.entry.js +1 -0
- package/dist/esm-es5/popper-8874fd6c.js +1 -0
- package/dist/esm-es5/{shadow-css-5d2d01ce.js → shadow-css-dfa0587f.js} +0 -0
- package/dist/mg-components/mg-components.css +1 -1
- package/dist/mg-components/mg-components.esm.js +1 -1
- package/dist/mg-components/mg-components.js +2 -2
- package/dist/mg-components/p-3633e9e1.system.entry.js +2 -0
- package/dist/mg-components/p-3c14153d.js +1 -0
- package/dist/mg-components/p-55a22b35.system.js +1 -0
- package/dist/mg-components/{p-f6455ab3.js → p-5e796581.js} +0 -0
- package/dist/mg-components/p-656b5efb.system.js +1 -0
- package/dist/mg-components/p-68d6f104.js +1 -0
- package/dist/mg-components/{p-366a224e.js → p-6d49ed95.js} +1 -1
- package/dist/mg-components/p-70177194.entry.js +1 -0
- package/dist/mg-components/{p-71d57b8b.system.js → p-8b2d8a2a.system.js} +0 -0
- package/dist/mg-components/p-8cb61c3f.system.js +1 -0
- package/dist/mg-components/p-ace173b1.js +1 -0
- package/dist/mg-components/p-c46fbd54.entry.js +1 -0
- package/dist/mg-components/p-c90cc4bf.system.js +1 -0
- package/dist/mg-components/p-cd2a4acc.system.entry.js +1 -0
- package/dist/mg-components/p-de1164fa.system.entry.js +1 -0
- package/dist/mg-components/p-dfe25da3.entry.js +1 -0
- package/dist/mg-components/p-e4a502b5.system.js +1 -0
- package/dist/mg-components/variables.css +30 -1
- package/dist/mg-components/variables.scss +30 -1
- package/dist/types/components/atoms/mg-badge/mg-badge.d.ts +8 -4
- package/dist/types/components/atoms/mg-badge/mg-badge.stories.d.ts +5 -0
- package/dist/types/components/atoms/mg-button/mg-button.d.ts +22 -2
- package/dist/types/components/atoms/mg-button/mg-button.stories.d.ts +5 -0
- package/dist/types/components/atoms/mg-character-left/mg-character-left.d.ts +13 -2
- package/dist/types/components/atoms/mg-character-left/mg-character-left.stories.d.ts +9 -0
- package/dist/types/components/atoms/mg-icon/mg-icon.conf.d.ts +1 -1
- package/dist/types/components/atoms/mg-icon/mg-icon.d.ts +11 -1
- package/dist/types/components/atoms/mg-input-title/mg-input-title.d.ts +11 -1
- package/dist/types/components/atoms/mg-tag/mg-tag.d.ts +10 -3
- package/dist/types/components/atoms/mg-tag/mg-tag.stories.d.ts +5 -0
- package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +11 -2
- package/dist/types/components/molecules/inputs/MgInput.conf.d.ts +8 -0
- package/dist/types/components/molecules/inputs/MgInput.d.ts +5 -4
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +31 -11
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.stories.d.ts +5 -0
- package/dist/types/components/molecules/inputs/mg-input-date/mg-input-date.d.ts +39 -14
- package/dist/types/components/molecules/inputs/mg-input-date/mg-input-date.stories.d.ts +5 -0
- package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +53 -14
- package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.stories.d.ts +5 -0
- package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.d.ts +28 -9
- package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.stories.d.ts +5 -0
- package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.conf.d.ts +1 -1
- package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.d.ts +37 -8
- package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.stories.d.ts +5 -0
- package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.conf.d.ts +1 -1
- package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.d.ts +30 -7
- package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.stories.d.ts +14 -0
- package/dist/types/components/molecules/inputs/mg-input-text/mg-input-text.d.ts +46 -10
- package/dist/types/components/molecules/inputs/mg-input-text/mg-input-text.stories.d.ts +5 -0
- package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.d.ts +30 -10
- package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.stories.d.ts +5 -0
- package/dist/types/components/molecules/inputs/mg-input-toggle/mg-input-toggle.conf.d.ts +1 -1
- package/dist/types/components/molecules/inputs/mg-input-toggle/mg-input-toggle.d.ts +27 -12
- package/dist/types/components/molecules/inputs/mg-input-toggle/mg-input-toggle.stories.d.ts +5 -0
- package/dist/types/components/molecules/mg-form/mg-form.d.ts +82 -0
- package/dist/types/components/molecules/mg-form/mg-form.stories.d.ts +11 -0
- package/dist/types/components/molecules/mg-message/mg-message.d.ts +11 -4
- package/dist/types/components/molecules/mg-message/mg-message.stories.d.ts +10 -0
- package/dist/types/components/molecules/mg-modal/mg-modal.d.ts +83 -0
- package/dist/types/components/molecules/mg-modal/mg-modal.stories.d.ts +13 -0
- package/dist/types/components/molecules/mg-pagination/mg-pagination.d.ts +23 -7
- package/dist/types/components/molecules/mg-pagination/mg-pagination.stories.d.ts +5 -0
- package/dist/types/components/molecules/mg-panel/mg-panel.d.ts +110 -0
- package/dist/types/components/molecules/mg-panel/mg-panel.stories.d.ts +6 -0
- package/dist/types/components/molecules/mg-popover/mg-popover.d.ts +18 -3
- package/dist/types/components/molecules/mg-tabs/mg-tabs.conf.d.ts +5 -0
- package/dist/types/components/molecules/mg-tabs/mg-tabs.d.ts +21 -6
- package/dist/types/components/molecules/mg-tabs/mg-tabs.stories.d.ts +8 -0
- package/dist/types/components.d.ts +365 -78
- package/dist/types/locales/index.d.ts +15 -8
- package/dist/types/utils/components.utils.d.ts +16 -9
- package/dist/types/utils/locale.utils.d.ts +6 -3
- package/dist/types/utils/test.utils.d.ts +13 -1
- package/package.json +13 -9
- package/readme.md +3 -0
- package/dist/cjs/css-shim-a22512c4.js +0 -6
- package/dist/cjs/mg-badge_20.cjs.entry.js +0 -4661
- package/dist/esm/css-shim-7c240feb.js +0 -4
- package/dist/esm/mg-badge_20.entry.js +0 -4638
- package/dist/esm-es5/css-shim-7c240feb.js +0 -1
- package/dist/esm-es5/index-e3e84606.js +0 -1
- package/dist/esm-es5/mg-badge_20.entry.js +0 -2
- package/dist/mg-components/p-1cd24462.system.js +0 -1
- package/dist/mg-components/p-2e2f6b27.system.entry.js +0 -2
- package/dist/mg-components/p-422c429b.system.js +0 -1
- package/dist/mg-components/p-62fa3797.js +0 -1
- package/dist/mg-components/p-9a215712.system.js +0 -1
- package/dist/mg-components/p-cbf0464b.entry.js +0 -1
|
@@ -0,0 +1,3289 @@
|
|
|
1
|
+
import { r as registerInstance, h, g as getElement, c as createEvent, H as Host } from './index-9e877561.js';
|
|
2
|
+
import { C as ClassList, c as createID, m as messages, l as locale, a as currency, b as allItemsAreString } from './index-c346f52d.js';
|
|
3
|
+
import { c as createPopper } from './popper-8874fd6c.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* List of all possibles variants
|
|
7
|
+
*/
|
|
8
|
+
const variants$4 = ['info', 'primary', 'secondary', 'success', 'warning', 'danger'];
|
|
9
|
+
|
|
10
|
+
const mgBadgeCss = ".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-badge{padding:0 0.4rem;height:var(--mg-badge-size);min-width:var(--mg-badge-size);-webkit-box-sizing:border-box;box-sizing:border-box;border:0.1rem solid;border-radius:50%;border-radius:calc(var(--mg-badge-size) / 2);font-size:var(--mg-badge-font-size);font-weight:600;text-align:center;line-height:var(--mg-badge-size)}.mg-badge.mg-badge--primary{background-color:hsl(var(--color-dark));border-color:hsl(var(--color-dark));color:hsl(var(--color-light))}.mg-badge.mg-badge--primary.mg-badge--outline{background-color:transparent;color:hsl(var(--color-dark))}.mg-badge.mg-badge--secondary{background-color:hsl(var(--color-light));border-color:hsl(var(--color-light));color:hsl(var(--color-dark))}.mg-badge.mg-badge--secondary.mg-badge--outline{background-color:transparent;color:hsl(var(--color-light))}.mg-badge.mg-badge--success{background-color:hsl(var(--color-success));border-color:hsl(var(--color-success));color:hsl(var(--color-dark))}.mg-badge.mg-badge--success.mg-badge--outline{background-color:transparent;color:hsl(var(--color-success))}.mg-badge.mg-badge--warning{background-color:hsl(var(--color-warning));border-color:hsl(var(--color-warning));color:hsl(var(--color-dark))}.mg-badge.mg-badge--warning.mg-badge--outline{background-color:transparent;color:hsl(var(--color-warning))}.mg-badge.mg-badge--danger{background-color:hsl(var(--color-danger));border-color:hsl(var(--color-danger));color:hsl(var(--color-light))}.mg-badge.mg-badge--danger.mg-badge--outline{background-color:transparent;color:hsl(var(--color-danger))}.mg-badge.mg-badge--info{background-color:hsl(var(--color-info));border-color:hsl(var(--color-info));color:hsl(var(--color-light))}.mg-badge.mg-badge--info.mg-badge--outline{background-color:transparent;color:hsl(var(--color-info))}.mg-badge,mg-badge{display:-ms-inline-flexbox;display:inline-flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center}";
|
|
11
|
+
|
|
12
|
+
const MgBadge = class {
|
|
13
|
+
constructor(hostRef) {
|
|
14
|
+
registerInstance(this, hostRef);
|
|
15
|
+
/**
|
|
16
|
+
* Define button variant
|
|
17
|
+
*/
|
|
18
|
+
this.variant = variants$4[0]; // info
|
|
19
|
+
/**
|
|
20
|
+
* Component classes
|
|
21
|
+
*/
|
|
22
|
+
this.classList = new ClassList(['mg-badge']);
|
|
23
|
+
}
|
|
24
|
+
validateValue(newValue) {
|
|
25
|
+
if (`${newValue}`.match(/^(\d+|[?*!a-z])$/i) === null) {
|
|
26
|
+
throw new Error('<mg-badge> prop "value" must be interger or ponctuation character.');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
validateVariant(newValue) {
|
|
30
|
+
if (!variants$4.includes(newValue)) {
|
|
31
|
+
throw new Error(`<mg-badge> prop "variant" must be one of : ${variants$4.join(', ')}.`);
|
|
32
|
+
}
|
|
33
|
+
this.classList.add(`mg-badge--${this.variant}`);
|
|
34
|
+
}
|
|
35
|
+
validateOutline(newValue) {
|
|
36
|
+
if (newValue)
|
|
37
|
+
this.classList.add(`mg-badge--outline`);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check if props are well configured on init
|
|
41
|
+
*
|
|
42
|
+
* @returns {void}
|
|
43
|
+
*/
|
|
44
|
+
componentWillLoad() {
|
|
45
|
+
this.validateValue(this.value);
|
|
46
|
+
this.validateVariant(this.variant);
|
|
47
|
+
this.validateOutline(this.outline);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Render
|
|
51
|
+
*
|
|
52
|
+
* @returns {HTMLElement} HTML Element
|
|
53
|
+
*/
|
|
54
|
+
render() {
|
|
55
|
+
return (h("span", { class: this.classList.join() }, this.value, h("span", { class: "sr-only" }, this.label)));
|
|
56
|
+
}
|
|
57
|
+
static get watchers() { return {
|
|
58
|
+
"value": ["validateValue"],
|
|
59
|
+
"variant": ["validateVariant"],
|
|
60
|
+
"outline": ["validateOutline"]
|
|
61
|
+
}; }
|
|
62
|
+
};
|
|
63
|
+
MgBadge.style = mgBadgeCss;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* List of all possibles variants
|
|
67
|
+
*/
|
|
68
|
+
const variants$3 = ['primary', 'secondary', 'danger', 'danger-alt', 'info', 'flat'];
|
|
69
|
+
|
|
70
|
+
const mgButtonCss = ".mg-button.sc-mg-button{position:relative;display:-ms-inline-flexbox;display:inline-flex;-ms-flex-align:center;align-items:center;-webkit-column-gap:0.6rem;-moz-column-gap:0.6rem;column-gap:0.6rem;padding:calc((var(--default-size) - 0.2rem - var(--font-size) * var(--line-height)) / 2) 1.1rem;min-height:var(--default-size);-webkit-box-sizing:border-box;box-sizing:border-box;border-top-right-radius:var(--mg-button-border-radius-top-right, var(--mg-button-border-radius));border-top-left-radius:var(--mg-button-border-radius-top-left, var(--mg-button-border-radius));border-bottom-right-radius:var(--mg-button-border-radius-bottom-right, var(--mg-button-border-radius));border-bottom-left-radius:var(--mg-button-border-radius-bottom-left, var(--mg-button-border-radius));cursor:pointer;background-image:none;border-top-width:var(--mg-button-border-top-width, 0.1rem);border-right-width:var(--mg-button-border-right-width, 0.1rem);border-bottom-width:var(--mg-button-border-bottom-width, 0.1rem);border-left-width:var(--mg-button-border-left-width, 0.1rem);border-style:solid;font-family:inherit;text-decoration:none;font-weight:normal;text-align:left;-ms-touch-action:manipulation;touch-action:manipulation}.mg-button[disabled].sc-mg-button,.mg-button[aria-disabled].sc-mg-button,.mg-button.disabled.sc-mg-button{opacity:var(--mg-button-disabled-opacity);cursor:default}.mg-button.mg-button--icon.sc-mg-button{padding:0;-ms-flex-pack:center;justify-content:center;width:var(--default-size);height:var(--default-size);border-top-right-radius:var(--mg-button-border-radius-top-right, var(--mg-button-icon-border-radius));border-top-left-radius:var(--mg-button-border-radius-top-left, var(--mg-button-icon-border-radius));border-bottom-right-radius:var(--mg-button-border-radius-bottom-right, var(--mg-button-icon-border-radius));border-bottom-left-radius:var(--mg-button-border-radius-bottom-left, var(--mg-button-icon-border-radius));font-size:var(--font-size);line-height:var(--font-size)}.mg-button.mg-button--primary.sc-mg-button{border-color:hsl(var(--mg-button-primary-color-h), var(--mg-button-primary-color-s), var(--mg-button-primary-color-l));border-color:hsl(var(--mg-button-primary-color-h), var(--mg-button-primary-color-s), calc(var(--mg-button-primary-color-l) - 10%));color:hsl(var(--mg-button-primary-font-color));background:hsl(var(--mg-button-primary-color-h), var(--mg-button-primary-color-s), var(--mg-button-primary-color-l));background:-webkit-gradient(linear, left top, left bottom, from(hsl(var(--mg-button-primary-color-h), var(--mg-button-primary-color-s), var(--mg-button-primary-color-l))), to(hsl(var(--mg-button-primary-color-h), var(--mg-button-primary-color-s), calc(var(--mg-button-primary-color-l) - var(--mg-button-gradient) * 10%))));background:linear-gradient(to bottom, hsl(var(--mg-button-primary-color-h), var(--mg-button-primary-color-s), var(--mg-button-primary-color-l)), hsl(var(--mg-button-primary-color-h), var(--mg-button-primary-color-s), calc(var(--mg-button-primary-color-l) - var(--mg-button-gradient) * 10%)))}.mg-button.mg-button--primary.sc-mg-button:hover:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button,.mg-button.mg-button--primary.sc-mg-button:focus:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button,.mg-button.mg-button--primary.sc-mg-button:active:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button{background:hsl(var(--mg-button-primary-color-h), var(--mg-button-primary-color-s), var(--mg-button-primary-color-l))}.mg-button.mg-button--secondary.sc-mg-button{border-color:hsl(var(--mg-button-secondary-color-h), var(--mg-button-secondary-color-s), var(--mg-button-secondary-color-l));border-color:hsl(var(--mg-button-secondary-color-h), var(--mg-button-secondary-color-s), calc(var(--mg-button-secondary-color-l) - 10%));color:hsl(var(--mg-button-secondary-font-color));background:hsl(var(--mg-button-secondary-color-h), var(--mg-button-secondary-color-s), var(--mg-button-secondary-color-l));background:-webkit-gradient(linear, left top, left bottom, from(hsl(var(--mg-button-secondary-color-h), var(--mg-button-secondary-color-s), var(--mg-button-secondary-color-l))), to(hsl(var(--mg-button-secondary-color-h), var(--mg-button-secondary-color-s), calc(var(--mg-button-secondary-color-l) - var(--mg-button-gradient) * 10%))));background:linear-gradient(to bottom, hsl(var(--mg-button-secondary-color-h), var(--mg-button-secondary-color-s), var(--mg-button-secondary-color-l)), hsl(var(--mg-button-secondary-color-h), var(--mg-button-secondary-color-s), calc(var(--mg-button-secondary-color-l) - var(--mg-button-gradient) * 10%)))}.mg-button.mg-button--secondary.sc-mg-button:hover:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button,.mg-button.mg-button--secondary.sc-mg-button:focus:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button,.mg-button.mg-button--secondary.sc-mg-button:active:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button{background:hsl(var(--mg-button-secondary-color-h), var(--mg-button-secondary-color-s), var(--mg-button-secondary-color-l))}.mg-button.mg-button--danger.sc-mg-button{border-color:hsl(var(--color-danger-h), var(--color-danger-s), var(--color-danger-l));border-color:hsl(var(--color-danger-h), var(--color-danger-s), calc(var(--color-danger-l) - 10%));color:hsl(var(--color-neutral));background:hsl(var(--color-danger-h), var(--color-danger-s), var(--color-danger-l));background:-webkit-gradient(linear, left top, left bottom, from(hsl(var(--color-danger-h), var(--color-danger-s), var(--color-danger-l))), to(hsl(var(--color-danger-h), var(--color-danger-s), calc(var(--color-danger-l) - var(--mg-button-gradient) * 10%))));background:linear-gradient(to bottom, hsl(var(--color-danger-h), var(--color-danger-s), var(--color-danger-l)), hsl(var(--color-danger-h), var(--color-danger-s), calc(var(--color-danger-l) - var(--mg-button-gradient) * 10%)))}.mg-button.mg-button--danger.sc-mg-button:hover:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button,.mg-button.mg-button--danger.sc-mg-button:focus:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button,.mg-button.mg-button--danger.sc-mg-button:active:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button{background:hsl(var(--color-danger-h), var(--color-danger-s), var(--color-danger-l))}.mg-button.mg-button--danger-alt.sc-mg-button{border-color:hsl(var(--color-neutral-h), var(--color-neutral-s), var(--color-neutral-l));border-color:hsl(var(--color-neutral-h), var(--color-neutral-s), calc(var(--color-neutral-l) - 10%));color:hsl(var(--color-danger));background:hsl(var(--color-neutral-h), var(--color-neutral-s), var(--color-neutral-l));background:-webkit-gradient(linear, left top, left bottom, from(hsl(var(--color-neutral-h), var(--color-neutral-s), var(--color-neutral-l))), to(hsl(var(--color-neutral-h), var(--color-neutral-s), calc(var(--color-neutral-l) - var(--mg-button-gradient) * 10%))));background:linear-gradient(to bottom, hsl(var(--color-neutral-h), var(--color-neutral-s), var(--color-neutral-l)), hsl(var(--color-neutral-h), var(--color-neutral-s), calc(var(--color-neutral-l) - var(--mg-button-gradient) * 10%)))}.mg-button.mg-button--danger-alt.sc-mg-button:hover:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button,.mg-button.mg-button--danger-alt.sc-mg-button:focus:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button,.mg-button.mg-button--danger-alt.sc-mg-button:active:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button{background:hsl(var(--color-neutral-h), var(--color-neutral-s), var(--color-neutral-l))}.mg-button.mg-button--info.sc-mg-button{border-color:hsl(var(--color-info-h), var(--color-info-s), var(--color-info-l));border-color:hsl(var(--color-info-h), var(--color-info-s), calc(var(--color-info-l) - 10%));color:hsl(var(--color-neutral));background:hsl(var(--color-info-h), var(--color-info-s), var(--color-info-l));background:-webkit-gradient(linear, left top, left bottom, from(hsl(var(--color-info-h), var(--color-info-s), var(--color-info-l))), to(hsl(var(--color-info-h), var(--color-info-s), calc(var(--color-info-l) - var(--mg-button-gradient) * 10%))));background:linear-gradient(to bottom, hsl(var(--color-info-h), var(--color-info-s), var(--color-info-l)), hsl(var(--color-info-h), var(--color-info-s), calc(var(--color-info-l) - var(--mg-button-gradient) * 10%)))}.mg-button.mg-button--info.sc-mg-button:hover:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button,.mg-button.mg-button--info.sc-mg-button:focus:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button,.mg-button.mg-button--info.sc-mg-button:active:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button{background:hsl(var(--color-info-h), var(--color-info-s), var(--color-info-l))}.mg-button.mg-button--flat.sc-mg-button{background:none;border:none}.mg-button.mg-button--flat.sc-mg-button:hover:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button,.mg-button.mg-button--flat.sc-mg-button:focus:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button,.mg-button.mg-button--flat.sc-mg-button:active:not([disabled],[aria-disabled].sc-mg-button,.disabled).sc-mg-button{background:hsla(var(--color-dark), 0.1)}.mg-button.sc-mg-button mg-icon.sc-mg-button:only-child,.mg-button .sc-mg-button-s>mg-icon{display:-ms-inline-flexbox;display:inline-flex;-ms-flex-negative:0;flex-shrink:0;line-height:1;margin:auto 0}.mg-button.mg-button--loading.sc-mg-button>mg-icon.sc-mg-button{position:absolute;left:50%;top:50%;-webkit-transform:translate(-50%, -50%);transform:translate(-50%, -50%)}.mg-button.mg-button--loading.sc-mg-button .mg-button__content.sc-mg-button{opacity:0}.mg-button__content.sc-mg-button{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-webkit-column-gap:0.6rem;-moz-column-gap:0.6rem;column-gap:0.6rem}mg-button.sc-mg-button{display:inline-block}.mg-button.sc-mg-button,mg-button.sc-mg-button{vertical-align:middle;max-width:100%}";
|
|
71
|
+
|
|
72
|
+
const MgButton = class {
|
|
73
|
+
constructor(hostRef) {
|
|
74
|
+
registerInstance(this, hostRef);
|
|
75
|
+
/************
|
|
76
|
+
* Internal *
|
|
77
|
+
************/
|
|
78
|
+
this.onClickElementFn = null;
|
|
79
|
+
/**
|
|
80
|
+
* Define button variant
|
|
81
|
+
*/
|
|
82
|
+
this.variant = variants$3[0]; // Primary
|
|
83
|
+
/**
|
|
84
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
85
|
+
* If not set, it will be created.
|
|
86
|
+
*/
|
|
87
|
+
this.identifier = createID('mg-button');
|
|
88
|
+
/**
|
|
89
|
+
* Disable button
|
|
90
|
+
*/
|
|
91
|
+
this.disabled = false;
|
|
92
|
+
/**
|
|
93
|
+
* Define if button is round.
|
|
94
|
+
* Used for icon button.
|
|
95
|
+
*/
|
|
96
|
+
this.isIcon = false;
|
|
97
|
+
/**
|
|
98
|
+
* Option to set input disable on click, in order to prevent multi-click.
|
|
99
|
+
* Parent component have to remove the attribute 'disabled' when the process ends.
|
|
100
|
+
*/
|
|
101
|
+
this.disableOnClick = false;
|
|
102
|
+
/**
|
|
103
|
+
* Prop to set aria-expanded on button element
|
|
104
|
+
*/
|
|
105
|
+
this.expanded = false;
|
|
106
|
+
/**
|
|
107
|
+
* Option to set aria-haspopup
|
|
108
|
+
* The aria-haspopup state informs assistive technology users that there is a popup and the type of popup it is, but provides no interactivity.
|
|
109
|
+
*/
|
|
110
|
+
this.haspopup = false;
|
|
111
|
+
/**
|
|
112
|
+
* Define if button is loading, default to false.
|
|
113
|
+
* Trigger when button is clicked or key-up ['enter', 'space], then value change to true.
|
|
114
|
+
* It's required to reset to false when action/promise in parent is done to stop the loading state
|
|
115
|
+
*/
|
|
116
|
+
this.loading = false;
|
|
117
|
+
/**
|
|
118
|
+
* Component classes
|
|
119
|
+
*/
|
|
120
|
+
this.classList = new ClassList(['mg-button']);
|
|
121
|
+
/**
|
|
122
|
+
* Trigger actions onClick event
|
|
123
|
+
*
|
|
124
|
+
* @param {MouseEvent} event click event
|
|
125
|
+
* @returns {void}
|
|
126
|
+
*/
|
|
127
|
+
this.handleClick = (event) => {
|
|
128
|
+
if (this.disabled)
|
|
129
|
+
event.stopPropagation();
|
|
130
|
+
// Used to prevent multi-click.
|
|
131
|
+
if (this.disableOnClick && !this.disabled) {
|
|
132
|
+
this.loading = true;
|
|
133
|
+
this.disabled = true;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
validateVariant(newValue) {
|
|
138
|
+
if (!variants$3.includes(newValue)) {
|
|
139
|
+
throw new Error(`<mg-button> prop "variant" must be one of : ${variants$3.join(', ')}`);
|
|
140
|
+
}
|
|
141
|
+
this.classList.add(`mg-button--${this.variant}`);
|
|
142
|
+
}
|
|
143
|
+
disabledHandler(isDisabled) {
|
|
144
|
+
// Remove loading when enable
|
|
145
|
+
// Will be set back onclick
|
|
146
|
+
if (!isDisabled && this.disableOnClick) {
|
|
147
|
+
this.loading = false;
|
|
148
|
+
}
|
|
149
|
+
// Manage if onclick
|
|
150
|
+
this.element.onclick = isDisabled ? undefined : this.onClickElementFn;
|
|
151
|
+
}
|
|
152
|
+
loadingHandler(newValue) {
|
|
153
|
+
// we add loading style if it newvalue is true else we remove it
|
|
154
|
+
if (newValue) {
|
|
155
|
+
this.classList.add('mg-button--loading');
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
this.classList.delete('mg-button--loading');
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Check if props are well configured on init
|
|
163
|
+
*
|
|
164
|
+
* @returns {void}
|
|
165
|
+
*/
|
|
166
|
+
componentWillLoad() {
|
|
167
|
+
this.validateVariant(this.variant);
|
|
168
|
+
if (this.isIcon) {
|
|
169
|
+
this.classList.add(`mg-button--icon`);
|
|
170
|
+
if (typeof this.label !== 'string' || this.label === '') {
|
|
171
|
+
throw new Error(`<mg-button> prop "label" is mandatory when prop "isIcon" is set to true.`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// Store the onclick fn
|
|
175
|
+
this.onClickElementFn = this.element.onclick;
|
|
176
|
+
this.disabledHandler(this.disabled);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Render component
|
|
180
|
+
*
|
|
181
|
+
* @returns {HTMLElement} html element
|
|
182
|
+
*/
|
|
183
|
+
render() {
|
|
184
|
+
return (h("button", { id: this.identifier, class: this.classList.join(), "aria-label": this.label, "aria-disabled": this.disabled, "aria-expanded": this.expanded, "aria-controls": this.controls, "aria-haspopup": this.haspopup, onClick: this.handleClick }, this.loading && h("mg-icon", { icon: "loader", spin: true }), h("div", { class: "mg-button__content" }, h("slot", null))));
|
|
185
|
+
}
|
|
186
|
+
get element() { return getElement(this); }
|
|
187
|
+
static get watchers() { return {
|
|
188
|
+
"variant": ["validateVariant"],
|
|
189
|
+
"disabled": ["disabledHandler"],
|
|
190
|
+
"loading": ["loadingHandler"]
|
|
191
|
+
}; }
|
|
192
|
+
};
|
|
193
|
+
MgButton.style = mgButtonCss;
|
|
194
|
+
|
|
195
|
+
const mgCharacterLeftCss = "mg-character-left.sc-mg-character-left{display:block}";
|
|
196
|
+
|
|
197
|
+
const MgCharacterLeft = class {
|
|
198
|
+
constructor(hostRef) {
|
|
199
|
+
registerInstance(this, hostRef);
|
|
200
|
+
/************
|
|
201
|
+
* Internal *
|
|
202
|
+
************/
|
|
203
|
+
this.mustacheCounter = '{counter}';
|
|
204
|
+
/**
|
|
205
|
+
* Template to display remaining characters.
|
|
206
|
+
* Must have {counter} inside
|
|
207
|
+
*/
|
|
208
|
+
this.template = messages.nbCharLeft;
|
|
209
|
+
/**
|
|
210
|
+
* Sets the characters to count
|
|
211
|
+
*/
|
|
212
|
+
this.characters = '';
|
|
213
|
+
/**
|
|
214
|
+
* Calculate number character left
|
|
215
|
+
*
|
|
216
|
+
* @returns {string} message
|
|
217
|
+
*/
|
|
218
|
+
this.getMessage = () => {
|
|
219
|
+
return this.template.replace(this.mustacheCounter, `<strong>${this.maxlength - this.characters.length}</strong>`);
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
validateTemplate(newValue) {
|
|
223
|
+
if (typeof newValue !== 'string' || newValue === '' || newValue.indexOf(this.mustacheCounter) === -1) {
|
|
224
|
+
throw new Error(`<mg-character-left> prop "template" must contain "${this.mustacheCounter}".`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
validateMaxlength(newValue) {
|
|
228
|
+
if (typeof newValue !== 'number') {
|
|
229
|
+
throw new Error('<mg-character-left> prop "maxlength" is required.');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/*************
|
|
233
|
+
* Lifecycle *
|
|
234
|
+
*************/
|
|
235
|
+
/**
|
|
236
|
+
* Check if props are well configured on init
|
|
237
|
+
*
|
|
238
|
+
* @returns {void}
|
|
239
|
+
*/
|
|
240
|
+
componentWillLoad() {
|
|
241
|
+
this.validateTemplate(this.template);
|
|
242
|
+
this.validateMaxlength(this.maxlength);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Render component
|
|
246
|
+
*
|
|
247
|
+
* @returns {HTMLElement} HTML Element
|
|
248
|
+
*/
|
|
249
|
+
render() {
|
|
250
|
+
return h("span", { id: this.identifier, innerHTML: this.getMessage(), "aria-live": "polite" });
|
|
251
|
+
}
|
|
252
|
+
static get watchers() { return {
|
|
253
|
+
"template": ["validateTemplate"],
|
|
254
|
+
"maxlength": ["validateMaxlength"]
|
|
255
|
+
}; }
|
|
256
|
+
};
|
|
257
|
+
MgCharacterLeft.style = mgCharacterLeftCss;
|
|
258
|
+
|
|
259
|
+
const mgFormCss = ".is-asterisk{color:hsl(var(--color-danger))}.mg-form,.mg-form-group{--mg-inputs-margin-bottom:1.5rem;--mg-inputs-title-horizontal-space:3rem;--mg-inputs-title-width:15rem;--mg-inputs-shrink:0}.mg-form.mg-form--all-required,.mg-form-group.mg-form--all-required{--mg-input-title-display:none}";
|
|
260
|
+
|
|
261
|
+
const MgForm = class {
|
|
262
|
+
constructor(hostRef) {
|
|
263
|
+
registerInstance(this, hostRef);
|
|
264
|
+
this.formValid = createEvent(this, "form-valid", 7);
|
|
265
|
+
/**
|
|
266
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
267
|
+
* If not set, it will be created.
|
|
268
|
+
*/
|
|
269
|
+
this.identifier = createID('mg-form');
|
|
270
|
+
/**
|
|
271
|
+
* Input name
|
|
272
|
+
* If not set the value equals the identifier
|
|
273
|
+
*/
|
|
274
|
+
this.name = this.identifier;
|
|
275
|
+
/**
|
|
276
|
+
* Define if form is readonly
|
|
277
|
+
*/
|
|
278
|
+
this.readonly = false;
|
|
279
|
+
/**
|
|
280
|
+
* Define if form is disabled
|
|
281
|
+
*/
|
|
282
|
+
this.disabled = false;
|
|
283
|
+
/**
|
|
284
|
+
* Component classes
|
|
285
|
+
*/
|
|
286
|
+
this.classList = new ClassList(['mg-form']);
|
|
287
|
+
/**
|
|
288
|
+
* Define required message based on mg-inputs required elements
|
|
289
|
+
* Also
|
|
290
|
+
*
|
|
291
|
+
* @returns {void}
|
|
292
|
+
*/
|
|
293
|
+
this.setRequiredMessage = () => {
|
|
294
|
+
// Get required fields
|
|
295
|
+
const requiredInputs = this.mgInputs.filter(input => input.required && !input.disabled && !this.disabled);
|
|
296
|
+
// All fields are required
|
|
297
|
+
// mg-input-toggle can not be required
|
|
298
|
+
if (requiredInputs.length > 0 && requiredInputs.length === this.mgInputs.filter(input => input.nodeName !== 'MG-INPUT-TOGGLE').length) {
|
|
299
|
+
this.requiredMessage = messages.form.allRequired;
|
|
300
|
+
this.classList.add('mg-form--all-required');
|
|
301
|
+
}
|
|
302
|
+
// Some fields are required
|
|
303
|
+
else if (requiredInputs.length > 0) {
|
|
304
|
+
this.requiredMessage = messages.form.required;
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* Check if form is valid
|
|
309
|
+
*
|
|
310
|
+
* @returns {void}
|
|
311
|
+
*/
|
|
312
|
+
this.checkValidity = () => {
|
|
313
|
+
const validity = !this.mgInputs.some(input => input.invalid);
|
|
314
|
+
this.valid = validity;
|
|
315
|
+
this.invalid = !validity;
|
|
316
|
+
this.formValid.emit(validity);
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Public method to display errors
|
|
321
|
+
*
|
|
322
|
+
* @returns {Promise<void>}
|
|
323
|
+
*/
|
|
324
|
+
async displayError() {
|
|
325
|
+
if (!this.readonly) {
|
|
326
|
+
this.mgInputs.forEach(input => {
|
|
327
|
+
input.displayError && input.displayError();
|
|
328
|
+
});
|
|
329
|
+
this.checkValidity();
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
/*************
|
|
333
|
+
* Lifecycle *
|
|
334
|
+
*************/
|
|
335
|
+
/**
|
|
336
|
+
* Check if component props are well configured on init
|
|
337
|
+
*
|
|
338
|
+
* @returns {void}
|
|
339
|
+
*/
|
|
340
|
+
componentWillLoad() {
|
|
341
|
+
// Get slotted mgIputs
|
|
342
|
+
this.mgInputs = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-INPUT-'));
|
|
343
|
+
// Define required message
|
|
344
|
+
this.setRequiredMessage();
|
|
345
|
+
// Check validity when slotted mgImputs are ready
|
|
346
|
+
Promise.all(this.mgInputs.map(async (input) => {
|
|
347
|
+
// Set inputs readonly or disabled based on form configuration
|
|
348
|
+
// Othewise listen to events
|
|
349
|
+
if (this.readonly)
|
|
350
|
+
input.readonly = true;
|
|
351
|
+
else if (this.disabled)
|
|
352
|
+
input.disabled = true;
|
|
353
|
+
else
|
|
354
|
+
input.addEventListener('input-valid', this.checkValidity);
|
|
355
|
+
await input.componentOnReady();
|
|
356
|
+
})).then(() => {
|
|
357
|
+
this.checkValidity();
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Render
|
|
362
|
+
*
|
|
363
|
+
* @returns {HTMLElement} HTML Element
|
|
364
|
+
*/
|
|
365
|
+
render() {
|
|
366
|
+
return (h("form", { class: this.classList.join(), id: this.identifier, name: this.name }, this.requiredMessage && h("p", { innerHTML: this.requiredMessage }), h("slot", null), !this.readonly && !this.disabled && h("slot", { name: "actions" })));
|
|
367
|
+
}
|
|
368
|
+
get element() { return getElement(this); }
|
|
369
|
+
};
|
|
370
|
+
MgForm.style = mgFormCss;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Icon SVG paths
|
|
374
|
+
*/
|
|
375
|
+
const icons = {
|
|
376
|
+
'arrow-down': () => (h("path", { fill: "currentColor", d: "M13,10.1H10.23a.31.31,0,0,1-.32-.28h0V.94A.3.3,0,0,0,9.59.65H6.37A.32.32,0,0,0,6,.94H6V9.81a.29.29,0,0,1-.31.29H3a.3.3,0,0,0-.31.29.27.27,0,0,0,.08.22l5.06,4.58a.36.36,0,0,0,.46,0l5-4.58a.29.29,0,0,0,0-.42C13.22,10.1,13.12,10.1,13,10.1Z" })),
|
|
377
|
+
'arrow-left': () => (h("path", { fill: "currentColor", d: "M5.88,12.93V10.18a.3.3,0,0,1,.28-.32H15a.31.31,0,0,0,.29-.33h0V6.32A.31.31,0,0,0,15,6H6.17a.32.32,0,0,1-.29-.31h0V2.93a.3.3,0,0,0-.28-.32.32.32,0,0,0-.23.09L.79,7.76a.36.36,0,0,0,0,.46l4.58,5a.31.31,0,0,0,.43,0A.4.4,0,0,0,5.88,12.93Z" })),
|
|
378
|
+
'arrow-right': () => (h("path", { fill: "currentColor", d: "M10.16,3V5.75a.3.3,0,0,1-.28.32H1a.31.31,0,0,0-.29.33h0V9.61A.31.31,0,0,0,1,9.94H9.87a.29.29,0,0,1,.29.31h0V13a.3.3,0,0,0,.28.32.32.32,0,0,0,.23-.09l4.58-5.06a.36.36,0,0,0,0-.46l-4.58-5a.3.3,0,0,0-.42,0C10.16,2.76,10.16,2.87,10.16,3Z" })),
|
|
379
|
+
'arrow-up': () => (h("path", { fill: "currentColor", d: "M3.06,5.82H5.81a.31.31,0,0,1,.32.28h0V15a.31.31,0,0,0,.33.29H9.67A.3.3,0,0,0,10,15h0V6.11a.3.3,0,0,1,.31-.29h2.75a.3.3,0,0,0,.23-.51L8.23.73a.36.36,0,0,0-.46,0l-5,4.58a.3.3,0,0,0,0,.43C2.82,5.83,2.92,5.82,3.06,5.82Z" })),
|
|
380
|
+
'arrow-up-right-square': () => (h("path", { fill: "currentColor", d: "M14.33 3v10A1.34 1.34 0 0 1 13 14.33H3A1.34 1.34 0 0 1 1.67 13V3A1.34 1.34 0 0 1 3 1.67h10A1.34 1.34 0 0 1 14.33 3Zm-2.48.46H8.68a.67.67 0 0 0-.68.7.63.63 0 0 0 .2.47l.91.91-5.53 5.53a.33.33 0 0 0 0 .48l.87.87a.33.33 0 0 0 .48 0l5.53-5.52.91.9a.69.69 0 0 0 1 0 .71.71 0 0 0 .19-.48V4.15a.67.67 0 0 0-.67-.67Z" })),
|
|
381
|
+
'arrows-rotate': () => (h("path", { fill: "currentColor", d: "M2.3,7h3.4c0.3,0,0.6-0.3,0.6-0.6c0-0.1-0.1-0.3-0.2-0.4L5.1,4.9c1.7-1.6,4.4-1.5,6,0.2c0,0,0,0,0,0 c0.5,0.5,0.8,1.2,1,1.9h2.1C13.7,3.5,10.4,1.2,7,1.8C5.7,2,4.6,2.6,3.6,3.4L2.7,2.5c-0.2-0.2-0.6-0.2-0.8,0c0,0,0,0,0,0l0,0 C1.8,2.6,1.7,2.8,1.7,2.9v3.4C1.7,6.7,1.9,7,2.3,7z M13.7,9h-3.4C9.9,9,9.7,9.3,9.7,9.6c0,0.2,0.1,0.3,0.2,0.4l1.1,1.1 c-1.7,1.6-4.4,1.5-6-0.2C4.4,10.4,4,9.7,3.8,9H1.7c0.6,3.5,3.9,5.8,7.3,5.2c1.3-0.2,2.4-0.8,3.3-1.7l0.9,0.9c0.2,0.2,0.6,0.2,0.8,0 c0,0,0,0,0,0l0,0c0.1-0.1,0.2-0.3,0.2-0.4V9.6C14.3,9.3,14.1,9,13.7,9z" })),
|
|
382
|
+
'ban': () => (h("path", { fill: "currentColor", d: "M8 .67A7.33 7.33 0 1 0 15.33 8 7.33 7.33 0 0 0 8 .67Zm3.85 3.48a5.46 5.46 0 0 1 .61 7L4.88 3.54a5.46 5.46 0 0 1 6.97.61Zm-7.7 7.7a5.45 5.45 0 0 1-.61-7l7.58 7.58a5.46 5.46 0 0 1-7-.61Z" })),
|
|
383
|
+
'calculator': () => (h("path", { fill: "currentColor", d: "M12.83.67H3.17a.5.5 0 0 0-.5.5v13.66a.5.5 0 0 0 .5.5h9.66a.5.5 0 0 0 .5-.5V1.17a.5.5 0 0 0-.5-.5ZM5.58 13.39a.29.29 0 0 1-.28.3H4.1a.29.29 0 0 1-.3-.28v-1.2a.29.29 0 0 1 .28-.3h1.2a.29.29 0 0 1 .3.28v1.2Zm0-3.28a.29.29 0 0 1-.3.3H4.1a.29.29 0 0 1-.3-.3V8.93a.29.29 0 0 1 .28-.3h1.2a.29.29 0 0 1 .3.28v1.2Zm3.29 3.28a.29.29 0 0 1-.3.3H7.38a.29.29 0 0 1-.3-.3v-1.18a.29.29 0 0 1 .3-.3h1.19a.29.29 0 0 1 .3.3Zm0-3.28a.32.32 0 0 1-.3.3H7.38a.32.32 0 0 1-.3-.3V8.93a.29.29 0 0 1 .3-.3h1.19a.29.29 0 0 1 .3.3Zm3.33 3.28a.29.29 0 0 1-.28.3h-1.25a.29.29 0 0 1-.3-.28V8.93a.29.29 0 0 1 .28-.3h1.25a.29.29 0 0 1 .3.28v4.48Zm0-7.15a.29.29 0 0 1-.3.3H4.1a.29.29 0 0 1-.3-.3V2.61a.29.29 0 0 1 .28-.3h7.82a.29.29 0 0 1 .3.28v3.65Z" })),
|
|
384
|
+
'check': () => (h("path", { fill: "currentColor", d: "M15.3,4.2L14.2,3c-0.1-0.1-0.3-0.1-0.4,0L6,10.4l-3.8-4C2.2,6.3,2.1,6.3,2,6.4L0.7,7.6c-0.1,0.1-0.1,0.2,0,0.3l5.1,5.4c0.1,0.1,0.2,0.1,0.3,0c0,0,0,0,0,0L7.4,12l0,0l7.9-7.4C15.4,4.5,15.4,4.3,15.3,4.2C15.3,4.2,15.3,4.2,15.3,4.2z" })),
|
|
385
|
+
'check-circle': () => (h("path", { fill: "currentColor", d: "M15.33 8A7.33 7.33 0 1 1 8 .67 7.33 7.33 0 0 1 15.33 8Zm-8.18 3.88 5.44-5.44a.46.46 0 0 0 0-.65l-.67-.67a.48.48 0 0 0-.67 0L6.82 9.54 4.75 7.47a.46.46 0 0 0-.65 0l-.67.67a.46.46 0 0 0 0 .65l3.07 3.07a.46.46 0 0 0 .65 0Z" })),
|
|
386
|
+
'chevron-down': () => (h("path", { fill: "currentColor", d: "M7.43,12.21.9,5.69a.81.81,0,0,1,0-1.14h0l.76-.77a.81.81,0,0,1,1.14,0L8,9l5.2-5.18a.81.81,0,0,1,1.14,0l.76.77a.8.8,0,0,1,0,1.13h0L8.57,12.21a.79.79,0,0,1-1.13,0Z" })),
|
|
387
|
+
'chevron-left': () => (h("path", { fill: "currentColor", d: "M3.79,7.43,10.31.9a.81.81,0,0,1,1.14,0h0l.77.76a.81.81,0,0,1,0,1.14L7,8l5.18,5.2a.81.81,0,0,1,0,1.14l-.77.76a.8.8,0,0,1-1.13,0h0L3.79,8.57a.79.79,0,0,1,0-1.13Z" })),
|
|
388
|
+
'chevron-right': () => (h("path", { fill: "currentColor", d: "M12.21,8.57,5.69,15.1a.81.81,0,0,1-1.14,0h0l-.77-.76a.81.81,0,0,1,0-1.14L9,8,3.78,2.8a.81.81,0,0,1,0-1.14L4.55.9A.8.8,0,0,1,5.68.9h0l6.53,6.53a.79.79,0,0,1,0,1.13Z" })),
|
|
389
|
+
'chevron-up': () => (h("path", { fill: "currentColor", d: "M8.57,3.79l6.53,6.52a.81.81,0,0,1,0,1.14h0l-.76.77a.81.81,0,0,1-1.14,0L8,7,2.8,12.22a.81.81,0,0,1-1.14,0L.9,11.45a.8.8,0,0,1,0-1.13h0L7.43,3.79a.79.79,0,0,1,1.13,0Z" })),
|
|
390
|
+
'cross': () => (h("path", { fill: "currentColor", d: "M14.26 12.74 9.52 8l4.7-4.7a.29.29 0 0 0 0-.41l-1.1-1.1a.29.29 0 0 0-.41 0L8 6.48 3.26 1.74a.24.24 0 0 0-.34 0L1.74 2.91a.24.24 0 0 0 0 .34L6.48 8l-4.7 4.7a.29.29 0 0 0 0 .41l1.1 1.1a.29.29 0 0 0 .41 0L8 9.52l4.74 4.74a.24.24 0 0 0 .34 0l1.17-1.17a.24.24 0 0 0 0-.34Z" })),
|
|
391
|
+
'cross-circle': () => (h("path", { fill: "currentColor", d: "M8.06.67H8A7.33 7.33 0 0 0 .68 8v.1a7.42 7.42 0 0 0 7.23 7.23A7.33 7.33 0 1 0 8.06.67Zm3.6 9.57a.28.28 0 0 1 0 .4l-.19.2-.61.61-.2.19a.27.27 0 0 1-.39 0L8 9.41l-2.23 2.24a.27.27 0 0 1-.39 0l-.2-.2-.6-.6-.19-.2a.28.28 0 0 1 0-.4L6.6 8 4.36 5.76a.28.28 0 0 1 0-.4l1-1a.28.28 0 0 1 .4 0L8 6.59l2.24-2.24a.28.28 0 0 1 .4 0l.2.2.6.6.2.2a.28.28 0 0 1 0 .4L9.42 8Z" })),
|
|
392
|
+
'download': () => (h("path", { fill: "currentColor", d: "M6.44,2V6.09a.31.31,0,0,1-.31.31H4a.31.31,0,0,0-.31.29.33.33,0,0,0,.1.23l4,4a.29.29,0,0,0,.41,0h0l4-4a.3.3,0,0,0,0-.42A.29.29,0,0,0,12,6.4H9.91a.31.31,0,0,1-.31-.31h0V2a.29.29,0,0,0-.28-.3H6.74a.29.29,0,0,0-.3.28ZM1.69,13v1a.29.29,0,0,0,.29.29H14a.29.29,0,0,0,.29-.29V13a.29.29,0,0,0-.28-.3H2a.29.29,0,0,0-.33.25Z" })),
|
|
393
|
+
'exclamation-circle': () => (h("path", { fill: "currentColor", d: "M8 15.33A7.33 7.33 0 1 0 .67 8 7.33 7.33 0 0 0 8 15.33ZM7 4a.29.29 0 0 1 .3-.3h1.35A.29.29 0 0 1 9 4v4.68a.29.29 0 0 1-.28.3H7.35a.29.29 0 0 1-.3-.28Zm0 6.78a.29.29 0 0 1 .3-.3h1.35a.29.29 0 0 1 .3.3H9V12a.29.29 0 0 1-.28.3H7.35a.29.29 0 0 1-.3-.28Z" })),
|
|
394
|
+
'exclamation-triangle': () => (h("path", { fill: "currentColor", d: "m14.28 13.87-6-12a.32.32 0 0 0-.41-.15.36.36 0 0 0-.15.15l-6 12a.31.31 0 0 0 .14.42.33.33 0 0 0 .14 0h12a.3.3 0 0 0 .33-.28.31.31 0 0 0-.05-.14ZM7 6a.29.29 0 0 1 .28-.28h1.44A.28.28 0 0 1 9 6v4a.28.28 0 0 1-.28.29H7.28A.29.29 0 0 1 7 10Zm2 7a.31.31 0 0 1-.3.32H7.32A.32.32 0 0 1 7 13v-1.38a.31.31 0 0 1 .31-.31h1.4a.31.31 0 0 1 .31.31H9Z" })),
|
|
395
|
+
'file-cog': () => (h("path", { fill: "currentColor", d: "M9,10.1C9,10.6,8.5,11,8,11l0,0c-0.6,0-1-0.4-1-1c0-0.6,0.4-1,1-1C8.6,9,9,9.4,9,10.1C9,10,9,10,9,10.1z M13.2,3.7l-2.8-2.8c-0.1-0.1-0.3-0.2-0.5-0.2H9.8v3.7h3.5V4.2C13.3,4,13.2,3.8,13.2,3.7L13.2,3.7z M9.6,5.3h3.8v9.4 c0,0.4-0.3,0.6-0.7,0.7H3.3c-0.4,0-0.7-0.3-0.7-0.7c0,0,0,0,0,0V1.3C2.7,1,3,0.7,3.3,0.7h5.5v3.9l0,0C8.9,4.9,9.2,5.2,9.6,5.3 C9.5,5.2,9.5,5.2,9.6,5.3z M10,8L9.5,8.3C9.3,8.1,9,8,8.8,7.9V7.3c0-0.1,0-0.1-0.1-0.1c-0.4-0.1-0.9-0.1-1.3,0 c-0.1,0-0.1,0.1-0.1,0.1v0.6C7,8,6.7,8.1,6.5,8.3L6,8C5.9,8,5.9,8,5.8,8C5.5,8.3,5.3,8.7,5.2,9.1c0,0.1,0,0.1,0.1,0.2l0.5,0.3 c-0.1,0.3-0.1,0.6,0,0.8l-0.5,0.3c-0.1,0-0.1,0.1-0.1,0.2c0.1,0.4,0.4,0.8,0.7,1.1c0.1,0,0.1,0,0.2,0l0.5-0.3 C6.7,11.9,7,12,7.2,12.1v0.6c0,0.1,0,0.1,0.1,0.1c0.4,0.1,0.9,0.1,1.3,0c0.1,0,0.1-0.1,0.1-0.1v-0.5C9,12.1,9.3,12,9.5,11.8l0.5,0.3 c0.1,0,0.1,0,0.2,0c0.3-0.3,0.5-0.7,0.6-1.1c0-0.1,0-0.1-0.1-0.2l0,0l-0.5-0.3c0-0.3,0-0.6,0-0.8l0.5-0.3c0.1,0,0.1-0.1,0.1-0.2 c-0.1-0.4-0.4-0.8-0.6-1.1C10.1,8,10.1,8,10,8z" })),
|
|
396
|
+
'file-text': () => (h("path", { fill: "currentColor", d: "M8.9 4.6V.7H3.3c-.3 0-.6.3-.6.6v13.3c0 .4.3.7.7.7h9.3c.4 0 .7-.3.7-.7V5.3H9.6c-.4-.1-.7-.4-.7-.7zm1.8 6.7c0 .2-.2.3-.3.4H5.7c-.2 0-.3-.2-.3-.4v-.2c0-.2.2-.3.3-.3h4.6c.2 0 .3.2.3.3v.2zm0-1.8c0 .2-.2.3-.3.3H5.7c-.2 0-.3-.2-.3-.3v-.2c0-.2.2-.3.3-.3h4.6c.2 0 .3.2.3.3v.2zm0-2.1v.2c0 .2-.2.3-.3.3H5.7c-.2.1-.4-.1-.4-.2v-.3c0-.2.2-.3.3-.3h4.6c.3 0 .5.1.5.3zm2.6-3.2v.2H9.8V.7h.2c.2 0 .3.1.5.2l2.7 2.8c0 .1.1.3.1.5z" })),
|
|
397
|
+
'file-upload': () => [
|
|
398
|
+
h("path", { fill: "currentColor", d: "M13.1 3.7 10.4.9c-.1-.1-.3-.2-.5-.2h-.1v3.7h3.5v-.2c0-.2-.1-.4-.2-.5z" }),
|
|
399
|
+
h("path", { fill: "currentColor", d: "M13.3 14.6V5.3H9.6c-.4 0-.7-.3-.7-.7V.7H3.3c-.3 0-.6.3-.6.6v13.3c0 .4.3.7.7.7h9.3c.3 0 .6-.3.6-.7zm-3-4.6H8.9c-.1 0-.2.1-.2.2v2.6c0 .1-.1.2-.2.2H6.9c-.1 0-.2-.1-.2-.2v-2.6c0-.1-.1-.2-.2-.2H5.1C5 9.9 5 9.8 5 9.7l2.5-2.6c.1-.1.2-.1.3 0l2.5 2.5.1.1c.1.2 0 .3-.1.3z" }),
|
|
400
|
+
],
|
|
401
|
+
'floppy-disk': () => (h("path", { fill: "currentColor", d: "m13.94 4.44-2.38-2.38a1.39 1.39 0 0 0-1-.39H3A1.35 1.35 0 0 0 1.67 3v10A1.35 1.35 0 0 0 3 14.33h10A1.35 1.35 0 0 0 14.33 13V5.4a1.39 1.39 0 0 0-.39-1ZM8 12.52a1.81 1.81 0 1 1 1.81-1.81A1.81 1.81 0 0 1 8 12.52Zm2.71-8.6v2.84a.34.34 0 0 1-.34.34H3.82a.34.34 0 0 1-.34-.34V3.82a.34.34 0 0 1 .34-.34h6.46a.35.35 0 0 1 .24.1l.1.1a.35.35 0 0 1 .1.24Z" })),
|
|
402
|
+
'info-circle': () => (h("path", { fill: "currentColor", d: "M8 .67A7.33 7.33 0 1 0 15.33 8 7.33 7.33 0 0 0 8 .67ZM9 12a.29.29 0 0 1-.3.3H7.35a.29.29 0 0 1-.3-.3V7.32A.29.29 0 0 1 7.33 7h1.32a.29.29 0 0 1 .35.3Zm0-6.74a.29.29 0 0 1-.3.3H7.35a.29.29 0 0 1-.3-.3V4a.29.29 0 0 1 .28-.3h1.32a.29.29 0 0 1 .3.28V4Z" })),
|
|
403
|
+
'loader': () => [
|
|
404
|
+
h("path", { fill: "currentColor", class: "loader__full-circle", d: "M8 2.67A5.33 5.33 0 1 1 2.67 8 5.33 5.33 0 0 1 8 2.67m0-2A7.33 7.33 0 1 0 15.33 8 7.33 7.33 0 0 0 8 .67Z" }),
|
|
405
|
+
h("path", { fill: "currentColor", d: "M8 2.67v-2A7.33 7.33 0 0 0 .67 8h2A5.33 5.33 0 0 1 8 2.67Z" }),
|
|
406
|
+
],
|
|
407
|
+
'log-in': () => (h("path", { fill: "currentColor", d: "M10.97,7.78h0L6.97,3.78c-.12-.12-.31-.12-.42,0h0c-.07,.06-.12,.15-.13,.24v2.07c0,.17-.13,.3-.3,.32H1.97c-.16,0-.29,.12-.3,.28h0v2.58c0,.16,.12,.29,.28,.3H6.11c.17,0,.3,.14,.3,.31v2.14c0,.16,.12,.29,.28,.3h0c.11,.01,.21-.03,.28-.11l4-4c.11-.12,.11-.3,0-.42Zm3.37,5.26h0v1c0,.16-.13,.28-.28,.28h-4.77c-.16,0-.28-.13-.28-.28v-1c0-.16,.13-.28,.28-.28h3.43V3.3h-3.42c-.16,0-.29-.13-.29-.29V1.97c0-.16,.13-.29,.29-.29h4.76c.16,0,.29,.13,.29,.29v.68h0V13.04Z" })),
|
|
408
|
+
'log-out': () => [
|
|
409
|
+
h("path", { fill: "currentColor", d: "M14.25,7.77h0l-4-4a.31.31,0,0,0-.43,0A.34.34,0,0,0,9.7,4V6.07a.32.32,0,0,1-.3.32H5.23a.3.3,0,0,0-.3.3V9.25a.3.3,0,0,0,.3.3H9.4a.31.31,0,0,1,.3.31V12a.3.3,0,0,0,.3.3.33.33,0,0,0,.23-.09l4-4A.29.29,0,0,0,14.25,7.77Z" }),
|
|
410
|
+
h("path", { fill: "currentColor", d: "M6.71,12.72H3.27V3.26H6.69A.31.31,0,0,0,7,3V2a.3.3,0,0,0-.31-.3H2A.29.29,0,0,0,1.67,2h0V3h0V14a.27.27,0,0,0,.1.24h0a.32.32,0,0,0,.14.08H6.71A.3.3,0,0,0,7,14V13A.3.3,0,0,0,6.71,12.72Z" }),
|
|
411
|
+
],
|
|
412
|
+
'magnifying-glass': () => (h("path", { fill: "currentColor", d: "M11.24,9.52A5.17,5.17,0,0,0,9.51,2.41l-.17-.09A5.18,5.18,0,0,0,4,11.18a5.16,5.16,0,0,0,5.54.11L12.3,14a1,1,0,0,0,1.41,0l.33-.33a1,1,0,0,0,0-1.41Zm-4.4.5A3.19,3.19,0,1,1,10,6.8v.06A3.19,3.19,0,0,1,6.84,10Z" })),
|
|
413
|
+
'paper-plane': () => (h("path", { fill: "currentColor", d: "M14 1.69 1.84 7a.28.28 0 0 0-.15.36.29.29 0 0 0 .16.15l3.27 1.82a.57.57 0 0 0 .61-.06l6.45-5.57c.05 0 .15-.1.19-.06s0 .14-.06.18l-5.59 6.29a.52.52 0 0 0 0 .63l2.09 3.44a.28.28 0 0 0 .37.12.3.3 0 0 0 .13-.12l5-12.11a.3.3 0 0 0-.14-.37.28.28 0 0 0-.17-.01Z" })),
|
|
414
|
+
'paper-plane-slash': () => (h("path", { fill: "currentColor", d: "M2.67,1.69,14.26,13.28l-1,1-2.79-2.8-1.1,2.67a.3.3,0,0,1-.13.12.28.28,0,0,1-.37-.12L6.75,10.74a.52.52,0,0,1,0-.63L7.82,8.9l-.76-.76L5.76,9.27a.57.57,0,0,1-.61.06L1.88,7.51a.29.29,0,0,1-.16-.15A.28.28,0,0,1,1.87,7L4.68,5.76l-3-3Zm11.53,0a.28.28,0,0,0-.22,0L7.53,4.51,9.26,6.24l3-2.54s.15-.1.19-.06,0,.14-.06.18L9.75,6.73l1.88,1.88,2.71-6.54A.3.3,0,0,0,14.2,1.7Z" })),
|
|
415
|
+
'pen': () => (h("path", { fill: "currentColor", d: "M1.67,11.69v2.64h2.64l7.78-7.78-2.64-2.64L1.67,11.69ZM14.13,4.51c.27-.28,.27-.72,0-1h0l-1.65-1.64c-.28-.27-.72-.27-1,0h0l-1.28,1.29,2.64,2.64,1.29-1.29Z" })),
|
|
416
|
+
'pen-fancy': () => (h("path", { fill: "currentColor", d: "M3.63,8.65c-.24,.07-.43,.26-.5,.5l-1.46,4.37,.11,.12,2.3-2.3c0-.06,0-.13,0-.19,0-.44,.35-.8,.79-.81,.44,0,.8,.35,.81,.79,0,.44-.35,.8-.79,.81,0,0-.01,0-.02,0h-.19l-2.3,2.3,.12,.11,4.37-1.46c.24-.07,.43-.26,.5-.5l.82-2.08-2.49-2.48-2.07,.82ZM10.8,2.35L6.27,7.28l2.42,2.42,4.94-4.52c2.1-1.86-.99-4.92-2.83-2.83Z" })),
|
|
417
|
+
'plus-circle': () => (h("path", { fill: "currentColor", d: "M8,0.7C4,0.7,0.7,4,0.7,8S4,15.3,8,15.3S15.3,12,15.3,8l0,0C15.3,4,12,0.7,8,0.7 C8,0.7,8,0.7,8,0.7z M12.3,8.8c0,0.2-0.2,0.4-0.4,0.4H9.2v2.7c0,0.2-0.2,0.4-0.4,0.4H7.2c-0.2,0-0.4-0.2-0.3-0.4V9.2H4.1 C3.9,9.2,3.7,9,3.7,8.8V7.2c0-0.2,0.2-0.4,0.4-0.3h2.7V4.1c0-0.2,0.2-0.4,0.3-0.4h1.7c0.2,0,0.4,0.2,0.4,0.4v2.7h2.7 c0.2,0,0.4,0.2,0.4,0.3L12.3,8.8z" })),
|
|
418
|
+
'trash': () => [
|
|
419
|
+
h("path", { fill: "currentColor", d: "M11.5,14.8h-7 c-0.6,0-1.1-0.5-1.1-1.1V4.4h9.3v9.2C12.6,14.2,12.1,14.8,11.5,14.8 M6.9,6.8c0-0.3-0.3-0.6-0.6-0.6S5.8,6.5,5.8,6.8v5.2 c0,0.3,0.3,0.6,0.6,0.6s0.6-0.3,0.6-0.6V6.8z M10.3,6.8c0-0.3-0.3-0.6-0.6-0.6S9.2,6.5,9.2,6.8v5.2c0,0.3,0.3,0.6,0.6,0.6 s0.6-0.3,0.6-0.6V6.8z" }),
|
|
420
|
+
h("path", { fill: "currentColor", d: "M13,2h-2.9L9.9,1.6 C9.8,1.4,9.6,1.2,9.4,1.2H6.6c-0.2,0-0.4,0.1-0.5,0.3L5.8,2H2.9C2.7,2,2.5,2.2,2.5,2.4c0,0,0,0,0,0v0.8c0,0.2,0.2,0.4,0.4,0.4H13 c0.2,0,0.4-0.2,0.4-0.4V2.4C13.4,2.2,13.2,2,13,2z" }),
|
|
421
|
+
],
|
|
422
|
+
'user-plus': () => (h("path", { fill: "currentColor", d: "M14,3.33H12.65V2a.36.36,0,0,0-.35-.33h-.65A.36.36,0,0,0,11.3,2V3.33H10a.34.34,0,0,0-.33.34v.66a.34.34,0,0,0,.33.34H11.3V6a.37.37,0,0,0,.35.33h.65A.37.37,0,0,0,12.65,6V4.67H14a.34.34,0,0,0,.32-.34V3.67A.34.34,0,0,0,14,3.33ZM9.28,9.77h-.2a5.19,5.19,0,0,1-3.91,0H5A3,3,0,0,0,1.7,12.46h0v.72A1.27,1.27,0,0,0,3,14.33h8.25a1.26,1.26,0,0,0,1.36-1.14v-.68A3,3,0,0,0,9.37,9.76H9.28ZM7.13,3.7A2.64,2.64,0,1,1,4.5,6.34h0A2.64,2.64,0,0,1,7.13,3.7Z" })),
|
|
423
|
+
'users': () => (h("path", { fill: "currentColor", d: "M12,8.76h-.2a5.24,5.24,0,0,1-3.93,0H7.61a3.05,3.05,0,0,0-3.3,2.75v.69a1.28,1.28,0,0,0,1.38,1.14H14a1.27,1.27,0,0,0,1.37-1.14v-.69A3.07,3.07,0,0,0,12,8.75Zm-6.4-.32A2,2,0,0,0,4.31,8H2.48A1.69,1.69,0,0,0,.65,9.53v.76a.85.85,0,0,0,.91.76H3.45A3.58,3.58,0,0,1,5.61,8.44ZM9.81,2.66A2.65,2.65,0,1,1,7.16,5.31h0A2.65,2.65,0,0,1,9.81,2.66ZM3.31,4.18A1.51,1.51,0,1,1,1.8,5.69,1.51,1.51,0,0,1,3.31,4.18Z" })),
|
|
424
|
+
};
|
|
425
|
+
/**
|
|
426
|
+
* List of all possibles sizes
|
|
427
|
+
*/
|
|
428
|
+
const sizes$1 = ['regular', 'large', 'extra-large'];
|
|
429
|
+
/**
|
|
430
|
+
* List of all possibles variants
|
|
431
|
+
*/
|
|
432
|
+
const variants$2 = ['success', 'warning', 'danger', 'info'];
|
|
433
|
+
|
|
434
|
+
const mgIconCss = ":host{display:-ms-inline-flexbox;display:inline-flex;vertical-align:middle}.mg-icon[size=regular],.mg-icon.mg-icon--size-regular{width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size)}.mg-icon[size=large],.mg-icon.mg-icon--size-large{width:var(--mg-icon-large-size);height:var(--mg-icon-large-size)}.mg-icon[size=extra-large],.mg-icon.mg-icon--size-extra-large{width:var(--mg-icon-extra-large-size);height:var(--mg-icon-extra-large-size)}.mg-icon[class*=mg-icon--variant-]{border-radius:var(--mg-message-border-radius);padding:0.3rem}.mg-icon.mg-icon--variant-success{background-color:hsl(var(--color-success-h), var(--color-success-s), calc(var(--color-success-l) + 20%))}.mg-icon.mg-icon--variant-warning{background-color:hsl(var(--color-warning-h), var(--color-warning-s), calc(var(--color-warning-l) + 20%))}.mg-icon.mg-icon--variant-danger{background-color:hsl(var(--color-danger-h), var(--color-danger-s), calc(var(--color-danger-l) + 20%))}.mg-icon.mg-icon--variant-info{background-color:hsl(var(--color-info-h), var(--color-info-s), calc(var(--color-info-l) + 20%))}.loader__full-circle{opacity:0.2}.mg-icon--spin{-webkit-animation-name:rotate;animation-name:rotate;-webkit-animation-duration:0.75s;animation-duration:0.75s;-webkit-animation-iteration-count:infinite;animation-iteration-count:infinite}@-webkit-keyframes rotate{to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes rotate{to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}";
|
|
435
|
+
|
|
436
|
+
const MgIcon = class {
|
|
437
|
+
constructor(hostRef) {
|
|
438
|
+
registerInstance(this, hostRef);
|
|
439
|
+
/**
|
|
440
|
+
* Define icon size
|
|
441
|
+
*/
|
|
442
|
+
this.size = 'regular';
|
|
443
|
+
/**
|
|
444
|
+
* Make the icon spin
|
|
445
|
+
*/
|
|
446
|
+
this.spin = false;
|
|
447
|
+
/**
|
|
448
|
+
* Component classes
|
|
449
|
+
*/
|
|
450
|
+
this.classList = new ClassList(['mg-icon']);
|
|
451
|
+
/**
|
|
452
|
+
* getIcon
|
|
453
|
+
*
|
|
454
|
+
* @returns {HTMLElement} icon html
|
|
455
|
+
*/
|
|
456
|
+
this.getIcon = () => icons[this.icon]();
|
|
457
|
+
}
|
|
458
|
+
validateIcon(newValue) {
|
|
459
|
+
if (!Object.keys(icons).includes(newValue)) {
|
|
460
|
+
throw new Error(`<mg-icon> prop "icon" must be one of : ${Object.keys(icons).join(', ')}`);
|
|
461
|
+
}
|
|
462
|
+
this.classList.add(`mg-icon--${this.icon}`);
|
|
463
|
+
}
|
|
464
|
+
validateSize(newValue) {
|
|
465
|
+
if (!sizes$1.includes(newValue)) {
|
|
466
|
+
throw new Error(`<mg-icon> prop "size" must be one of : ${sizes$1.join(', ')}`);
|
|
467
|
+
}
|
|
468
|
+
this.classList.add(`mg-icon--size-${this.size}`);
|
|
469
|
+
}
|
|
470
|
+
validateVariant(newValue) {
|
|
471
|
+
if (newValue !== undefined && !variants$2.includes(newValue)) {
|
|
472
|
+
throw new Error(`<mg-icon> prop "variant" must be one of : ${variants$2.join(', ')}`);
|
|
473
|
+
}
|
|
474
|
+
else if (newValue !== undefined) {
|
|
475
|
+
this.classList.add(`mg-icon--variant-${this.variant}`);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
handleSpin(newValue) {
|
|
479
|
+
if (newValue) {
|
|
480
|
+
this.classList.add('mg-icon--spin');
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Check if props are well configured on init
|
|
485
|
+
*
|
|
486
|
+
* @returns {void}
|
|
487
|
+
*/
|
|
488
|
+
componentWillLoad() {
|
|
489
|
+
this.validateIcon(this.icon);
|
|
490
|
+
this.validateSize(this.size);
|
|
491
|
+
this.validateVariant(this.variant);
|
|
492
|
+
this.handleSpin(this.spin);
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Render component
|
|
496
|
+
*
|
|
497
|
+
* @returns {HTMLElement} HTML Element
|
|
498
|
+
*/
|
|
499
|
+
render() {
|
|
500
|
+
return (h("svg", { class: this.classList.join(), "aria-hidden": "true", focusable: "false", viewBox: "0 0 16 16" }, this.getIcon()));
|
|
501
|
+
}
|
|
502
|
+
static get watchers() { return {
|
|
503
|
+
"icon": ["validateIcon"],
|
|
504
|
+
"size": ["validateSize"],
|
|
505
|
+
"variant": ["validateVariant"],
|
|
506
|
+
"spin": ["handleSpin"]
|
|
507
|
+
}; }
|
|
508
|
+
};
|
|
509
|
+
MgIcon.style = mgIconCss;
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Possible input classes
|
|
513
|
+
*/
|
|
514
|
+
var InputClass;
|
|
515
|
+
(function (InputClass) {
|
|
516
|
+
InputClass["ERROR"] = "is-not-valid";
|
|
517
|
+
})(InputClass || (InputClass = {}));
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Apply in all input child node the aria-describedby attribute
|
|
521
|
+
*
|
|
522
|
+
* @param {VNode[]} children Represent scoped elements
|
|
523
|
+
* @param {Set<string>} ariaDescribedbyIDs List of IDs
|
|
524
|
+
* @param {FunctionalUtilities} utils Stencil.js utils
|
|
525
|
+
* @returns {VNode[]} Children with aria-describedby attribute
|
|
526
|
+
*/
|
|
527
|
+
const applyAriadescribedBy = (children, ariaDescribedbyIDs, utils) => utils.map(children, child => {
|
|
528
|
+
if (['input', 'select', 'textarea'].includes(child.vtag)) {
|
|
529
|
+
return Object.assign(Object.assign({}, child), { vattrs: Object.assign(Object.assign({}, child.vattrs), { 'aria-describedby': [...ariaDescribedbyIDs].join(' ') }) });
|
|
530
|
+
}
|
|
531
|
+
// we recursively apply ariadescribedBy attributes to child input nodes if exists
|
|
532
|
+
if (child.vchildren === null)
|
|
533
|
+
return Object.assign({}, child);
|
|
534
|
+
return Object.assign(Object.assign({}, child), { vchildren: applyAriadescribedBy(child.vchildren, ariaDescribedbyIDs, utils) });
|
|
535
|
+
});
|
|
536
|
+
/**
|
|
537
|
+
* Add classes based on props
|
|
538
|
+
*
|
|
539
|
+
* @param {MgInputProps} props MgInput Interface Props
|
|
540
|
+
*/
|
|
541
|
+
const manageClasses = (props) => {
|
|
542
|
+
props.classList.add('mg-input');
|
|
543
|
+
if (props.labelOnTop)
|
|
544
|
+
props.classList.add('mg-input--label-on-top');
|
|
545
|
+
if (props.readonly)
|
|
546
|
+
props.classList.add('mg-input--readonly');
|
|
547
|
+
if (props.width !== undefined)
|
|
548
|
+
props.classList.add(`mg-input--width-${props.width}`);
|
|
549
|
+
if (props.readonly || props.disabled) {
|
|
550
|
+
props.classList.delete(InputClass.ERROR);
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
/**
|
|
554
|
+
* Get tagname
|
|
555
|
+
*
|
|
556
|
+
* @param {boolean} isFieldset is fieldset
|
|
557
|
+
* @returns {string} tag name
|
|
558
|
+
*/
|
|
559
|
+
const getTagName = (isFieldset) => (isFieldset ? 'fieldset' : 'div');
|
|
560
|
+
/**
|
|
561
|
+
* Get input template
|
|
562
|
+
*
|
|
563
|
+
* @param {MgInputProps} props MgInput Interface Props
|
|
564
|
+
* @param {VNode[]} children Represent scoped elements
|
|
565
|
+
* @param {FunctionalUtilities} utils Stencil.js utils
|
|
566
|
+
* @returns {VNode[]} input template
|
|
567
|
+
*/
|
|
568
|
+
const MgInput = (props, children, utils) => {
|
|
569
|
+
/**
|
|
570
|
+
* Check required properties
|
|
571
|
+
*/
|
|
572
|
+
if (typeof props.label !== 'string' || props.label === '') {
|
|
573
|
+
throw new Error('<mg-input> prop "label" is required');
|
|
574
|
+
}
|
|
575
|
+
if (props.labelOnTop && props.labelHide) {
|
|
576
|
+
throw new Error('<mg-input> prop "labelOnTop" must not be paired with the prop "labelHide"');
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Component classes
|
|
580
|
+
*/
|
|
581
|
+
manageClasses(props);
|
|
582
|
+
/**
|
|
583
|
+
* a11y IDs
|
|
584
|
+
*/
|
|
585
|
+
const ariaDescribedbyIDs = new Set();
|
|
586
|
+
// Character Left
|
|
587
|
+
const characterLeftId = `${props.identifier}-character-left`;
|
|
588
|
+
if (props.classList.has('is-focused') && props.displayCharacterLeft) {
|
|
589
|
+
ariaDescribedbyIDs.add(characterLeftId);
|
|
590
|
+
}
|
|
591
|
+
// Help text
|
|
592
|
+
const helpTextId = `${props.identifier}-help-text`;
|
|
593
|
+
if (typeof props.helpText === 'string' && props.helpText !== '') {
|
|
594
|
+
ariaDescribedbyIDs.add(helpTextId);
|
|
595
|
+
}
|
|
596
|
+
// Error Message
|
|
597
|
+
const helpTextErrorId = `${props.identifier}-error`;
|
|
598
|
+
if (typeof props.errorMessage === 'string' && props.errorMessage !== '') {
|
|
599
|
+
ariaDescribedbyIDs.add(helpTextErrorId);
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Update input(s) in children
|
|
603
|
+
*/
|
|
604
|
+
if (props.readonly) {
|
|
605
|
+
children = children.filter(child => child.$name$ === 'append-input');
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
children = applyAriadescribedBy(children, ariaDescribedbyIDs, utils);
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Return template
|
|
612
|
+
*
|
|
613
|
+
* +--------+--------------+---------+
|
|
614
|
+
* | label | input | tooltip |
|
|
615
|
+
* | +--------------+---------+
|
|
616
|
+
* | | nb Char Left |
|
|
617
|
+
* | +------------------------+
|
|
618
|
+
* | | Help Text |
|
|
619
|
+
* | +------------------------+
|
|
620
|
+
* | | Error |
|
|
621
|
+
* +--------+------------------------+
|
|
622
|
+
*
|
|
623
|
+
* Error message is based on this aria method: https://www.w3.org/WAI/tutorials/forms/notifications/#on-focus-change
|
|
624
|
+
*/
|
|
625
|
+
const TagName = getTagName(props.isFieldset);
|
|
626
|
+
/**
|
|
627
|
+
* Get tooltip node
|
|
628
|
+
*
|
|
629
|
+
* @returns {VNode[]} mg-tooltip
|
|
630
|
+
*/
|
|
631
|
+
const getTooltip = () => (h("mg-tooltip", { identifier: `${props.identifier}-tooltip`, message: props.tooltip },
|
|
632
|
+
h("mg-icon", { icon: "info-circle" })));
|
|
633
|
+
/**
|
|
634
|
+
* Get input title (label) node
|
|
635
|
+
*
|
|
636
|
+
* @returns {VNode[]} mg-input-title
|
|
637
|
+
*/
|
|
638
|
+
const getInputTitle = () => (h("mg-input-title", { identifier: props.identifier, class: props.labelHide ? 'sr-only' : undefined, required: props.required && !props.disabled, "is-legend": props.isFieldset }, props.label));
|
|
639
|
+
return (h(TagName, { class: props.classList.join() },
|
|
640
|
+
props.labelOnTop ? (h("div", { class: "mg-input__title" },
|
|
641
|
+
getInputTitle(),
|
|
642
|
+
!props.readonly && props.tooltip && getTooltip())) : (getInputTitle()),
|
|
643
|
+
props.readonly ? (h("div", { class: "mg-input__input-container" },
|
|
644
|
+
h("strong", null, props.readonlyValue || props.value),
|
|
645
|
+
children)) : (h("div", { class: "mg-input__input-container" },
|
|
646
|
+
h("div", { class: "mg-input__input" },
|
|
647
|
+
children,
|
|
648
|
+
!props.labelOnTop && props.tooltip && getTooltip()),
|
|
649
|
+
props.displayCharacterLeft && props.maxlength && props.classList.has('is-focused') && (h("mg-character-left", { identifier: characterLeftId, characters: props.value, maxlength: props.maxlength, template: props.characterLeftTemplate })),
|
|
650
|
+
props.helpText && h("div", { id: helpTextId, class: "mg-input__help-text", innerHTML: props.helpText }),
|
|
651
|
+
props.errorMessage && h("div", { id: helpTextErrorId, class: "mg-input__error", innerHTML: props.errorMessage, "aria-live": "assertive" })))));
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
const mgInputCheckboxCss = ":host{display:block}.mg-input{display:-ms-flexbox;display:flex;-ms-flex-align:start;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input.is-not-valid{color:hsl(var(--color-danger))}.mg-input.is-not-valid .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input mg-input-title{-ms-flex-negative:var(--mg-inputs-shrink, 1);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{-ms-flex-direction:column;flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:-ms-flexbox;display:flex;-ms-flex-align:baseline;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{-ms-flex-negative:1;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:-ms-inline-flexbox;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:-ms-inline-flexbox;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-icon{display:-ms-flexbox;display:flex}.mg-input__input{display:-ms-flexbox;display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input+*{text-align:start;margin-top:0.5rem}fieldset.mg-input{border:0;margin-left:0;margin-right:0;padding:0}fieldset.mg-input input[type=radio],fieldset.mg-input input[type=checkbox]{-ms-flex-negative:0;flex-shrink:0;width:var(--mg-input-check-size);height:var(--mg-input-check-size);margin-top:calc((var(--font-size) * var(--line-height) - var(--mg-input-check-size)) / 2);margin-right:0.6rem;margin-bottom:0;margin-left:0}fieldset.mg-input.mg-input--label-on-top .mg-input__input-group-container{margin-top:0.7rem}fieldset.mg-input.is-not-valid .mg-input__input-group{color:initial}.mg-input__input-container mg-tooltip{margin-left:2rem}.mg-input__input-group-container{margin:0;padding:0;list-style:none;display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;-webkit-column-gap:2.3rem;-moz-column-gap:2.3rem;column-gap:2.3rem;row-gap:1rem;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2)}.mg-input__input-group-container--vertical{-ms-flex-direction:column;flex-direction:column}.mg-input__input-group{display:-ms-flexbox;display:flex;-ms-flex-align:top;align-items:top}.mg-input__input-group.mg-input__input-group--disabled label{opacity:0.3}.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}";
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* type CheckboxItem validation function
|
|
658
|
+
*
|
|
659
|
+
* @param {CheckboxItem} item Checkbox item
|
|
660
|
+
* @returns {boolean} match item expectations
|
|
661
|
+
*/
|
|
662
|
+
const isCheckboxItem = (item) => typeof item === 'object' && typeof item.title === 'string' && (item.value === null || typeof item.value === 'boolean') && item.value !== undefined;
|
|
663
|
+
const MgInputCheckbox = class {
|
|
664
|
+
constructor(hostRef) {
|
|
665
|
+
registerInstance(this, hostRef);
|
|
666
|
+
this.valueChange = createEvent(this, "value-change", 7);
|
|
667
|
+
this.inputValid = createEvent(this, "input-valid", 7);
|
|
668
|
+
/************
|
|
669
|
+
* Internal *
|
|
670
|
+
************/
|
|
671
|
+
// classes
|
|
672
|
+
this.classError = InputClass.ERROR;
|
|
673
|
+
// HTML selector
|
|
674
|
+
this.inputs = [];
|
|
675
|
+
/**
|
|
676
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
677
|
+
* If not set, it will be created.
|
|
678
|
+
*/
|
|
679
|
+
this.identifier = createID('mg-input-checkbox');
|
|
680
|
+
/**
|
|
681
|
+
* Input name
|
|
682
|
+
* If not set the value equals the identifier
|
|
683
|
+
*/
|
|
684
|
+
this.name = this.identifier;
|
|
685
|
+
/**
|
|
686
|
+
* Define if label is visible
|
|
687
|
+
*/
|
|
688
|
+
this.labelHide = false;
|
|
689
|
+
/**
|
|
690
|
+
* Define if inputs are display verticaly
|
|
691
|
+
*/
|
|
692
|
+
this.inputVerticalList = false;
|
|
693
|
+
/**
|
|
694
|
+
* Define if input is required
|
|
695
|
+
*/
|
|
696
|
+
this.required = false;
|
|
697
|
+
/**
|
|
698
|
+
* Define if input is readonly
|
|
699
|
+
*/
|
|
700
|
+
this.readonly = false;
|
|
701
|
+
/**
|
|
702
|
+
* Define if input is disabled
|
|
703
|
+
*/
|
|
704
|
+
this.disabled = false;
|
|
705
|
+
/**
|
|
706
|
+
* Component classes
|
|
707
|
+
*/
|
|
708
|
+
this.classList = new ClassList(['mg-input--checkbox']);
|
|
709
|
+
/**
|
|
710
|
+
* Formated value for display
|
|
711
|
+
*/
|
|
712
|
+
this.checkboxItems = [];
|
|
713
|
+
/**
|
|
714
|
+
* Handle input event
|
|
715
|
+
*
|
|
716
|
+
* @param {InputEvent} event input event
|
|
717
|
+
*/
|
|
718
|
+
this.handleInput = (event) => {
|
|
719
|
+
this.checkboxItems = this.checkboxItems.map(item => {
|
|
720
|
+
if (item.id === event.target.id) {
|
|
721
|
+
item.value = Boolean(event.target.checked);
|
|
722
|
+
}
|
|
723
|
+
return item;
|
|
724
|
+
});
|
|
725
|
+
this.value = this.checkboxItems.map(o => ({ value: o.value, title: o.title, disabled: o.disabled }));
|
|
726
|
+
this.checkValidity();
|
|
727
|
+
};
|
|
728
|
+
/**
|
|
729
|
+
* Handle blur event
|
|
730
|
+
*/
|
|
731
|
+
this.handleBlur = () => {
|
|
732
|
+
// Check validity
|
|
733
|
+
this.checkValidity();
|
|
734
|
+
this.checkError();
|
|
735
|
+
};
|
|
736
|
+
/**
|
|
737
|
+
* Check if input is valid
|
|
738
|
+
*/
|
|
739
|
+
this.checkValidity = () => {
|
|
740
|
+
if (!this.readonly) {
|
|
741
|
+
const validity = this.getInvalidElement() === undefined;
|
|
742
|
+
// Set validity
|
|
743
|
+
this.valid = validity;
|
|
744
|
+
this.invalid = !validity;
|
|
745
|
+
//Send event
|
|
746
|
+
this.inputValid.emit(validity);
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
/**
|
|
750
|
+
* Check input errors
|
|
751
|
+
*/
|
|
752
|
+
this.checkError = () => {
|
|
753
|
+
const invalidElement = this.getInvalidElement();
|
|
754
|
+
// Set error message
|
|
755
|
+
this.errorMessage = undefined;
|
|
756
|
+
if (!this.valid && invalidElement.validity.valueMissing) {
|
|
757
|
+
this.errorMessage = messages.errors.required;
|
|
758
|
+
}
|
|
759
|
+
// Update class
|
|
760
|
+
if (this.valid) {
|
|
761
|
+
this.classList.delete(this.classError);
|
|
762
|
+
}
|
|
763
|
+
else {
|
|
764
|
+
this.classList.add(this.classError);
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
/**
|
|
768
|
+
* get invalid element
|
|
769
|
+
*
|
|
770
|
+
* @returns {HTMLInputElement} element
|
|
771
|
+
*/
|
|
772
|
+
this.getInvalidElement = () => this.inputs.find((element) => !element.disabled && !element.checkValidity());
|
|
773
|
+
}
|
|
774
|
+
validateValue(newValue) {
|
|
775
|
+
if (newValue && newValue.every(item => isCheckboxItem(item))) {
|
|
776
|
+
this.checkboxItems = newValue.map((item, index) => ({
|
|
777
|
+
id: `${this.identifier}_${index.toString()}`,
|
|
778
|
+
title: item.title,
|
|
779
|
+
value: item.value,
|
|
780
|
+
disabled: item.disabled,
|
|
781
|
+
}));
|
|
782
|
+
this.valueChange.emit(newValue);
|
|
783
|
+
}
|
|
784
|
+
else {
|
|
785
|
+
throw new Error('<mg-input-checkbox> prop "value" is required and all values must be the same type, CheckboxItem.');
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
handleReadOnly() {
|
|
789
|
+
this.classList.delete(this.classError);
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Public method to display errors
|
|
793
|
+
*
|
|
794
|
+
* @returns {Promise<void>}
|
|
795
|
+
*/
|
|
796
|
+
async displayError() {
|
|
797
|
+
this.checkValidity();
|
|
798
|
+
this.checkError();
|
|
799
|
+
}
|
|
800
|
+
/*************
|
|
801
|
+
* Lifecycle *
|
|
802
|
+
*************/
|
|
803
|
+
/**
|
|
804
|
+
* Check if component props are well configured on init
|
|
805
|
+
*
|
|
806
|
+
* @returns {ReturnType<typeof setTimeout>} timeout
|
|
807
|
+
*/
|
|
808
|
+
componentWillLoad() {
|
|
809
|
+
// Check values format
|
|
810
|
+
this.validateValue(this.value);
|
|
811
|
+
// Check validity when component is ready
|
|
812
|
+
// return a promise to process action only in the FIRST render().
|
|
813
|
+
// https://stenciljs.com/docs/component-lifecycle#componentwillload
|
|
814
|
+
return setTimeout(() => {
|
|
815
|
+
this.checkValidity();
|
|
816
|
+
}, 0);
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* Render
|
|
820
|
+
*
|
|
821
|
+
* @returns {HTMLElement} HTML Element
|
|
822
|
+
*/
|
|
823
|
+
render() {
|
|
824
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: undefined, width: undefined, disabled: this.disabled, value: this.value && this.value.toString(), readonlyValue: undefined, tooltip: !this.readonly && this.tooltip, displayCharacterLeft: undefined, characterLeftTemplate: undefined, maxlength: undefined, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: true }, h("ul", { class: { 'mg-input__input-group-container': true, 'mg-input__input-group-container--vertical': this.inputVerticalList } }, this.checkboxItems
|
|
825
|
+
.filter(item => {
|
|
826
|
+
return !this.readonly || item.value;
|
|
827
|
+
})
|
|
828
|
+
.map(input => (h("li", { class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } }, h("input", { type: "checkbox", id: input.id, name: this.identifier, value: input.value && input.value.toString(), checked: Boolean(input.value), disabled: this.readonly || this.disabled || input.disabled, required: this.required, indeterminate: input.value === null, onInput: this.handleInput, onBlur: this.handleBlur, ref: el => this.inputs.push(el) }), h("label", { htmlFor: input.id }, input.title)))))));
|
|
829
|
+
}
|
|
830
|
+
static get watchers() { return {
|
|
831
|
+
"value": ["validateValue"],
|
|
832
|
+
"readonly": ["handleReadOnly"]
|
|
833
|
+
}; }
|
|
834
|
+
};
|
|
835
|
+
MgInputCheckbox.style = mgInputCheckboxCss;
|
|
836
|
+
|
|
837
|
+
var InputError$1;
|
|
838
|
+
(function (InputError) {
|
|
839
|
+
InputError["MIN"] = "min";
|
|
840
|
+
InputError["MAX"] = "max";
|
|
841
|
+
InputError["MINMAX"] = "minMax";
|
|
842
|
+
InputError["REQUIRED"] = "required";
|
|
843
|
+
})(InputError$1 || (InputError$1 = {}));
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* Format number to the locale currency
|
|
847
|
+
*
|
|
848
|
+
* @param {number} number number to format
|
|
849
|
+
* @returns {string} formatted currency
|
|
850
|
+
*/
|
|
851
|
+
function localeCurrency(number) {
|
|
852
|
+
return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(number);
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Format number to locale
|
|
856
|
+
*
|
|
857
|
+
* @param {number} number number to format
|
|
858
|
+
* @returns {string} formatted number
|
|
859
|
+
*/
|
|
860
|
+
function localeNumber(number) {
|
|
861
|
+
return new Intl.NumberFormat(locale).format(number);
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Date RegExp
|
|
865
|
+
*/
|
|
866
|
+
const dateRegExp = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
|
|
867
|
+
/**
|
|
868
|
+
* Locale date format
|
|
869
|
+
*
|
|
870
|
+
* @param {string} date date to format
|
|
871
|
+
* @returns {string} formatted date
|
|
872
|
+
*/
|
|
873
|
+
function localeDate(date) {
|
|
874
|
+
if (typeof date !== 'string' || date === '' || !dateRegExp.test(date)) {
|
|
875
|
+
return '';
|
|
876
|
+
}
|
|
877
|
+
return new Intl.DateTimeFormat(locale).format(new Date(date));
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
const mgInputDateCss = ":host{display:block}.mg-input{display:-ms-flexbox;display:flex;-ms-flex-align:start;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input.is-not-valid{color:hsl(var(--color-danger))}.mg-input.is-not-valid .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input mg-input-title{-ms-flex-negative:var(--mg-inputs-shrink, 1);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{-ms-flex-direction:column;flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:-ms-flexbox;display:flex;-ms-flex-align:baseline;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{-ms-flex-negative:1;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:-ms-inline-flexbox;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:-ms-inline-flexbox;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-icon{display:-ms-flexbox;display:flex}.mg-input__input{display:-ms-flexbox;display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input+*{text-align:start;margin-top:0.5rem}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);width:100%;height:var(--default-size);-webkit-box-sizing:border-box;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)}.mg-input__box::-webkit-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::-moz-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:-ms-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::-ms-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{-webkit-box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5);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-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left: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-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.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)}.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}";
|
|
881
|
+
|
|
882
|
+
const MgInputDate = class {
|
|
883
|
+
constructor(hostRef) {
|
|
884
|
+
registerInstance(this, hostRef);
|
|
885
|
+
this.valueChange = createEvent(this, "value-change", 7);
|
|
886
|
+
this.inputValid = createEvent(this, "input-valid", 7);
|
|
887
|
+
/************
|
|
888
|
+
* Internal *
|
|
889
|
+
************/
|
|
890
|
+
// classes
|
|
891
|
+
this.classError = InputClass.ERROR;
|
|
892
|
+
/**
|
|
893
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
894
|
+
* If not set, it will be created.
|
|
895
|
+
*/
|
|
896
|
+
this.identifier = createID('mg-input-date');
|
|
897
|
+
/**
|
|
898
|
+
* Input name
|
|
899
|
+
* If not set the value equals the identifier
|
|
900
|
+
*/
|
|
901
|
+
this.name = this.identifier;
|
|
902
|
+
/**
|
|
903
|
+
* Define if label is visible
|
|
904
|
+
*/
|
|
905
|
+
this.labelHide = false;
|
|
906
|
+
/**
|
|
907
|
+
* Define if input is required
|
|
908
|
+
*/
|
|
909
|
+
this.required = false;
|
|
910
|
+
/**
|
|
911
|
+
* Define if input is readonly
|
|
912
|
+
*/
|
|
913
|
+
this.readonly = false;
|
|
914
|
+
/**
|
|
915
|
+
* Define if input is disabled
|
|
916
|
+
*/
|
|
917
|
+
this.disabled = false;
|
|
918
|
+
/**
|
|
919
|
+
* Component classes
|
|
920
|
+
*/
|
|
921
|
+
this.classList = new ClassList(['mg-input--date']);
|
|
922
|
+
/**
|
|
923
|
+
* Handle input event
|
|
924
|
+
*/
|
|
925
|
+
this.handleInput = () => {
|
|
926
|
+
this.checkValidity();
|
|
927
|
+
this.value = this.input.value;
|
|
928
|
+
};
|
|
929
|
+
/**
|
|
930
|
+
* Handle blur event
|
|
931
|
+
*/
|
|
932
|
+
this.handleBlur = () => {
|
|
933
|
+
this.checkValidity();
|
|
934
|
+
this.checkError();
|
|
935
|
+
};
|
|
936
|
+
/**
|
|
937
|
+
* Check if input is valid
|
|
938
|
+
*/
|
|
939
|
+
this.checkValidity = () => {
|
|
940
|
+
if (!this.readonly && this.input !== undefined) {
|
|
941
|
+
const validity = this.input.checkValidity();
|
|
942
|
+
// Set validity
|
|
943
|
+
this.valid = validity;
|
|
944
|
+
this.invalid = !validity;
|
|
945
|
+
//Send event
|
|
946
|
+
this.inputValid.emit(validity);
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
/**
|
|
950
|
+
* get input error code
|
|
951
|
+
*
|
|
952
|
+
* @returns {null | InputError} error code
|
|
953
|
+
*/
|
|
954
|
+
this.getInputError = () => {
|
|
955
|
+
var _a, _b;
|
|
956
|
+
let inputError = null;
|
|
957
|
+
// required
|
|
958
|
+
if (this.input.validity.valueMissing) {
|
|
959
|
+
inputError = InputError$1.REQUIRED;
|
|
960
|
+
}
|
|
961
|
+
// min & max
|
|
962
|
+
else if ((this.input.validity.rangeUnderflow || this.input.validity.rangeOverflow) && ((_a = this.min) === null || _a === void 0 ? void 0 : _a.length) > 0 && ((_b = this.max) === null || _b === void 0 ? void 0 : _b.length) > 0) {
|
|
963
|
+
inputError = InputError$1.MINMAX;
|
|
964
|
+
}
|
|
965
|
+
// min
|
|
966
|
+
else if (this.input.validity.rangeUnderflow) {
|
|
967
|
+
inputError = InputError$1.MIN;
|
|
968
|
+
}
|
|
969
|
+
//max
|
|
970
|
+
else if (this.input.validity.rangeOverflow) {
|
|
971
|
+
inputError = InputError$1.MAX;
|
|
972
|
+
}
|
|
973
|
+
return inputError;
|
|
974
|
+
};
|
|
975
|
+
/**
|
|
976
|
+
* Set error message
|
|
977
|
+
*
|
|
978
|
+
* @returns {void}
|
|
979
|
+
*/
|
|
980
|
+
this.setErrorMessage = () => {
|
|
981
|
+
var _a;
|
|
982
|
+
const inputError = this.getInputError();
|
|
983
|
+
// required
|
|
984
|
+
if (inputError === InputError$1.REQUIRED) {
|
|
985
|
+
this.errorMessage = messages.errors[inputError];
|
|
986
|
+
}
|
|
987
|
+
// min, max & minMax
|
|
988
|
+
else if ([InputError$1.MIN, InputError$1.MAX, InputError$1.MINMAX].includes(inputError)) {
|
|
989
|
+
this.errorMessage = messages.errors.date[inputError].replace('{min}', localeDate(this.min)).replace('{max}', localeDate(this.max));
|
|
990
|
+
}
|
|
991
|
+
// wrong date format
|
|
992
|
+
// element.validity.badInput is default error message
|
|
993
|
+
else {
|
|
994
|
+
this.errorMessage = messages.errors.date.badInput.replace('{min}', ((_a = this.min) === null || _a === void 0 ? void 0 : _a.length) > 0 ? localeDate(this.min) : localeDate('1900-01-01'));
|
|
995
|
+
}
|
|
996
|
+
};
|
|
997
|
+
/**
|
|
998
|
+
* Check input errors
|
|
999
|
+
*
|
|
1000
|
+
* @returns {void}
|
|
1001
|
+
*/
|
|
1002
|
+
this.checkError = () => {
|
|
1003
|
+
// Set error message
|
|
1004
|
+
this.errorMessage = undefined;
|
|
1005
|
+
if (!this.valid) {
|
|
1006
|
+
this.setErrorMessage();
|
|
1007
|
+
this.classList.add(this.classError);
|
|
1008
|
+
}
|
|
1009
|
+
else {
|
|
1010
|
+
this.classList.delete(this.classError);
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
}
|
|
1014
|
+
validateValue(newValue) {
|
|
1015
|
+
if (newValue !== undefined && newValue !== '' && !(typeof newValue === 'string' && dateRegExp.test(newValue))) {
|
|
1016
|
+
throw new Error("<mg-input-date> props 'value' doesn't match pattern: yyyy-mm-dd");
|
|
1017
|
+
}
|
|
1018
|
+
else {
|
|
1019
|
+
this.valueChange.emit(this.value);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
validateMin(newValue) {
|
|
1023
|
+
this.validateDateFormat(newValue);
|
|
1024
|
+
}
|
|
1025
|
+
validateMax(newValue) {
|
|
1026
|
+
this.validateDateFormat(newValue);
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Public method to display errors
|
|
1030
|
+
*
|
|
1031
|
+
* @returns {Promise<void>}
|
|
1032
|
+
*/
|
|
1033
|
+
async displayError() {
|
|
1034
|
+
this.checkValidity();
|
|
1035
|
+
this.checkError();
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Date format validation
|
|
1039
|
+
*
|
|
1040
|
+
* @param {string} date date to validate
|
|
1041
|
+
* @returns {void}
|
|
1042
|
+
*/
|
|
1043
|
+
validateDateFormat(date) {
|
|
1044
|
+
if ((date === null || date === void 0 ? void 0 : date.length) > 0 && !(typeof date === 'string' && dateRegExp.test(date))) {
|
|
1045
|
+
throw new Error("<mg-input-date> props 'min/max' doesn't match pattern: yyyy-mm-dd");
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
/*************
|
|
1049
|
+
* Lifecycle *
|
|
1050
|
+
*************/
|
|
1051
|
+
/**
|
|
1052
|
+
* Check if component props are well configured on init
|
|
1053
|
+
*
|
|
1054
|
+
* @returns {ReturnType<typeof setTimeout>} timeout
|
|
1055
|
+
*/
|
|
1056
|
+
componentWillLoad() {
|
|
1057
|
+
this.validateValue(this.value);
|
|
1058
|
+
this.validateMin(this.min);
|
|
1059
|
+
this.validateMax(this.max);
|
|
1060
|
+
// Check validity when component is ready
|
|
1061
|
+
// return a promise to process action only in the FIRST render().
|
|
1062
|
+
// https://stenciljs.com/docs/component-lifecycle#componentwillload
|
|
1063
|
+
return setTimeout(() => {
|
|
1064
|
+
this.checkValidity();
|
|
1065
|
+
}, 0);
|
|
1066
|
+
}
|
|
1067
|
+
/**
|
|
1068
|
+
* Render
|
|
1069
|
+
*
|
|
1070
|
+
* @returns {HTMLElement} HTML Element
|
|
1071
|
+
*/
|
|
1072
|
+
render() {
|
|
1073
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, width: undefined, disabled: this.disabled, value: this.value, readonlyValue: localeDate(this.value), tooltip: this.tooltip, displayCharacterLeft: undefined, characterLeftTemplate: undefined, maxlength: undefined, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("input", { type: "date", class: "mg-input__box", min: this.min, max: this.max, value: this.value, id: this.identifier, name: this.name, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, pattern: "[0-9]{4}-[0-9]{2}-[0-9]{2}", ref: el => (this.input = el) })));
|
|
1074
|
+
}
|
|
1075
|
+
static get watchers() { return {
|
|
1076
|
+
"value": ["validateValue"],
|
|
1077
|
+
"min": ["validateMin"],
|
|
1078
|
+
"max": ["validateMax"]
|
|
1079
|
+
}; }
|
|
1080
|
+
};
|
|
1081
|
+
MgInputDate.style = mgInputDateCss;
|
|
1082
|
+
|
|
1083
|
+
/**
|
|
1084
|
+
* List of all possibles types
|
|
1085
|
+
*/
|
|
1086
|
+
const types = ['decimal', 'integer', 'currency'];
|
|
1087
|
+
var InputError;
|
|
1088
|
+
(function (InputError) {
|
|
1089
|
+
InputError["MIN"] = "min";
|
|
1090
|
+
InputError["MAX"] = "max";
|
|
1091
|
+
InputError["MINMAX"] = "minMax";
|
|
1092
|
+
InputError["REQUIRED"] = "required";
|
|
1093
|
+
})(InputError || (InputError = {}));
|
|
1094
|
+
|
|
1095
|
+
const mgInputNumericCss = ":host{display:block}.mg-input{display:-ms-flexbox;display:flex;-ms-flex-align:start;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input.is-not-valid{color:hsl(var(--color-danger))}.mg-input.is-not-valid .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input mg-input-title{-ms-flex-negative:var(--mg-inputs-shrink, 1);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{-ms-flex-direction:column;flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:-ms-flexbox;display:flex;-ms-flex-align:baseline;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{-ms-flex-negative:1;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:-ms-inline-flexbox;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:-ms-inline-flexbox;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-icon{display:-ms-flexbox;display:flex}.mg-input__input{display:-ms-flexbox;display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input+*{text-align:start;margin-top:0.5rem}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);width:100%;height:var(--default-size);-webkit-box-sizing:border-box;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)}.mg-input__box::-webkit-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::-moz-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:-ms-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::-ms-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{-webkit-box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5);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-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left: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-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.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){-ms-flex-pack:justify;justify-content:space-between}.mg-input.mg-input--width-full .mg-input__input-container{-ms-flex:auto;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:right}";
|
|
1096
|
+
|
|
1097
|
+
const MgInputNumeric = class {
|
|
1098
|
+
constructor(hostRef) {
|
|
1099
|
+
registerInstance(this, hostRef);
|
|
1100
|
+
this.valueChange = createEvent(this, "value-change", 7);
|
|
1101
|
+
this.inputValid = createEvent(this, "input-valid", 7);
|
|
1102
|
+
// Classes
|
|
1103
|
+
this.classError = InputClass.ERROR;
|
|
1104
|
+
/**
|
|
1105
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
1106
|
+
* If not set, it will be created.
|
|
1107
|
+
*/
|
|
1108
|
+
this.identifier = createID('mg-input-numeric');
|
|
1109
|
+
/**
|
|
1110
|
+
* Input name
|
|
1111
|
+
* If not set the value equals the identifier
|
|
1112
|
+
*/
|
|
1113
|
+
this.name = this.identifier;
|
|
1114
|
+
/**
|
|
1115
|
+
* Define if label is visible
|
|
1116
|
+
*/
|
|
1117
|
+
this.labelHide = false;
|
|
1118
|
+
/**
|
|
1119
|
+
* Define if input is required
|
|
1120
|
+
*/
|
|
1121
|
+
this.required = false;
|
|
1122
|
+
/**
|
|
1123
|
+
* Define if input is readonly
|
|
1124
|
+
*/
|
|
1125
|
+
this.readonly = false;
|
|
1126
|
+
/**
|
|
1127
|
+
* Define if input is disabled
|
|
1128
|
+
*/
|
|
1129
|
+
this.disabled = false;
|
|
1130
|
+
/**
|
|
1131
|
+
* Define numeric type
|
|
1132
|
+
*/
|
|
1133
|
+
this.type = types[0];
|
|
1134
|
+
/**
|
|
1135
|
+
* Override integer length
|
|
1136
|
+
* integer is the number before the decimal point
|
|
1137
|
+
*/
|
|
1138
|
+
this.integerLength = 13;
|
|
1139
|
+
/**
|
|
1140
|
+
* Override decimal length
|
|
1141
|
+
* decimal is the number after the decimal point
|
|
1142
|
+
*/
|
|
1143
|
+
this.decimalLength = 2;
|
|
1144
|
+
/**
|
|
1145
|
+
* Component classes
|
|
1146
|
+
*/
|
|
1147
|
+
this.classList = new ClassList(['mg-input--numeric']);
|
|
1148
|
+
/**
|
|
1149
|
+
* Define if input has focus
|
|
1150
|
+
*/
|
|
1151
|
+
this.hasFocus = false;
|
|
1152
|
+
/**
|
|
1153
|
+
* Handle input event
|
|
1154
|
+
*
|
|
1155
|
+
* @returns {void}
|
|
1156
|
+
*/
|
|
1157
|
+
this.handleInput = () => {
|
|
1158
|
+
// Check validity
|
|
1159
|
+
this.checkValidity();
|
|
1160
|
+
this.value = this.input.value;
|
|
1161
|
+
};
|
|
1162
|
+
/**
|
|
1163
|
+
* Handle focus event
|
|
1164
|
+
*
|
|
1165
|
+
* @returns {void}
|
|
1166
|
+
*/
|
|
1167
|
+
this.handleFocus = () => {
|
|
1168
|
+
this.hasFocus = true;
|
|
1169
|
+
};
|
|
1170
|
+
/**
|
|
1171
|
+
* Handle blur event
|
|
1172
|
+
*
|
|
1173
|
+
* @returns {void}
|
|
1174
|
+
*/
|
|
1175
|
+
this.handleBlur = () => {
|
|
1176
|
+
// Check validity
|
|
1177
|
+
this.checkValidity();
|
|
1178
|
+
this.checkError();
|
|
1179
|
+
this.hasFocus = false;
|
|
1180
|
+
};
|
|
1181
|
+
/**
|
|
1182
|
+
* Check if input is valid
|
|
1183
|
+
*
|
|
1184
|
+
* @returns {void}
|
|
1185
|
+
*/
|
|
1186
|
+
this.checkValidity = () => {
|
|
1187
|
+
if (!this.readonly) {
|
|
1188
|
+
const validity = this.getInputError() === null;
|
|
1189
|
+
// Set validity
|
|
1190
|
+
this.valid = validity;
|
|
1191
|
+
this.invalid = !validity;
|
|
1192
|
+
//Send event
|
|
1193
|
+
this.inputValid.emit(validity);
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
/**
|
|
1197
|
+
* Set error message
|
|
1198
|
+
*
|
|
1199
|
+
* @returns {void}
|
|
1200
|
+
*/
|
|
1201
|
+
this.setErrorMessage = () => {
|
|
1202
|
+
const inputError = this.getInputError();
|
|
1203
|
+
if (inputError === InputError.REQUIRED) {
|
|
1204
|
+
this.errorMessage = messages.errors[inputError];
|
|
1205
|
+
}
|
|
1206
|
+
else {
|
|
1207
|
+
this.errorMessage = messages.errors.numeric[inputError].replace('{min}', `${this.formatValue(this.min)}`).replace('{max}', `${this.formatValue(this.max)}`);
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1210
|
+
/**
|
|
1211
|
+
* Check input errors
|
|
1212
|
+
*
|
|
1213
|
+
* @returns {void}
|
|
1214
|
+
*/
|
|
1215
|
+
this.checkError = () => {
|
|
1216
|
+
// Set error message
|
|
1217
|
+
this.errorMessage = undefined;
|
|
1218
|
+
// Update class
|
|
1219
|
+
if (!this.valid) {
|
|
1220
|
+
this.setErrorMessage();
|
|
1221
|
+
this.classList.add(this.classError);
|
|
1222
|
+
}
|
|
1223
|
+
else {
|
|
1224
|
+
this.classList.delete(this.classError);
|
|
1225
|
+
}
|
|
1226
|
+
};
|
|
1227
|
+
/**
|
|
1228
|
+
* Get input error code
|
|
1229
|
+
*
|
|
1230
|
+
* @returns {null | InputError} error code
|
|
1231
|
+
*/
|
|
1232
|
+
this.getInputError = () => {
|
|
1233
|
+
let inputError = null;
|
|
1234
|
+
if (this.input === undefined)
|
|
1235
|
+
return inputError;
|
|
1236
|
+
// required
|
|
1237
|
+
if (!this.input.checkValidity() && this.input.validity.valueMissing) {
|
|
1238
|
+
inputError = InputError.REQUIRED;
|
|
1239
|
+
}
|
|
1240
|
+
// Min & Max
|
|
1241
|
+
else if (this.min !== undefined && this.numericValue < this.min && this.max === undefined) {
|
|
1242
|
+
// Only a min value is set
|
|
1243
|
+
inputError = InputError.MIN;
|
|
1244
|
+
}
|
|
1245
|
+
else if (this.max !== undefined && this.numericValue > this.max && this.min === undefined) {
|
|
1246
|
+
// Only a max value is set
|
|
1247
|
+
inputError = InputError.MAX;
|
|
1248
|
+
}
|
|
1249
|
+
else if ((this.min !== undefined && this.numericValue < this.min) || (this.max !== undefined && this.numericValue > this.max)) {
|
|
1250
|
+
// both min and max values are set
|
|
1251
|
+
inputError = InputError.MINMAX;
|
|
1252
|
+
}
|
|
1253
|
+
return inputError;
|
|
1254
|
+
};
|
|
1255
|
+
/**
|
|
1256
|
+
* Format value based on type
|
|
1257
|
+
*
|
|
1258
|
+
* @param {number} value value to format
|
|
1259
|
+
* @returns {string} formated local value
|
|
1260
|
+
*/
|
|
1261
|
+
this.formatValue = (value) => (this.type === 'currency' ? localeCurrency(value) : localeNumber(value));
|
|
1262
|
+
/**
|
|
1263
|
+
* Validate append slot
|
|
1264
|
+
*
|
|
1265
|
+
* @returns {void}
|
|
1266
|
+
*/
|
|
1267
|
+
this.validateAppendSlot = () => {
|
|
1268
|
+
const slotAppendInput = this.element.querySelector('[slot="append-input"]');
|
|
1269
|
+
if (slotAppendInput !== null) {
|
|
1270
|
+
this.classList.add(slotAppendInput.nodeName === 'MG-BUTTON' ? 'mg-input--is-input-group-append' : 'mg-input--is-append-input-slot-content');
|
|
1271
|
+
}
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
validateValue(newValue) {
|
|
1275
|
+
if (newValue !== undefined && newValue !== null) {
|
|
1276
|
+
// Split number and decimal
|
|
1277
|
+
const [integer, decimal = ''] = newValue.replace('-', '').split(/[\.,]/);
|
|
1278
|
+
// Regex
|
|
1279
|
+
const regex = this.type === 'integer' ? /^[\-]?\d+$/ : /^[\-]?\d+[.,]?\d*$/;
|
|
1280
|
+
// Filter input
|
|
1281
|
+
if (newValue === '' || (newValue.match(regex) && integer.length <= this.integerLength && decimal.length <= (this.type === 'integer' ? 0 : this.decimalLength))) {
|
|
1282
|
+
this.storedValue = newValue;
|
|
1283
|
+
}
|
|
1284
|
+
else if (this.storedValue !== undefined) {
|
|
1285
|
+
newValue = this.storedValue;
|
|
1286
|
+
}
|
|
1287
|
+
else {
|
|
1288
|
+
newValue = null;
|
|
1289
|
+
}
|
|
1290
|
+
// Set value and input value
|
|
1291
|
+
this.value = newValue;
|
|
1292
|
+
if (this.input !== undefined)
|
|
1293
|
+
this.input.value = this.value;
|
|
1294
|
+
// emit numeric value
|
|
1295
|
+
this.numericValue = this.value !== '' && this.value !== null ? parseFloat(this.value.replace(',', '.')) : null;
|
|
1296
|
+
this.valueChange.emit(this.numericValue);
|
|
1297
|
+
// Set readOnlyValue
|
|
1298
|
+
this.readonlyValue = this.numericValue !== null ? this.formatValue(this.numericValue) : '';
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
validateType(newValue) {
|
|
1302
|
+
if (!types.includes(newValue)) {
|
|
1303
|
+
throw new Error(`<mg-input-numeric> prop "type" must be one of : ${types.join(', ')}`);
|
|
1304
|
+
}
|
|
1305
|
+
this.classList.add(`mg-input--numeric--${this.type}`);
|
|
1306
|
+
}
|
|
1307
|
+
validateIntegerLength(newValue) {
|
|
1308
|
+
if (newValue < 1) {
|
|
1309
|
+
throw new Error(`<mg-input-numeric> prop "integer-length" must be a positive number.`);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
validateDecimalLength(newValue) {
|
|
1313
|
+
if (newValue < 1) {
|
|
1314
|
+
throw new Error(`<mg-input-numeric> prop "decimal-length" must be a positive number, consider using prop "type" to "integer" instead.`);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Public method to display errors
|
|
1319
|
+
*
|
|
1320
|
+
* @returns {Promise<void>}
|
|
1321
|
+
*/
|
|
1322
|
+
async displayError() {
|
|
1323
|
+
this.checkValidity();
|
|
1324
|
+
this.checkError();
|
|
1325
|
+
}
|
|
1326
|
+
/**
|
|
1327
|
+
* Displayed value in input
|
|
1328
|
+
* Change on focus/blur
|
|
1329
|
+
*
|
|
1330
|
+
* @returns {string} display value
|
|
1331
|
+
*/
|
|
1332
|
+
displayValue() {
|
|
1333
|
+
return this.hasFocus ? this.value : this.readonlyValue;
|
|
1334
|
+
}
|
|
1335
|
+
/*************
|
|
1336
|
+
* Lifecycle *
|
|
1337
|
+
*************/
|
|
1338
|
+
/**
|
|
1339
|
+
* Check if component props are well configured on init
|
|
1340
|
+
*
|
|
1341
|
+
* @returns {ReturnType<typeof setTimeout>} timeout
|
|
1342
|
+
*/
|
|
1343
|
+
componentWillLoad() {
|
|
1344
|
+
this.validateValue(this.value);
|
|
1345
|
+
this.validateType(this.type);
|
|
1346
|
+
this.validateIntegerLength(this.integerLength);
|
|
1347
|
+
this.validateDecimalLength(this.decimalLength);
|
|
1348
|
+
this.validateAppendSlot();
|
|
1349
|
+
// Check validity when component is ready
|
|
1350
|
+
// return a promise to process action only in the FIRST render().
|
|
1351
|
+
// https://stenciljs.com/docs/component-lifecycle#componentwillload
|
|
1352
|
+
return setTimeout(() => {
|
|
1353
|
+
this.checkValidity();
|
|
1354
|
+
}, 0);
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Render
|
|
1358
|
+
*
|
|
1359
|
+
* @returns {HTMLElement} HTML Element
|
|
1360
|
+
*/
|
|
1361
|
+
render() {
|
|
1362
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, width: this.width, disabled: this.disabled, value: this.value, readonlyValue: this.readonlyValue, tooltip: this.tooltip, displayCharacterLeft: undefined, characterLeftTemplate: undefined, maxlength: undefined, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("input", { type: "text", class: "mg-input__box", value: this.displayValue(), id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el => (this.input = el) }), h("slot", { name: "append-input" })));
|
|
1363
|
+
}
|
|
1364
|
+
get element() { return getElement(this); }
|
|
1365
|
+
static get watchers() { return {
|
|
1366
|
+
"value": ["validateValue"],
|
|
1367
|
+
"type": ["validateType"],
|
|
1368
|
+
"integerLength": ["validateIntegerLength"],
|
|
1369
|
+
"decimalLength": ["validateDecimalLength"]
|
|
1370
|
+
}; }
|
|
1371
|
+
};
|
|
1372
|
+
MgInputNumeric.style = mgInputNumericCss;
|
|
1373
|
+
|
|
1374
|
+
const mgInputPasswordCss = ":host{display:block}.mg-input{display:-ms-flexbox;display:flex;-ms-flex-align:start;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input.is-not-valid{color:hsl(var(--color-danger))}.mg-input.is-not-valid .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input mg-input-title{-ms-flex-negative:var(--mg-inputs-shrink, 1);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{-ms-flex-direction:column;flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:-ms-flexbox;display:flex;-ms-flex-align:baseline;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{-ms-flex-negative:1;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:-ms-inline-flexbox;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:-ms-inline-flexbox;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-icon{display:-ms-flexbox;display:flex}.mg-input__input{display:-ms-flexbox;display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input+*{text-align:start;margin-top:0.5rem}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);width:100%;height:var(--default-size);-webkit-box-sizing:border-box;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)}.mg-input__box::-webkit-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::-moz-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:-ms-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::-ms-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{-webkit-box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5);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-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left: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-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.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){-ms-flex-pack:justify;justify-content:space-between}.mg-input.mg-input--width-full .mg-input__input-container{-ms-flex:auto;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}";
|
|
1375
|
+
|
|
1376
|
+
const MgInputPassword = class {
|
|
1377
|
+
constructor(hostRef) {
|
|
1378
|
+
registerInstance(this, hostRef);
|
|
1379
|
+
this.valueChange = createEvent(this, "value-change", 7);
|
|
1380
|
+
this.inputValid = createEvent(this, "input-valid", 7);
|
|
1381
|
+
/************
|
|
1382
|
+
* Internal *
|
|
1383
|
+
************/
|
|
1384
|
+
// classes
|
|
1385
|
+
this.classError = InputClass.ERROR;
|
|
1386
|
+
/**
|
|
1387
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
1388
|
+
* If not set, it will be created.
|
|
1389
|
+
*/
|
|
1390
|
+
this.identifier = createID('mg-input-password');
|
|
1391
|
+
/**
|
|
1392
|
+
* Input name
|
|
1393
|
+
* If not set the value equals the identifier
|
|
1394
|
+
*/
|
|
1395
|
+
this.name = this.identifier;
|
|
1396
|
+
/**
|
|
1397
|
+
* Define if label is visible
|
|
1398
|
+
*/
|
|
1399
|
+
this.labelHide = false;
|
|
1400
|
+
/**
|
|
1401
|
+
* Define if input is required
|
|
1402
|
+
*/
|
|
1403
|
+
this.required = false;
|
|
1404
|
+
/**
|
|
1405
|
+
* Define if input is readonly
|
|
1406
|
+
*/
|
|
1407
|
+
this.readonly = false;
|
|
1408
|
+
/**
|
|
1409
|
+
* Define if input is disabled
|
|
1410
|
+
*/
|
|
1411
|
+
this.disabled = false;
|
|
1412
|
+
/**
|
|
1413
|
+
* Define input width
|
|
1414
|
+
*/
|
|
1415
|
+
this.width = 'full';
|
|
1416
|
+
/**
|
|
1417
|
+
* Component classes
|
|
1418
|
+
*/
|
|
1419
|
+
this.classList = new ClassList(['mg-input--password']);
|
|
1420
|
+
/**
|
|
1421
|
+
* Handle input event
|
|
1422
|
+
*/
|
|
1423
|
+
this.handleInput = () => {
|
|
1424
|
+
this.checkValidity();
|
|
1425
|
+
this.value = this.input.value;
|
|
1426
|
+
};
|
|
1427
|
+
/**
|
|
1428
|
+
* Handle blur event
|
|
1429
|
+
*/
|
|
1430
|
+
this.handleBlur = () => {
|
|
1431
|
+
this.checkValidity();
|
|
1432
|
+
this.checkError();
|
|
1433
|
+
};
|
|
1434
|
+
/**
|
|
1435
|
+
* Check if input is valid
|
|
1436
|
+
*/
|
|
1437
|
+
this.checkValidity = () => {
|
|
1438
|
+
if (!this.readonly && this.input !== undefined) {
|
|
1439
|
+
const validity = this.input.checkValidity();
|
|
1440
|
+
// Set validity
|
|
1441
|
+
this.valid = validity;
|
|
1442
|
+
this.invalid = !validity;
|
|
1443
|
+
//Send event
|
|
1444
|
+
this.inputValid.emit(validity);
|
|
1445
|
+
}
|
|
1446
|
+
};
|
|
1447
|
+
/**
|
|
1448
|
+
* Check input errors
|
|
1449
|
+
*/
|
|
1450
|
+
this.checkError = () => {
|
|
1451
|
+
// Set error message
|
|
1452
|
+
this.errorMessage = undefined;
|
|
1453
|
+
// required
|
|
1454
|
+
if (!this.valid && this.input.validity.valueMissing) {
|
|
1455
|
+
this.errorMessage = messages.errors.required;
|
|
1456
|
+
}
|
|
1457
|
+
// Update class
|
|
1458
|
+
if (this.valid) {
|
|
1459
|
+
this.classList.delete(this.classError);
|
|
1460
|
+
}
|
|
1461
|
+
else {
|
|
1462
|
+
this.classList.add(this.classError);
|
|
1463
|
+
}
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
handleValue(newValue) {
|
|
1467
|
+
this.valueChange.emit(newValue);
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Public method to display errors
|
|
1471
|
+
*
|
|
1472
|
+
* @returns {Promise<void>}
|
|
1473
|
+
*/
|
|
1474
|
+
async displayError() {
|
|
1475
|
+
this.checkValidity();
|
|
1476
|
+
this.checkError();
|
|
1477
|
+
}
|
|
1478
|
+
/*************
|
|
1479
|
+
* Lifecycle *
|
|
1480
|
+
*************/
|
|
1481
|
+
/**
|
|
1482
|
+
* Check if component props are well configured on init
|
|
1483
|
+
*
|
|
1484
|
+
* @returns {ReturnType<typeof setTimeout>} timeout
|
|
1485
|
+
*/
|
|
1486
|
+
componentWillLoad() {
|
|
1487
|
+
// Check validity when component is ready
|
|
1488
|
+
// return a promise to process action only in the FIRST render().
|
|
1489
|
+
// https://stenciljs.com/docs/component-lifecycle#componentwillload
|
|
1490
|
+
return setTimeout(() => {
|
|
1491
|
+
this.checkValidity();
|
|
1492
|
+
}, 0);
|
|
1493
|
+
}
|
|
1494
|
+
/**
|
|
1495
|
+
* Render
|
|
1496
|
+
*
|
|
1497
|
+
* @returns {HTMLElement} HTML Element
|
|
1498
|
+
*/
|
|
1499
|
+
render() {
|
|
1500
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, width: this.width, disabled: this.disabled, value: this.value, readonlyValue: this.value !== undefined ? '•'.repeat(this.value.length) : undefined, tooltip: this.tooltip, displayCharacterLeft: false, characterLeftTemplate: undefined, maxlength: undefined, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("input", { type: "password", class: "mg-input__box", value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, ref: el => (this.input = el) })));
|
|
1501
|
+
}
|
|
1502
|
+
static get watchers() { return {
|
|
1503
|
+
"value": ["handleValue"]
|
|
1504
|
+
}; }
|
|
1505
|
+
};
|
|
1506
|
+
MgInputPassword.style = mgInputPasswordCss;
|
|
1507
|
+
|
|
1508
|
+
const mgInputRadioCss = ":host{display:block}.mg-input{display:-ms-flexbox;display:flex;-ms-flex-align:start;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input.is-not-valid{color:hsl(var(--color-danger))}.mg-input.is-not-valid .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input mg-input-title{-ms-flex-negative:var(--mg-inputs-shrink, 1);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{-ms-flex-direction:column;flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:-ms-flexbox;display:flex;-ms-flex-align:baseline;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{-ms-flex-negative:1;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:-ms-inline-flexbox;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:-ms-inline-flexbox;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-icon{display:-ms-flexbox;display:flex}.mg-input__input{display:-ms-flexbox;display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input+*{text-align:start;margin-top:0.5rem}fieldset.mg-input{border:0;margin-left:0;margin-right:0;padding:0}fieldset.mg-input input[type=radio],fieldset.mg-input input[type=checkbox]{-ms-flex-negative:0;flex-shrink:0;width:var(--mg-input-check-size);height:var(--mg-input-check-size);margin-top:calc((var(--font-size) * var(--line-height) - var(--mg-input-check-size)) / 2);margin-right:0.6rem;margin-bottom:0;margin-left:0}fieldset.mg-input.mg-input--label-on-top .mg-input__input-group-container{margin-top:0.7rem}fieldset.mg-input.is-not-valid .mg-input__input-group{color:initial}.mg-input__input-container mg-tooltip{margin-left:2rem}.mg-input__input-group-container{margin:0;padding:0;list-style:none;display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;-webkit-column-gap:2.3rem;-moz-column-gap:2.3rem;column-gap:2.3rem;row-gap:1rem;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2)}.mg-input__input-group-container--vertical{-ms-flex-direction:column;flex-direction:column}.mg-input__input-group{display:-ms-flexbox;display:flex;-ms-flex-align:top;align-items:top}.mg-input__input-group.mg-input__input-group--disabled label{opacity:0.3}.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}";
|
|
1509
|
+
|
|
1510
|
+
/**
|
|
1511
|
+
* type Option validation function
|
|
1512
|
+
*
|
|
1513
|
+
* @param {RadioOption} option radio option
|
|
1514
|
+
* @returns {boolean} radio option type is valid
|
|
1515
|
+
*/
|
|
1516
|
+
const isOption$2 = (option) => typeof option === 'object' && typeof option.title === 'string' && option.value !== undefined;
|
|
1517
|
+
const MgInputRadio = class {
|
|
1518
|
+
constructor(hostRef) {
|
|
1519
|
+
registerInstance(this, hostRef);
|
|
1520
|
+
this.valueChange = createEvent(this, "value-change", 7);
|
|
1521
|
+
this.inputValid = createEvent(this, "input-valid", 7);
|
|
1522
|
+
/************
|
|
1523
|
+
* Internal *
|
|
1524
|
+
************/
|
|
1525
|
+
// classes
|
|
1526
|
+
this.classError = InputClass.ERROR;
|
|
1527
|
+
// HTML selector
|
|
1528
|
+
this.inputs = [];
|
|
1529
|
+
/**
|
|
1530
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
1531
|
+
* If not set, it will be created.
|
|
1532
|
+
*/
|
|
1533
|
+
this.identifier = createID('mg-input-radio');
|
|
1534
|
+
/**
|
|
1535
|
+
* Input name
|
|
1536
|
+
* If not set the value equals the identifier
|
|
1537
|
+
*/
|
|
1538
|
+
this.name = this.identifier;
|
|
1539
|
+
/**
|
|
1540
|
+
* Define if label is displayed on top
|
|
1541
|
+
*/
|
|
1542
|
+
this.labelOnTop = false;
|
|
1543
|
+
/**
|
|
1544
|
+
* Define if label is visible
|
|
1545
|
+
*/
|
|
1546
|
+
this.labelHide = false;
|
|
1547
|
+
/**
|
|
1548
|
+
* Define if inputs are display verticaly
|
|
1549
|
+
*/
|
|
1550
|
+
this.inputVerticalList = false;
|
|
1551
|
+
/**
|
|
1552
|
+
* Define if input is required
|
|
1553
|
+
*/
|
|
1554
|
+
this.required = false;
|
|
1555
|
+
/**
|
|
1556
|
+
* Define if input is readonly
|
|
1557
|
+
*/
|
|
1558
|
+
this.readonly = false;
|
|
1559
|
+
/**
|
|
1560
|
+
* Define if input is disabled
|
|
1561
|
+
*/
|
|
1562
|
+
this.disabled = false;
|
|
1563
|
+
/**
|
|
1564
|
+
* Component classes
|
|
1565
|
+
*/
|
|
1566
|
+
this.classList = new ClassList(['mg-input--radio']);
|
|
1567
|
+
/**
|
|
1568
|
+
* Handle input event
|
|
1569
|
+
*
|
|
1570
|
+
* @param {event} event input event
|
|
1571
|
+
* @returns {void}
|
|
1572
|
+
*/
|
|
1573
|
+
this.handleInput = (event) => {
|
|
1574
|
+
this.checkValidity();
|
|
1575
|
+
this.value = this.options[event.target.value].value;
|
|
1576
|
+
};
|
|
1577
|
+
/**
|
|
1578
|
+
* Handle blur event
|
|
1579
|
+
*
|
|
1580
|
+
* @returns {void}
|
|
1581
|
+
*/
|
|
1582
|
+
this.handleBlur = () => {
|
|
1583
|
+
this.checkValidity();
|
|
1584
|
+
this.checkError();
|
|
1585
|
+
};
|
|
1586
|
+
/**
|
|
1587
|
+
* Check if input is valid
|
|
1588
|
+
*
|
|
1589
|
+
* @returns {void}
|
|
1590
|
+
*/
|
|
1591
|
+
this.checkValidity = () => {
|
|
1592
|
+
if (!this.readonly) {
|
|
1593
|
+
const validity = this.getInvalidElement() === undefined;
|
|
1594
|
+
// Set validity
|
|
1595
|
+
this.valid = validity;
|
|
1596
|
+
this.invalid = !validity;
|
|
1597
|
+
//Send event
|
|
1598
|
+
this.inputValid.emit(validity);
|
|
1599
|
+
}
|
|
1600
|
+
};
|
|
1601
|
+
/**
|
|
1602
|
+
* Check input errors
|
|
1603
|
+
*
|
|
1604
|
+
* @returns {void}
|
|
1605
|
+
*/
|
|
1606
|
+
this.checkError = () => {
|
|
1607
|
+
const invalidElement = this.getInvalidElement();
|
|
1608
|
+
// Set error message
|
|
1609
|
+
this.errorMessage = undefined;
|
|
1610
|
+
if (!this.valid && invalidElement.validity.valueMissing) {
|
|
1611
|
+
this.errorMessage = messages.errors.required;
|
|
1612
|
+
}
|
|
1613
|
+
// Update class
|
|
1614
|
+
if (this.valid) {
|
|
1615
|
+
this.classList.delete(this.classError);
|
|
1616
|
+
}
|
|
1617
|
+
else {
|
|
1618
|
+
this.classList.add(this.classError);
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
/**
|
|
1622
|
+
* get invalid element
|
|
1623
|
+
*
|
|
1624
|
+
* @returns {HTMLInputElement} element
|
|
1625
|
+
*/
|
|
1626
|
+
this.getInvalidElement = () => this.inputs.find((element) => !element.disabled && !element.checkValidity());
|
|
1627
|
+
}
|
|
1628
|
+
handleValue(newValue) {
|
|
1629
|
+
this.valueChange.emit(newValue);
|
|
1630
|
+
}
|
|
1631
|
+
validateItems(newValue) {
|
|
1632
|
+
// Validate if items have required min length
|
|
1633
|
+
if (typeof newValue === 'object' && newValue.length < 2) {
|
|
1634
|
+
throw new Error('<mg-input-radio> prop "items" require at least 2 items.');
|
|
1635
|
+
}
|
|
1636
|
+
// String array
|
|
1637
|
+
else if (allItemsAreString(newValue)) {
|
|
1638
|
+
this.options = newValue.map(item => ({ title: item, value: item, disabled: this.disabled }));
|
|
1639
|
+
}
|
|
1640
|
+
// Object array
|
|
1641
|
+
else if (newValue && newValue.every(item => isOption$2(item))) {
|
|
1642
|
+
this.options = newValue;
|
|
1643
|
+
}
|
|
1644
|
+
else {
|
|
1645
|
+
throw new Error('<mg-input-radio> prop "items" is required and all items must be the same type, string or RadioOption.');
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
/**
|
|
1649
|
+
* Public method to display errors
|
|
1650
|
+
*
|
|
1651
|
+
* @returns {Promise<void>}
|
|
1652
|
+
*/
|
|
1653
|
+
async displayError() {
|
|
1654
|
+
this.checkValidity();
|
|
1655
|
+
this.checkError();
|
|
1656
|
+
}
|
|
1657
|
+
/*************
|
|
1658
|
+
* Lifecycle *
|
|
1659
|
+
*************/
|
|
1660
|
+
/**
|
|
1661
|
+
* Check if component props are well configured on init
|
|
1662
|
+
*
|
|
1663
|
+
* @returns {ReturnType<typeof setTimeout>} timeout
|
|
1664
|
+
*/
|
|
1665
|
+
componentWillLoad() {
|
|
1666
|
+
// Check items format
|
|
1667
|
+
this.validateItems(this.items);
|
|
1668
|
+
// Check validity when component is ready
|
|
1669
|
+
// return a promise to process action only in the FIRST render().
|
|
1670
|
+
// https://stenciljs.com/docs/component-lifecycle#componentwillload
|
|
1671
|
+
return setTimeout(() => {
|
|
1672
|
+
this.checkValidity();
|
|
1673
|
+
}, 0);
|
|
1674
|
+
}
|
|
1675
|
+
/**
|
|
1676
|
+
* Render
|
|
1677
|
+
*
|
|
1678
|
+
* @returns {HTMLElement} HTML Element
|
|
1679
|
+
*/
|
|
1680
|
+
render() {
|
|
1681
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, disabled: this.disabled, readonly: this.readonly, width: undefined, value: this.value, readonlyValue: this.value, tooltip: this.tooltip, displayCharacterLeft: undefined, characterLeftTemplate: undefined, maxlength: undefined, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: true }, h("ul", { class: { 'mg-input__input-group-container': true, 'mg-input__input-group-container--vertical': this.inputVerticalList } }, this.options.map((input, index) => (h("li", { class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } }, h("input", { type: "radio", id: this.identifier + '_' + index, name: this.identifier, value: index, checked: JSON.stringify(this.value) === JSON.stringify(this.options[index].value), disabled: this.disabled || input.disabled, required: this.required, onBlur: this.handleBlur, onInput: this.handleInput, ref: el => this.inputs.push(el) }), h("label", { htmlFor: this.identifier + '_' + index }, input.title)))))));
|
|
1682
|
+
}
|
|
1683
|
+
static get watchers() { return {
|
|
1684
|
+
"value": ["handleValue"],
|
|
1685
|
+
"items": ["validateItems"]
|
|
1686
|
+
}; }
|
|
1687
|
+
};
|
|
1688
|
+
MgInputRadio.style = mgInputRadioCss;
|
|
1689
|
+
|
|
1690
|
+
const mgInputSelectCss = ":host{display:block}.mg-input{display:-ms-flexbox;display:flex;-ms-flex-align:start;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input.is-not-valid{color:hsl(var(--color-danger))}.mg-input.is-not-valid .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input mg-input-title{-ms-flex-negative:var(--mg-inputs-shrink, 1);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{-ms-flex-direction:column;flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:-ms-flexbox;display:flex;-ms-flex-align:baseline;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{-ms-flex-negative:1;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:-ms-inline-flexbox;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:-ms-inline-flexbox;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-icon{display:-ms-flexbox;display:flex}.mg-input__input{display:-ms-flexbox;display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input+*{text-align:start;margin-top:0.5rem}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);width:100%;height:var(--default-size);-webkit-box-sizing:border-box;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)}.mg-input__box::-webkit-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::-moz-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:-ms-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::-ms-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{-webkit-box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5);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-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left: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-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.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){-ms-flex-pack:justify;justify-content:space-between}.mg-input.mg-input--width-full .mg-input__input-container{-ms-flex:auto;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{padding-top:0;padding-bottom:0;padding-right:1rem}";
|
|
1691
|
+
|
|
1692
|
+
/**
|
|
1693
|
+
* Check if item is a well configured option
|
|
1694
|
+
*
|
|
1695
|
+
* @param {SelectOption} option select option
|
|
1696
|
+
* @returns {boolean} select option type is valid
|
|
1697
|
+
*/
|
|
1698
|
+
const isOption$1 = (option) => typeof option === 'object' && typeof option.title === 'string' && option.value !== undefined;
|
|
1699
|
+
/**
|
|
1700
|
+
* Group options
|
|
1701
|
+
*
|
|
1702
|
+
* @param {(SelectOption | OptGroup)[]} acc reduce accumulator
|
|
1703
|
+
* @param {SelectOption} item item to add
|
|
1704
|
+
* @param {string} item.group item group
|
|
1705
|
+
* @param {string} item.title item title
|
|
1706
|
+
* @param {unknown} item.value item value
|
|
1707
|
+
* @param {boolean} item.disabled is item disabled
|
|
1708
|
+
* @returns {(SelectOption | OptGroup)[]} grouped options
|
|
1709
|
+
*/
|
|
1710
|
+
const groupOptions = (acc, { group, title, value, disabled }) => {
|
|
1711
|
+
if (group !== undefined) {
|
|
1712
|
+
// Check if group is already created
|
|
1713
|
+
const optGroup = acc.find(grp => grp.group === group);
|
|
1714
|
+
// Add to group
|
|
1715
|
+
if (optGroup !== undefined) {
|
|
1716
|
+
optGroup.options.push({ title, value, disabled });
|
|
1717
|
+
}
|
|
1718
|
+
// Create group
|
|
1719
|
+
else {
|
|
1720
|
+
acc.push({ group, options: [{ title, value, disabled }] });
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
else {
|
|
1724
|
+
acc.push({ title, value, disabled });
|
|
1725
|
+
}
|
|
1726
|
+
return acc;
|
|
1727
|
+
};
|
|
1728
|
+
const MgInputSelect = class {
|
|
1729
|
+
constructor(hostRef) {
|
|
1730
|
+
registerInstance(this, hostRef);
|
|
1731
|
+
this.valueChange = createEvent(this, "value-change", 7);
|
|
1732
|
+
this.inputValid = createEvent(this, "input-valid", 7);
|
|
1733
|
+
/************
|
|
1734
|
+
* Internal *
|
|
1735
|
+
************/
|
|
1736
|
+
// classes
|
|
1737
|
+
this.classError = InputClass.ERROR;
|
|
1738
|
+
/**
|
|
1739
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
1740
|
+
* If not set, it will be created.
|
|
1741
|
+
*/
|
|
1742
|
+
this.identifier = createID('mg-input-select');
|
|
1743
|
+
/**
|
|
1744
|
+
* Input name
|
|
1745
|
+
* If not set the value equals the identifier
|
|
1746
|
+
*/
|
|
1747
|
+
this.name = this.identifier;
|
|
1748
|
+
/**
|
|
1749
|
+
* Define if label is visible
|
|
1750
|
+
*/
|
|
1751
|
+
this.labelHide = false;
|
|
1752
|
+
/**
|
|
1753
|
+
* Input placeholder.
|
|
1754
|
+
* It should be a word or short phrase that demonstrates the expected type of data, not a replacement for labels or help text.
|
|
1755
|
+
*/
|
|
1756
|
+
this.placeholder = messages.input.select.placeholder;
|
|
1757
|
+
/**
|
|
1758
|
+
* Option to remove placeholder
|
|
1759
|
+
*/
|
|
1760
|
+
this.placeholderHide = false;
|
|
1761
|
+
/**
|
|
1762
|
+
* Option to disable placeholder
|
|
1763
|
+
*/
|
|
1764
|
+
this.placeholderDisabled = false;
|
|
1765
|
+
/**
|
|
1766
|
+
* Define if input is required
|
|
1767
|
+
*/
|
|
1768
|
+
this.required = false;
|
|
1769
|
+
/**
|
|
1770
|
+
* Define if input is readonly
|
|
1771
|
+
*/
|
|
1772
|
+
this.readonly = false;
|
|
1773
|
+
/**
|
|
1774
|
+
* Define if input is disabled
|
|
1775
|
+
*/
|
|
1776
|
+
this.disabled = false;
|
|
1777
|
+
/**
|
|
1778
|
+
* Component classes
|
|
1779
|
+
*/
|
|
1780
|
+
this.classList = new ClassList(['mg-input--select']);
|
|
1781
|
+
/**
|
|
1782
|
+
* Handle input event
|
|
1783
|
+
*/
|
|
1784
|
+
this.handleInput = () => {
|
|
1785
|
+
this.checkValidity();
|
|
1786
|
+
if (this.input.value !== '') {
|
|
1787
|
+
this.value = allItemsAreString(this.items) ? this.input.value : this.items.find(item => item.title === this.input.value).value;
|
|
1788
|
+
}
|
|
1789
|
+
else {
|
|
1790
|
+
this.value = null;
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1793
|
+
/**
|
|
1794
|
+
* Handle blur event
|
|
1795
|
+
*/
|
|
1796
|
+
this.handleBlur = () => {
|
|
1797
|
+
this.checkValidity();
|
|
1798
|
+
this.checkError();
|
|
1799
|
+
};
|
|
1800
|
+
/**
|
|
1801
|
+
* Check if input is valid
|
|
1802
|
+
*/
|
|
1803
|
+
this.checkValidity = () => {
|
|
1804
|
+
if (!this.readonly && this.input !== undefined) {
|
|
1805
|
+
const validity = this.input.checkValidity && this.input.checkValidity();
|
|
1806
|
+
// Set validity
|
|
1807
|
+
this.valid = validity;
|
|
1808
|
+
this.invalid = !validity;
|
|
1809
|
+
//Send event
|
|
1810
|
+
this.inputValid.emit(validity);
|
|
1811
|
+
}
|
|
1812
|
+
};
|
|
1813
|
+
/**
|
|
1814
|
+
* Check input errors
|
|
1815
|
+
*/
|
|
1816
|
+
this.checkError = () => {
|
|
1817
|
+
// Set error message
|
|
1818
|
+
this.errorMessage = undefined;
|
|
1819
|
+
if (!this.valid && this.input.validity.valueMissing) {
|
|
1820
|
+
this.errorMessage = messages.errors.required;
|
|
1821
|
+
}
|
|
1822
|
+
// Update class
|
|
1823
|
+
if (this.valid) {
|
|
1824
|
+
this.classList.delete(this.classError);
|
|
1825
|
+
}
|
|
1826
|
+
else {
|
|
1827
|
+
this.classList.add(this.classError);
|
|
1828
|
+
}
|
|
1829
|
+
};
|
|
1830
|
+
}
|
|
1831
|
+
handleValue(newValue) {
|
|
1832
|
+
if (newValue !== null) {
|
|
1833
|
+
this.readonlyValue = allItemsAreString(this.items) ? this.input.value : this.items.find(item => item.value === newValue).title;
|
|
1834
|
+
}
|
|
1835
|
+
else {
|
|
1836
|
+
this.readonlyValue = null;
|
|
1837
|
+
}
|
|
1838
|
+
this.valueChange.emit(newValue);
|
|
1839
|
+
}
|
|
1840
|
+
validateItems(newValue) {
|
|
1841
|
+
// String array
|
|
1842
|
+
if (allItemsAreString(newValue)) {
|
|
1843
|
+
this.valueExist = newValue.includes(this.value);
|
|
1844
|
+
this.options = newValue.map((item) => ({ title: item, value: item }));
|
|
1845
|
+
}
|
|
1846
|
+
// Object array
|
|
1847
|
+
else if (newValue && newValue.every(item => isOption$1(item))) {
|
|
1848
|
+
this.valueExist = newValue.map(item => item.value).includes(this.value);
|
|
1849
|
+
// Grouped object options
|
|
1850
|
+
if (newValue.some(item => item.group !== undefined)) {
|
|
1851
|
+
this.options = newValue.reduce(groupOptions, []);
|
|
1852
|
+
}
|
|
1853
|
+
// Standart object options
|
|
1854
|
+
else {
|
|
1855
|
+
this.options = newValue;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
else {
|
|
1859
|
+
throw new Error('<mg-input-select> prop "items" is required and all items must be the same type, string or Option.');
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
/**
|
|
1863
|
+
* Public method to display errors
|
|
1864
|
+
*
|
|
1865
|
+
* @returns {Promise<void>}
|
|
1866
|
+
*/
|
|
1867
|
+
async displayError() {
|
|
1868
|
+
this.checkValidity();
|
|
1869
|
+
this.checkError();
|
|
1870
|
+
}
|
|
1871
|
+
/*************
|
|
1872
|
+
* Lifecycle *
|
|
1873
|
+
*************/
|
|
1874
|
+
/**
|
|
1875
|
+
* Check if component props are well configured on init
|
|
1876
|
+
*
|
|
1877
|
+
* @returns {ReturnType<typeof setTimeout>} timeout
|
|
1878
|
+
*/
|
|
1879
|
+
componentWillLoad() {
|
|
1880
|
+
// Check items format
|
|
1881
|
+
this.validateItems(this.items);
|
|
1882
|
+
// Check validity when component is ready
|
|
1883
|
+
// return a promise to process action only in the FIRST render().
|
|
1884
|
+
// https://stenciljs.com/docs/component-lifecycle#componentwillload
|
|
1885
|
+
return setTimeout(() => {
|
|
1886
|
+
this.checkValidity();
|
|
1887
|
+
}, 0);
|
|
1888
|
+
}
|
|
1889
|
+
/**
|
|
1890
|
+
* Render
|
|
1891
|
+
*
|
|
1892
|
+
* @returns {HTMLElement} HTML Element
|
|
1893
|
+
*/
|
|
1894
|
+
render() {
|
|
1895
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, width: this.width, disabled: this.disabled, value: this.value, readonlyValue: this.readonlyValue, tooltip: this.tooltip, displayCharacterLeft: undefined, characterLeftTemplate: undefined, maxlength: undefined, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("select", { class: "mg-input__box", id: this.identifier, name: this.name, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, ref: el => (this.input = el) }, (!this.placeholderHide || !this.valueExist) && ( // In case passed value does not match any option we display the placeholder
|
|
1896
|
+
h("option", { value: "", disabled: this.placeholderDisabled && this.valueExist }, this.placeholder)), this.options.map(option => option.group !== undefined ? (h("optgroup", { label: option.group }, option.options.map(optgroup => (h("option", { value: optgroup.title, selected: JSON.stringify(this.value) === JSON.stringify(optgroup.value), disabled: optgroup.disabled }, optgroup.title))))) : (h("option", { value: option.title, selected: JSON.stringify(this.value) === JSON.stringify(option.value), disabled: option.disabled }, option.title))))));
|
|
1897
|
+
}
|
|
1898
|
+
static get watchers() { return {
|
|
1899
|
+
"value": ["handleValue"],
|
|
1900
|
+
"items": ["validateItems"]
|
|
1901
|
+
}; }
|
|
1902
|
+
};
|
|
1903
|
+
MgInputSelect.style = mgInputSelectCss;
|
|
1904
|
+
|
|
1905
|
+
const mgInputTextCss = ":host{display:block}.mg-input{display:-ms-flexbox;display:flex;-ms-flex-align:start;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input.is-not-valid{color:hsl(var(--color-danger))}.mg-input.is-not-valid .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input mg-input-title{-ms-flex-negative:var(--mg-inputs-shrink, 1);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{-ms-flex-direction:column;flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:-ms-flexbox;display:flex;-ms-flex-align:baseline;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{-ms-flex-negative:1;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:-ms-inline-flexbox;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:-ms-inline-flexbox;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-icon{display:-ms-flexbox;display:flex}.mg-input__input{display:-ms-flexbox;display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input+*{text-align:start;margin-top:0.5rem}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);width:100%;height:var(--default-size);-webkit-box-sizing:border-box;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)}.mg-input__box::-webkit-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::-moz-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:-ms-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::-ms-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{-webkit-box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5);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-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left: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-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.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){-ms-flex-pack:justify;justify-content:space-between}.mg-input.mg-input--width-full .mg-input__input-container{-ms-flex:auto;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{display:none}.mg-input.is-focused mg-character-left{display:block}.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__input{position:relative}.mg-input.mg-input--has-icon .mg-input__input>mg-icon{position:absolute;top:calc(var(--default-size) - var(--mg-icon-regular-size));left:var(--mg-inputs-spacer);color:var(--mg-inputs-color);-webkit-transform:translateY(-50%);transform:translateY(-50%)}.mg-input.mg-input--has-icon .mg-input__input .mg-input__box{padding-left:calc(var(--mg-icon-regular-size) + var(--mg-inputs-spacer) * 2)}";
|
|
1906
|
+
|
|
1907
|
+
const MgInputText = class {
|
|
1908
|
+
constructor(hostRef) {
|
|
1909
|
+
registerInstance(this, hostRef);
|
|
1910
|
+
this.valueChange = createEvent(this, "value-change", 7);
|
|
1911
|
+
this.inputValid = createEvent(this, "input-valid", 7);
|
|
1912
|
+
/************
|
|
1913
|
+
* Internal *
|
|
1914
|
+
************/
|
|
1915
|
+
// classes
|
|
1916
|
+
this.classFocus = 'is-focused';
|
|
1917
|
+
this.isInputGroupAppend = 'mg-input--is-input-group-append';
|
|
1918
|
+
this.classError = InputClass.ERROR;
|
|
1919
|
+
/**
|
|
1920
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
1921
|
+
* If not set, it will be created.
|
|
1922
|
+
*/
|
|
1923
|
+
this.identifier = createID('mg-input-text');
|
|
1924
|
+
/**
|
|
1925
|
+
* Input name
|
|
1926
|
+
* If not set the value equals the identifier
|
|
1927
|
+
*/
|
|
1928
|
+
this.name = this.identifier;
|
|
1929
|
+
/**
|
|
1930
|
+
* Input type
|
|
1931
|
+
*/
|
|
1932
|
+
this.type = 'text';
|
|
1933
|
+
/**
|
|
1934
|
+
* Define if label is visible
|
|
1935
|
+
*/
|
|
1936
|
+
this.labelHide = false;
|
|
1937
|
+
/**
|
|
1938
|
+
* Input max length
|
|
1939
|
+
*/
|
|
1940
|
+
this.maxlength = 400;
|
|
1941
|
+
/**
|
|
1942
|
+
* Define if input is required
|
|
1943
|
+
*/
|
|
1944
|
+
this.required = false;
|
|
1945
|
+
/**
|
|
1946
|
+
* Define if input is readonly
|
|
1947
|
+
*/
|
|
1948
|
+
this.readonly = false;
|
|
1949
|
+
/**
|
|
1950
|
+
* Define if input is disabled
|
|
1951
|
+
*/
|
|
1952
|
+
this.disabled = false;
|
|
1953
|
+
/**
|
|
1954
|
+
* Define input width
|
|
1955
|
+
*/
|
|
1956
|
+
this.width = 'full';
|
|
1957
|
+
/**
|
|
1958
|
+
* Define if component should display character left
|
|
1959
|
+
*/
|
|
1960
|
+
this.displayCharacterLeft = true;
|
|
1961
|
+
/**
|
|
1962
|
+
* Component classes
|
|
1963
|
+
*/
|
|
1964
|
+
this.classList = new ClassList(['mg-input--text']);
|
|
1965
|
+
/**
|
|
1966
|
+
* Handle input event
|
|
1967
|
+
*
|
|
1968
|
+
* @returns {void}
|
|
1969
|
+
*/
|
|
1970
|
+
this.handleInput = () => {
|
|
1971
|
+
this.checkValidity();
|
|
1972
|
+
this.value = this.input.value;
|
|
1973
|
+
};
|
|
1974
|
+
/**
|
|
1975
|
+
* Handle focus event
|
|
1976
|
+
*
|
|
1977
|
+
* @returns {void}
|
|
1978
|
+
*/
|
|
1979
|
+
this.handleFocus = () => {
|
|
1980
|
+
this.classList.add(this.classFocus);
|
|
1981
|
+
this.classList = new ClassList(this.classList.classes);
|
|
1982
|
+
};
|
|
1983
|
+
/**
|
|
1984
|
+
* Handle blur event
|
|
1985
|
+
*
|
|
1986
|
+
* @returns {void}
|
|
1987
|
+
*/
|
|
1988
|
+
this.handleBlur = () => {
|
|
1989
|
+
// Manage focus
|
|
1990
|
+
this.classList.delete(this.classFocus);
|
|
1991
|
+
this.classList = new ClassList(this.classList.classes);
|
|
1992
|
+
// Check validity
|
|
1993
|
+
this.checkValidity();
|
|
1994
|
+
this.checkError();
|
|
1995
|
+
};
|
|
1996
|
+
/**
|
|
1997
|
+
* Check if input is valid
|
|
1998
|
+
*
|
|
1999
|
+
* @returns {void}
|
|
2000
|
+
*/
|
|
2001
|
+
this.checkValidity = () => {
|
|
2002
|
+
if (!this.readonly && this.input !== undefined) {
|
|
2003
|
+
const validity = this.input.checkValidity();
|
|
2004
|
+
// Set validity
|
|
2005
|
+
this.valid = validity;
|
|
2006
|
+
this.invalid = !validity;
|
|
2007
|
+
//Send event
|
|
2008
|
+
this.inputValid.emit(validity);
|
|
2009
|
+
}
|
|
2010
|
+
};
|
|
2011
|
+
/**
|
|
2012
|
+
* Check input errors
|
|
2013
|
+
*
|
|
2014
|
+
* @returns {void}
|
|
2015
|
+
*/
|
|
2016
|
+
this.checkError = () => {
|
|
2017
|
+
// Set error message
|
|
2018
|
+
this.errorMessage = undefined;
|
|
2019
|
+
// Does not match pattern
|
|
2020
|
+
if (!this.valid && this.input.validity.patternMismatch) {
|
|
2021
|
+
this.errorMessage = this.patternErrorMessage;
|
|
2022
|
+
}
|
|
2023
|
+
// required
|
|
2024
|
+
else if (!this.valid && this.input.validity.valueMissing) {
|
|
2025
|
+
this.errorMessage = messages.errors.required;
|
|
2026
|
+
}
|
|
2027
|
+
// Update class
|
|
2028
|
+
if (this.valid) {
|
|
2029
|
+
this.classList.delete(this.classError);
|
|
2030
|
+
}
|
|
2031
|
+
else {
|
|
2032
|
+
this.classList.add(this.classError);
|
|
2033
|
+
}
|
|
2034
|
+
};
|
|
2035
|
+
/**
|
|
2036
|
+
* Validate patern configuration
|
|
2037
|
+
*
|
|
2038
|
+
* @returns {void}
|
|
2039
|
+
*/
|
|
2040
|
+
this.validatePattern = () => {
|
|
2041
|
+
if (this.pattern &&
|
|
2042
|
+
typeof this.pattern === 'string' &&
|
|
2043
|
+
this.pattern !== '' &&
|
|
2044
|
+
(this.patternErrorMessage === undefined || typeof this.patternErrorMessage !== 'string' || this.patternErrorMessage === '')) {
|
|
2045
|
+
throw new Error('<mg-input-text> prop "pattern" must be paired with the prop "patternErrorMessage"');
|
|
2046
|
+
}
|
|
2047
|
+
};
|
|
2048
|
+
/**
|
|
2049
|
+
* Validate append slot
|
|
2050
|
+
*
|
|
2051
|
+
* @returns {void}
|
|
2052
|
+
*/
|
|
2053
|
+
this.validateAppendSlot = () => {
|
|
2054
|
+
const slotAppendInput = Array.from(this.element.querySelectorAll('[slot="append-input"]'));
|
|
2055
|
+
if (slotAppendInput.length === 1) {
|
|
2056
|
+
this.classList.add(slotAppendInput[0].nodeName === 'MG-BUTTON' ? this.isInputGroupAppend : 'mg-input--is-append-input-slot-content');
|
|
2057
|
+
}
|
|
2058
|
+
else if (slotAppendInput.filter(slot => slot.nodeName === 'MG-BUTTON').length > 1) {
|
|
2059
|
+
this.classList.add(this.isInputGroupAppend);
|
|
2060
|
+
this.classList.add('mg-input--has-buttons-group-append');
|
|
2061
|
+
}
|
|
2062
|
+
};
|
|
2063
|
+
}
|
|
2064
|
+
handleValue(newValue) {
|
|
2065
|
+
this.valueChange.emit(newValue);
|
|
2066
|
+
}
|
|
2067
|
+
/**
|
|
2068
|
+
* Public method to play input focus
|
|
2069
|
+
*
|
|
2070
|
+
* @returns {Promise<void>}
|
|
2071
|
+
*/
|
|
2072
|
+
async setFocus() {
|
|
2073
|
+
this.input.focus();
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* Public method to display errors
|
|
2077
|
+
*
|
|
2078
|
+
* @returns {Promise<void>}
|
|
2079
|
+
*/
|
|
2080
|
+
async displayError() {
|
|
2081
|
+
this.checkValidity();
|
|
2082
|
+
this.checkError();
|
|
2083
|
+
}
|
|
2084
|
+
/*************
|
|
2085
|
+
* Lifecycle *
|
|
2086
|
+
*************/
|
|
2087
|
+
/**
|
|
2088
|
+
* Check if component props are well configured on init
|
|
2089
|
+
*
|
|
2090
|
+
* @returns {ReturnType<typeof setTimeout>} timeout
|
|
2091
|
+
*/
|
|
2092
|
+
componentWillLoad() {
|
|
2093
|
+
if (this.icon !== undefined) {
|
|
2094
|
+
this.classList.add('mg-input--has-icon');
|
|
2095
|
+
}
|
|
2096
|
+
this.validatePattern();
|
|
2097
|
+
this.validateAppendSlot();
|
|
2098
|
+
// Check validity when component is ready
|
|
2099
|
+
// return a promise to process action only in the FIRST render().
|
|
2100
|
+
// https://stenciljs.com/docs/component-lifecycle#componentwillload
|
|
2101
|
+
return setTimeout(() => {
|
|
2102
|
+
this.checkValidity();
|
|
2103
|
+
}, 0);
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Render
|
|
2107
|
+
*
|
|
2108
|
+
* @returns {HTMLElement} HTML Element
|
|
2109
|
+
*/
|
|
2110
|
+
render() {
|
|
2111
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, width: this.width, disabled: this.disabled, value: this.value, readonlyValue: undefined, tooltip: this.tooltip, displayCharacterLeft: this.displayCharacterLeft, characterLeftTemplate: this.characterLeftTemplate, maxlength: this.maxlength, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, this.icon !== undefined && h("mg-icon", { icon: this.icon }), h("input", { type: this.type, class: "mg-input__box", value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, maxlength: this.maxlength, disabled: this.disabled, required: this.required, pattern: this.pattern, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el => (this.input = el) }), h("slot", { name: "append-input" })));
|
|
2112
|
+
}
|
|
2113
|
+
get element() { return getElement(this); }
|
|
2114
|
+
static get watchers() { return {
|
|
2115
|
+
"value": ["handleValue"]
|
|
2116
|
+
}; }
|
|
2117
|
+
};
|
|
2118
|
+
MgInputText.style = mgInputTextCss;
|
|
2119
|
+
|
|
2120
|
+
const mgInputTextareaCss = ":host{display:block}.mg-input{display:-ms-flexbox;display:flex;-ms-flex-align:start;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input.is-not-valid{color:hsl(var(--color-danger))}.mg-input.is-not-valid .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input mg-input-title{-ms-flex-negative:var(--mg-inputs-shrink, 1);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{-ms-flex-direction:column;flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:-ms-flexbox;display:flex;-ms-flex-align:baseline;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{-ms-flex-negative:1;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:-ms-inline-flexbox;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:-ms-inline-flexbox;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-icon{display:-ms-flexbox;display:flex}.mg-input__input{display:-ms-flexbox;display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input+*{text-align:start;margin-top:0.5rem}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);width:100%;height:var(--default-size);-webkit-box-sizing:border-box;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)}.mg-input__box::-webkit-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::-moz-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:-ms-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::-ms-input-placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{-webkit-box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5);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-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left: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-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.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){-ms-flex-pack:justify;justify-content:space-between}.mg-input.mg-input--width-full .mg-input__input-container{-ms-flex:auto;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{display:none}.mg-input.is-focused mg-character-left{display:block}.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{height:auto}@-moz-document url-prefix(){.mg-input__box{overflow-x:hidden}}";
|
|
2121
|
+
|
|
2122
|
+
const MgInputTextarea = class {
|
|
2123
|
+
constructor(hostRef) {
|
|
2124
|
+
registerInstance(this, hostRef);
|
|
2125
|
+
this.valueChange = createEvent(this, "value-change", 7);
|
|
2126
|
+
this.inputValid = createEvent(this, "input-valid", 7);
|
|
2127
|
+
/************
|
|
2128
|
+
* Internal *
|
|
2129
|
+
************/
|
|
2130
|
+
// classes
|
|
2131
|
+
this.classFocus = 'is-focused';
|
|
2132
|
+
this.classError = InputClass.ERROR;
|
|
2133
|
+
/**
|
|
2134
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
2135
|
+
* If not set, it will be created.
|
|
2136
|
+
*/
|
|
2137
|
+
this.identifier = createID('mg-input-textarea');
|
|
2138
|
+
/**
|
|
2139
|
+
* Input name
|
|
2140
|
+
* If not set the value equals the identifier
|
|
2141
|
+
*/
|
|
2142
|
+
this.name = this.identifier;
|
|
2143
|
+
/**
|
|
2144
|
+
* Define if label is visible
|
|
2145
|
+
*/
|
|
2146
|
+
this.labelHide = false;
|
|
2147
|
+
/**
|
|
2148
|
+
* Input max length
|
|
2149
|
+
*/
|
|
2150
|
+
this.maxlength = 4000;
|
|
2151
|
+
/**
|
|
2152
|
+
* Define if input is required
|
|
2153
|
+
*/
|
|
2154
|
+
this.required = false;
|
|
2155
|
+
/**
|
|
2156
|
+
* Define if input is readonly
|
|
2157
|
+
*/
|
|
2158
|
+
this.readonly = false;
|
|
2159
|
+
/**
|
|
2160
|
+
* Define if input is disabled
|
|
2161
|
+
*/
|
|
2162
|
+
this.disabled = false;
|
|
2163
|
+
/**
|
|
2164
|
+
* Define input width
|
|
2165
|
+
*/
|
|
2166
|
+
this.width = 'full';
|
|
2167
|
+
/**
|
|
2168
|
+
* Define input pattern error message
|
|
2169
|
+
*/
|
|
2170
|
+
this.rows = 3;
|
|
2171
|
+
/**
|
|
2172
|
+
* Define if component should display character left
|
|
2173
|
+
*/
|
|
2174
|
+
this.displayCharacterLeft = true;
|
|
2175
|
+
/**
|
|
2176
|
+
* Component classes
|
|
2177
|
+
*/
|
|
2178
|
+
this.classList = new ClassList(['mg-input--textarea']);
|
|
2179
|
+
/**
|
|
2180
|
+
* Handle input event
|
|
2181
|
+
*/
|
|
2182
|
+
this.handleInput = () => {
|
|
2183
|
+
this.value = this.input.value;
|
|
2184
|
+
};
|
|
2185
|
+
/**
|
|
2186
|
+
* Handle focus event
|
|
2187
|
+
*/
|
|
2188
|
+
this.handleFocus = () => {
|
|
2189
|
+
this.classList.add(this.classFocus);
|
|
2190
|
+
this.classList = new ClassList(this.classList.classes);
|
|
2191
|
+
};
|
|
2192
|
+
/**
|
|
2193
|
+
* Handle blur event
|
|
2194
|
+
*/
|
|
2195
|
+
this.handleBlur = () => {
|
|
2196
|
+
// Manage focus
|
|
2197
|
+
this.classList.delete(this.classFocus);
|
|
2198
|
+
this.classList = new ClassList(this.classList.classes);
|
|
2199
|
+
// Check validity
|
|
2200
|
+
this.checkValidity();
|
|
2201
|
+
this.checkError();
|
|
2202
|
+
};
|
|
2203
|
+
/**
|
|
2204
|
+
* Get pattern validity
|
|
2205
|
+
* Pattern is not defined on textarea field : https://developer.mozilla.org/fr/docs/Web/HTML/Element/Textarea
|
|
2206
|
+
*
|
|
2207
|
+
* @returns {boolean} is pattern valid
|
|
2208
|
+
*/
|
|
2209
|
+
this.getPatternValidity = () => this.pattern === undefined || new RegExp(`^${this.pattern}$`, 'u').test(this.value);
|
|
2210
|
+
/**
|
|
2211
|
+
* Check if input is valid
|
|
2212
|
+
*/
|
|
2213
|
+
this.checkValidity = () => {
|
|
2214
|
+
if (!this.readonly && this.input !== undefined) {
|
|
2215
|
+
const validity = this.input.checkValidity && this.input.checkValidity() && this.getPatternValidity();
|
|
2216
|
+
// Set validity
|
|
2217
|
+
this.valid = validity;
|
|
2218
|
+
this.invalid = !validity;
|
|
2219
|
+
//Send event
|
|
2220
|
+
this.inputValid.emit(validity);
|
|
2221
|
+
}
|
|
2222
|
+
};
|
|
2223
|
+
/**
|
|
2224
|
+
* Check input errors
|
|
2225
|
+
*/
|
|
2226
|
+
this.checkError = () => {
|
|
2227
|
+
// Set error message
|
|
2228
|
+
this.errorMessage = undefined;
|
|
2229
|
+
// Does not match pattern
|
|
2230
|
+
if (!this.valid && !this.getPatternValidity()) {
|
|
2231
|
+
this.errorMessage = this.patternErrorMessage;
|
|
2232
|
+
}
|
|
2233
|
+
// required
|
|
2234
|
+
else if (!this.valid && this.input.validity.valueMissing) {
|
|
2235
|
+
this.errorMessage = messages.errors.required;
|
|
2236
|
+
}
|
|
2237
|
+
// Update class
|
|
2238
|
+
if (this.valid) {
|
|
2239
|
+
this.classList.delete(this.classError);
|
|
2240
|
+
}
|
|
2241
|
+
else {
|
|
2242
|
+
this.classList.add(this.classError);
|
|
2243
|
+
}
|
|
2244
|
+
};
|
|
2245
|
+
/**
|
|
2246
|
+
* Validate pattern configuration
|
|
2247
|
+
*/
|
|
2248
|
+
this.validatePattern = () => {
|
|
2249
|
+
if (this.pattern &&
|
|
2250
|
+
typeof this.pattern === 'string' &&
|
|
2251
|
+
this.pattern !== '' &&
|
|
2252
|
+
(this.patternErrorMessage === undefined || typeof this.patternErrorMessage !== 'string' || this.patternErrorMessage === '')) {
|
|
2253
|
+
throw new Error('<mg-input-textarea> prop "pattern" must be paired with the prop "patternErrorMessage"');
|
|
2254
|
+
}
|
|
2255
|
+
};
|
|
2256
|
+
}
|
|
2257
|
+
handleValue(newValue) {
|
|
2258
|
+
this.checkValidity();
|
|
2259
|
+
this.valueChange.emit(newValue);
|
|
2260
|
+
}
|
|
2261
|
+
/**
|
|
2262
|
+
* Public method to display errors
|
|
2263
|
+
*
|
|
2264
|
+
* @returns {Promise<void>}
|
|
2265
|
+
*/
|
|
2266
|
+
async displayError() {
|
|
2267
|
+
this.checkValidity();
|
|
2268
|
+
this.checkError();
|
|
2269
|
+
}
|
|
2270
|
+
/*************
|
|
2271
|
+
* Lifecycle *
|
|
2272
|
+
*************/
|
|
2273
|
+
/**
|
|
2274
|
+
* Check if component props are well configured on init
|
|
2275
|
+
*
|
|
2276
|
+
* @returns {ReturnType<typeof setTimeout>} timeout
|
|
2277
|
+
*/
|
|
2278
|
+
componentWillLoad() {
|
|
2279
|
+
this.validatePattern();
|
|
2280
|
+
// Check validity when component is ready
|
|
2281
|
+
// return a promise to process action only in the FIRST render().
|
|
2282
|
+
// https://stenciljs.com/docs/component-lifecycle#componentwillload
|
|
2283
|
+
return setTimeout(() => {
|
|
2284
|
+
this.checkValidity();
|
|
2285
|
+
}, 0);
|
|
2286
|
+
}
|
|
2287
|
+
/**
|
|
2288
|
+
* Render
|
|
2289
|
+
*
|
|
2290
|
+
* @returns {HTMLElement} HTML Element
|
|
2291
|
+
*/
|
|
2292
|
+
render() {
|
|
2293
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, width: this.width, disabled: this.disabled, value: this.value, readonlyValue: undefined, tooltip: this.tooltip, displayCharacterLeft: this.displayCharacterLeft, characterLeftTemplate: this.characterLeftTemplate, maxlength: this.maxlength, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("textarea", { class: "mg-input__box", 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 => (this.input = el) })));
|
|
2294
|
+
}
|
|
2295
|
+
static get watchers() { return {
|
|
2296
|
+
"value": ["handleValue"]
|
|
2297
|
+
}; }
|
|
2298
|
+
};
|
|
2299
|
+
MgInputTextarea.style = mgInputTextareaCss;
|
|
2300
|
+
|
|
2301
|
+
const mgInputTitleCss = ".is-asterisk.sc-mg-input-title{color:hsl(var(--color-danger))}legend.mg-input-title.sc-mg-input-title{padding-left:0;padding-right:0}.mg-input-title__required.sc-mg-input-title{display:var(--mg-input-title-display, unset)}";
|
|
2302
|
+
|
|
2303
|
+
const MgInputTitle = class {
|
|
2304
|
+
constructor(hostRef) {
|
|
2305
|
+
registerInstance(this, hostRef);
|
|
2306
|
+
/**
|
|
2307
|
+
* Switch from label to fieldset sementic
|
|
2308
|
+
*/
|
|
2309
|
+
this.isLegend = false;
|
|
2310
|
+
/**
|
|
2311
|
+
* Component parent tagname
|
|
2312
|
+
*/
|
|
2313
|
+
this.tagName = 'label';
|
|
2314
|
+
this.getTagName = () => {
|
|
2315
|
+
this.tagName = this.isLegend ? 'legend' : 'label';
|
|
2316
|
+
};
|
|
2317
|
+
}
|
|
2318
|
+
/*************
|
|
2319
|
+
* Lifecycle *
|
|
2320
|
+
*************/
|
|
2321
|
+
/**
|
|
2322
|
+
* Init tag name
|
|
2323
|
+
*
|
|
2324
|
+
* @returns {void}
|
|
2325
|
+
*/
|
|
2326
|
+
componentWillLoad() {
|
|
2327
|
+
this.getTagName();
|
|
2328
|
+
}
|
|
2329
|
+
/**
|
|
2330
|
+
* Render
|
|
2331
|
+
*
|
|
2332
|
+
* @returns {HTMLElement} HTML Element
|
|
2333
|
+
*/
|
|
2334
|
+
render() {
|
|
2335
|
+
const TagName = this.tagName;
|
|
2336
|
+
// \u00A0 represent a
|
|
2337
|
+
return (h(TagName, { class: "mg-input-title", htmlFor: this.isLegend ? undefined : this.identifier }, h("slot", null), this.required && (h("span", { class: "mg-input-title__required" }, "\u00A0", h("span", { class: "is-asterisk" }, "*")))));
|
|
2338
|
+
}
|
|
2339
|
+
};
|
|
2340
|
+
MgInputTitle.style = mgInputTitleCss;
|
|
2341
|
+
|
|
2342
|
+
const mgInputToggleCss = ":host{display:block}.mg-input{display:-ms-flexbox;display:flex;-ms-flex-align:start;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input.is-not-valid{color:hsl(var(--color-danger))}.mg-input.is-not-valid .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input mg-input-title{-ms-flex-negative:var(--mg-inputs-shrink, 1);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{-ms-flex-direction:column;flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:-ms-flexbox;display:flex;-ms-flex-align:baseline;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{-ms-flex-negative:1;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:-ms-inline-flexbox;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:-ms-inline-flexbox;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-icon{display:-ms-flexbox;display:flex}.mg-input__input{display:-ms-flexbox;display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input+*{text-align:start;margin-top:0.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.mg-input--toggle .mg-input__input-container{-ms-flex:auto;flex:auto;min-width:0}.mg-input__button-toggle{display:-ms-flexbox;display:flex;padding:0.2rem;min-width:0;background-color:hsl(var(--color-light));border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:calc((var(--font-size) * var(--line-height) + 2 * (0.7rem + var(--mg-inputs-border-width))) / var(--mg-input-toggle-border-radius-ratio));font-size:inherit;line-height:inherit;cursor:pointer}.mg-input__button-toggle:disabled{cursor:default}.mg-input__toggle-item-container{padding:0.5rem 0.9rem;border:0;-webkit-box-sizing:border-box;box-sizing:border-box;border-radius:calc((var(--font-size) * var(--line-height) + 1rem) / var(--mg-input-toggle-border-radius-ratio));background-color:unset;font-weight:unset;color:hsl(var(--color-dark));white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.mg-input__toggle-item-container:first-of-type{font-weight:600;color:hsl(var(--color-info));background-color:hsl(var(--color-info-h), calc(var(--color-info-s) - 64%), calc(var(--color-info-l) + 55%))}.mg-input.mg-input--toggle-is-active .mg-input__toggle-item-container:first-of-type{background-color:unset;font-weight:unset;color:hsl(var(--color-dark))}.mg-input.mg-input--toggle-is-active .mg-input__toggle-item-container:last-of-type{font-weight:600;color:hsl(var(--color-info));background-color:hsl(var(--color-info-h), calc(var(--color-info-s) - 64%), calc(var(--color-info-l) + 55%))}.mg-input.mg-input--toggle-icon .mg-input__toggle-item-container{display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center;width:calc(var(--font-size) * var(--line-height) + 1rem);height:calc(var(--font-size) * var(--line-height) + 1rem);padding:0;visibility:hidden}.mg-input.mg-input--toggle-icon .mg-input__toggle-item-container:first-of-type{visibility:visible}.mg-input.mg-input--toggle-icon .mg-input__toggle-item-container ::slotted(mg-icon){display:-ms-flexbox;display:flex}.mg-input.mg-input--toggle-icon.mg-input--toggle-is-active .mg-input__toggle-item-container:first-of-type{visibility:hidden}.mg-input.mg-input--toggle-icon.mg-input--toggle-is-active .mg-input__toggle-item-container:last-of-type{visibility:visible}.mg-input.mg-input--toggle-on-off .mg-input__toggle-item-container:first-of-type{font-weight:600;color:hsl(var(--color-dark));background-color:hsl(var(--color-dark-h), calc(var(--color-dark-s) - 30%), calc(var(--color-dark-l) + 75%))}.mg-input.mg-input--toggle-on-off.mg-input--toggle-is-active .mg-input__toggle-item-container:first-of-type{background-color:unset;font-weight:unset;color:hsl(var(--color-dark))}.mg-input.mg-input--toggle-readonly .mg-input__button-toggle{border-color:transparent;background-color:transparent;cursor:initial}.mg-input.mg-input--toggle-readonly .mg-input__toggle-item-container:last-of-type{display:none}.mg-input.mg-input--toggle-readonly.mg-input--toggle-is-active .mg-input__toggle-item-container:first-of-type{display:none}.mg-input.mg-input--toggle-readonly.mg-input--toggle-is-active .mg-input__toggle-item-container:last-of-type{display:-ms-flexbox;display:flex}.mg-input.mg-input--toggle-disabled .mg-input__button-toggle{opacity:0.3}";
|
|
2343
|
+
|
|
2344
|
+
/**
|
|
2345
|
+
* type Option validation function
|
|
2346
|
+
*
|
|
2347
|
+
* @param {ToggleValue} option radio option
|
|
2348
|
+
* @returns {boolean} toggle option type is valid
|
|
2349
|
+
*/
|
|
2350
|
+
const isOption = (option) => typeof option === 'object' && typeof option.title === 'string' && option.value !== undefined;
|
|
2351
|
+
const MgInputToggle = class {
|
|
2352
|
+
constructor(hostRef) {
|
|
2353
|
+
registerInstance(this, hostRef);
|
|
2354
|
+
this.valueChange = createEvent(this, "value-change", 7);
|
|
2355
|
+
this.inputValid = createEvent(this, "input-valid", 7);
|
|
2356
|
+
/************
|
|
2357
|
+
* Internal *
|
|
2358
|
+
************/
|
|
2359
|
+
// classes
|
|
2360
|
+
this.classReadonly = 'mg-input--toggle-readonly';
|
|
2361
|
+
this.classDisabled = 'mg-input--toggle-disabled';
|
|
2362
|
+
this.classIsActive = 'mg-input--toggle-is-active';
|
|
2363
|
+
/**
|
|
2364
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
2365
|
+
* If not set, it will be created.
|
|
2366
|
+
*/
|
|
2367
|
+
this.identifier = createID('mg-input-toggle');
|
|
2368
|
+
/**
|
|
2369
|
+
* Input name
|
|
2370
|
+
* If not set the value equals the identifier
|
|
2371
|
+
*/
|
|
2372
|
+
this.name = this.identifier;
|
|
2373
|
+
/**
|
|
2374
|
+
* Define if label is visible
|
|
2375
|
+
*/
|
|
2376
|
+
this.labelHide = false;
|
|
2377
|
+
/**
|
|
2378
|
+
* Define if toggle have on/off style
|
|
2379
|
+
*/
|
|
2380
|
+
this.isOnOff = false;
|
|
2381
|
+
/**
|
|
2382
|
+
* Define if toggle display icon
|
|
2383
|
+
*/
|
|
2384
|
+
this.isIcon = false;
|
|
2385
|
+
/**
|
|
2386
|
+
* Define if input is readonly
|
|
2387
|
+
*/
|
|
2388
|
+
this.readonly = false;
|
|
2389
|
+
/**
|
|
2390
|
+
* Define if input is disabled
|
|
2391
|
+
*/
|
|
2392
|
+
this.disabled = false;
|
|
2393
|
+
/**
|
|
2394
|
+
* Component classes
|
|
2395
|
+
*/
|
|
2396
|
+
this.classList = new ClassList(['mg-input--toggle']);
|
|
2397
|
+
/**
|
|
2398
|
+
* Checked internal value
|
|
2399
|
+
*/
|
|
2400
|
+
this.checked = false;
|
|
2401
|
+
/**
|
|
2402
|
+
* Change checked value
|
|
2403
|
+
*
|
|
2404
|
+
* @returns {void}
|
|
2405
|
+
*/
|
|
2406
|
+
this.toggleChecked = () => {
|
|
2407
|
+
this.checked = !this.checked;
|
|
2408
|
+
};
|
|
2409
|
+
/**
|
|
2410
|
+
* Slots validation
|
|
2411
|
+
*
|
|
2412
|
+
* @returns {void}
|
|
2413
|
+
*/
|
|
2414
|
+
this.validateSlots = () => {
|
|
2415
|
+
const slots = Array.from(this.element.children);
|
|
2416
|
+
if (slots.length !== 2) {
|
|
2417
|
+
throw new Error('<mg-input-toggle> 2 slots are required.');
|
|
2418
|
+
}
|
|
2419
|
+
else if (!this.isIcon) {
|
|
2420
|
+
// Due to text-overflow set to ellipsis
|
|
2421
|
+
// we need to ensure that slot element have title to display value on mouse over
|
|
2422
|
+
slots.forEach(slot => slot.setAttribute('title', slot.textContent));
|
|
2423
|
+
}
|
|
2424
|
+
};
|
|
2425
|
+
}
|
|
2426
|
+
handleValue(newValue) {
|
|
2427
|
+
// Swich to the right option
|
|
2428
|
+
this.setChecked();
|
|
2429
|
+
// Emit value-change event
|
|
2430
|
+
this.valueChange.emit(newValue);
|
|
2431
|
+
}
|
|
2432
|
+
validateItems(newValue) {
|
|
2433
|
+
if (typeof newValue === 'object' && this.items.length !== 2) {
|
|
2434
|
+
throw new Error('<mg-input-toggle> prop "items" require 2 items.');
|
|
2435
|
+
}
|
|
2436
|
+
// String array
|
|
2437
|
+
else if (allItemsAreString(newValue)) {
|
|
2438
|
+
this.options = newValue.map(item => ({ title: item, value: item }));
|
|
2439
|
+
}
|
|
2440
|
+
// Object array
|
|
2441
|
+
else if (newValue && newValue.every(item => isOption(item))) {
|
|
2442
|
+
this.options = newValue;
|
|
2443
|
+
}
|
|
2444
|
+
else {
|
|
2445
|
+
throw new Error('<mg-input-toggle> prop "items" is required and all items must be the same type: ToggleValue.');
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
handleIsOnOff(newValue) {
|
|
2449
|
+
if (newValue)
|
|
2450
|
+
this.classList.add(`mg-input--toggle-on-off`);
|
|
2451
|
+
}
|
|
2452
|
+
handleIsIcon(newValue) {
|
|
2453
|
+
if (newValue)
|
|
2454
|
+
this.classList.add(`mg-input--toggle-icon`);
|
|
2455
|
+
}
|
|
2456
|
+
handleReadonly(newValue) {
|
|
2457
|
+
if (newValue)
|
|
2458
|
+
this.classList.add(this.classReadonly);
|
|
2459
|
+
else
|
|
2460
|
+
this.classList.delete(this.classReadonly);
|
|
2461
|
+
}
|
|
2462
|
+
handleDisabled(newValue) {
|
|
2463
|
+
if (newValue)
|
|
2464
|
+
this.classList.add(this.classDisabled);
|
|
2465
|
+
else
|
|
2466
|
+
this.classList.delete(this.classDisabled);
|
|
2467
|
+
}
|
|
2468
|
+
handleChecked(newValue) {
|
|
2469
|
+
// style
|
|
2470
|
+
if (newValue)
|
|
2471
|
+
this.classList.add(this.classIsActive);
|
|
2472
|
+
else
|
|
2473
|
+
this.classList.delete(this.classIsActive);
|
|
2474
|
+
// update value
|
|
2475
|
+
this.value = this.options[newValue ? 1 : 0].value;
|
|
2476
|
+
}
|
|
2477
|
+
/**
|
|
2478
|
+
* set checked state
|
|
2479
|
+
*
|
|
2480
|
+
* @returns {void}
|
|
2481
|
+
*/
|
|
2482
|
+
setChecked() {
|
|
2483
|
+
// has "value" props type is not a boolean, it is bind/render as an attributes/props
|
|
2484
|
+
// true props will be represent by "true" string so we convert it has boolean
|
|
2485
|
+
// true attribute will be represent by "" string so we convert it has boolean
|
|
2486
|
+
// https://stenciljs.com/docs/properties
|
|
2487
|
+
if (['', 'true'].includes(this.value) && this.options.find(option => option.value) !== undefined) {
|
|
2488
|
+
this.value = true;
|
|
2489
|
+
}
|
|
2490
|
+
this.checked = this.value === this.options[1].value;
|
|
2491
|
+
}
|
|
2492
|
+
/*************
|
|
2493
|
+
* Lifecycle *
|
|
2494
|
+
*************/
|
|
2495
|
+
/**
|
|
2496
|
+
* Check if component props are well configured on init
|
|
2497
|
+
*/
|
|
2498
|
+
componentWillLoad() {
|
|
2499
|
+
// Check items format
|
|
2500
|
+
this.validateItems(this.items);
|
|
2501
|
+
// Check slots
|
|
2502
|
+
this.validateSlots();
|
|
2503
|
+
// init checked value
|
|
2504
|
+
this.setChecked();
|
|
2505
|
+
// apply handler
|
|
2506
|
+
this.handleIsOnOff(this.isOnOff);
|
|
2507
|
+
this.handleIsIcon(this.isIcon);
|
|
2508
|
+
this.handleReadonly(this.readonly);
|
|
2509
|
+
this.handleDisabled(this.disabled);
|
|
2510
|
+
}
|
|
2511
|
+
/**
|
|
2512
|
+
* Render
|
|
2513
|
+
*
|
|
2514
|
+
* @returns {HTMLElement} HTML Element
|
|
2515
|
+
*/
|
|
2516
|
+
render() {
|
|
2517
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: undefined, readonly: undefined, width: undefined, disabled: this.disabled, value: this.value, readonlyValue: undefined, tooltip: !this.readonly && this.tooltip, displayCharacterLeft: undefined, characterLeftTemplate: undefined, maxlength: undefined, helpText: this.helpText, errorMessage: undefined, isFieldset: false }, h("button", { type: "button", role: "switch", "aria-checked": this.checked, "aria-readonly": this.disabled || this.readonly, id: this.identifier, class: "mg-input__button-toggle", disabled: this.disabled || this.readonly, onClick: this.toggleChecked }, h("span", { "aria-hidden": "true", class: "mg-input__toggle-item-container" }, h("slot", { name: "item-1" })), h("span", { "aria-hidden": "true", class: "mg-input__toggle-item-container" }, h("slot", { name: "item-2" })))));
|
|
2518
|
+
}
|
|
2519
|
+
get element() { return getElement(this); }
|
|
2520
|
+
static get watchers() { return {
|
|
2521
|
+
"value": ["handleValue"],
|
|
2522
|
+
"items": ["validateItems"],
|
|
2523
|
+
"isOnOff": ["handleIsOnOff"],
|
|
2524
|
+
"isIcon": ["handleIsIcon"],
|
|
2525
|
+
"readonly": ["handleReadonly"],
|
|
2526
|
+
"disabled": ["handleDisabled"],
|
|
2527
|
+
"checked": ["handleChecked"]
|
|
2528
|
+
}; }
|
|
2529
|
+
};
|
|
2530
|
+
MgInputToggle.style = mgInputToggleCss;
|
|
2531
|
+
|
|
2532
|
+
/**
|
|
2533
|
+
* List of all possibles message variants
|
|
2534
|
+
*/
|
|
2535
|
+
const variants$1 = ['info', 'warning', 'success', 'danger'];
|
|
2536
|
+
|
|
2537
|
+
const mgMessageCss = ".mg-message{display:inline-block;position:relative;-webkit-box-sizing:border-box;box-sizing:border-box;min-height:var(--default-size);overflow:hidden;background-color:white;border-radius:var(--mg-message-border-radius);-webkit-box-shadow:var(--box-shadow);box-shadow:var(--box-shadow)}.mg-message::before{content:\"\";position:absolute;top:0;left:0;width:0.3rem;height:100%}.mg-message.mg-message--info::before{background-color:hsl(var(--color-info))}.mg-message.mg-message--info .mg-message__icon{color:hsl(var(--color-info))}.mg-message.mg-message--warning::before{background-color:hsl(var(--color-warning))}.mg-message.mg-message--warning .mg-message__icon{color:hsl(var(--color-warning))}.mg-message.mg-message--success::before{background-color:hsl(var(--color-success))}.mg-message.mg-message--success .mg-message__icon{color:hsl(var(--color-success))}.mg-message.mg-message--danger::before{background-color:hsl(var(--color-danger))}.mg-message.mg-message--danger .mg-message__icon{color:hsl(var(--color-danger))}.mg-message.mg-message--close-button{padding-right:3.4rem}.mg-message.mg-message--hide{display:none}.mg-message ::slotted(*){margin:0;padding:0}.mg-message__icon{position:absolute;top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2);left:1.3rem;line-height:1}.mg-message__content{display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;-ms-flex-pack:end;justify-content:flex-end;-ms-flex-line-pack:stretch;align-content:stretch;padding:0 1rem 0 3.8rem}.mg-message__content-slot{-ms-flex-positive:1;flex-grow:1;margin:0.84rem 0}.mg-message__content-separator{display:inline-block;width:4.5rem;height:0}.mg-message__content-actions-slot{padding:1rem 0;text-align:right}.mg-message__close-button{position:absolute;top:0;right:0}.mg-message,mg-message{max-width:100%}";
|
|
2538
|
+
|
|
2539
|
+
const MgMessage = class {
|
|
2540
|
+
constructor(hostRef) {
|
|
2541
|
+
registerInstance(this, hostRef);
|
|
2542
|
+
this.componentShow = createEvent(this, "component-show", 7);
|
|
2543
|
+
this.componentHide = createEvent(this, "component-hide", 7);
|
|
2544
|
+
/************
|
|
2545
|
+
* Internal *
|
|
2546
|
+
************/
|
|
2547
|
+
this.closeButtonId = '';
|
|
2548
|
+
// Stored timer setted when hide action is run from setTimeOut
|
|
2549
|
+
this.storedTimer = null;
|
|
2550
|
+
/**
|
|
2551
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
2552
|
+
* If not set, it will be created.
|
|
2553
|
+
*/
|
|
2554
|
+
this.identifier = createID('mg-message');
|
|
2555
|
+
/**
|
|
2556
|
+
* Message variant
|
|
2557
|
+
*/
|
|
2558
|
+
this.variant = variants$1[0]; // info
|
|
2559
|
+
/**
|
|
2560
|
+
* Define if message has a cross button
|
|
2561
|
+
* RG 01: https://jira.mgdis.fr/browse/PDA9-140
|
|
2562
|
+
*/
|
|
2563
|
+
this.closeButton = false;
|
|
2564
|
+
/**
|
|
2565
|
+
* Define if message is hidden
|
|
2566
|
+
*/
|
|
2567
|
+
this.hide = false;
|
|
2568
|
+
/**
|
|
2569
|
+
* Component classes
|
|
2570
|
+
*/
|
|
2571
|
+
this.classList = new ClassList(['mg-message']);
|
|
2572
|
+
/**
|
|
2573
|
+
* Define if component is using actions slot
|
|
2574
|
+
*/
|
|
2575
|
+
this.hasActions = false;
|
|
2576
|
+
/**
|
|
2577
|
+
* Handle close button
|
|
2578
|
+
*/
|
|
2579
|
+
this.handleClose = () => {
|
|
2580
|
+
this.hide = true;
|
|
2581
|
+
};
|
|
2582
|
+
/**
|
|
2583
|
+
* Hide component whith delay
|
|
2584
|
+
*/
|
|
2585
|
+
this.hideWithDelay = () => {
|
|
2586
|
+
if (this.delay > 0 && this.hide !== true) {
|
|
2587
|
+
this.storedTimer = setTimeout(() => (this.hide = true), this.delay * 1000);
|
|
2588
|
+
}
|
|
2589
|
+
else if (this.storedTimer !== null) {
|
|
2590
|
+
clearTimeout(this.storedTimer);
|
|
2591
|
+
}
|
|
2592
|
+
};
|
|
2593
|
+
/**
|
|
2594
|
+
* Get icon corresponding to variant
|
|
2595
|
+
*
|
|
2596
|
+
* @returns {string} icon
|
|
2597
|
+
*/
|
|
2598
|
+
this.getIcon = () => {
|
|
2599
|
+
switch (this.variant) {
|
|
2600
|
+
case 'info':
|
|
2601
|
+
return 'info-circle';
|
|
2602
|
+
case 'warning':
|
|
2603
|
+
return 'exclamation-triangle';
|
|
2604
|
+
case 'success':
|
|
2605
|
+
return 'check-circle';
|
|
2606
|
+
case 'danger':
|
|
2607
|
+
return 'exclamation-circle';
|
|
2608
|
+
}
|
|
2609
|
+
};
|
|
2610
|
+
}
|
|
2611
|
+
validateDelay(newValue) {
|
|
2612
|
+
if (newValue && newValue < 2) {
|
|
2613
|
+
throw new Error(`<mg-message> prop "delay" must be greater than 2 seconds.`);
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
validateVariant(newValue, oldValue) {
|
|
2617
|
+
if (!variants$1.includes(newValue)) {
|
|
2618
|
+
throw new Error(`<mg-message> prop "variant" must be one of : ${variants$1.join(', ')}`);
|
|
2619
|
+
}
|
|
2620
|
+
if (oldValue !== undefined) {
|
|
2621
|
+
this.classList.delete(`mg-message--${oldValue}`);
|
|
2622
|
+
}
|
|
2623
|
+
this.classList.add(`mg-message--${this.variant}`);
|
|
2624
|
+
}
|
|
2625
|
+
validateCloseButton(newValue) {
|
|
2626
|
+
if (newValue && this.hasActions) {
|
|
2627
|
+
this.closeButton = false;
|
|
2628
|
+
throw new Error('<mg-message> prop "close-button" can\'t be used with the actions slot.');
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
validateHide(newValue) {
|
|
2632
|
+
if (newValue) {
|
|
2633
|
+
this.componentHide.emit();
|
|
2634
|
+
this.classList.add('mg-message--hide');
|
|
2635
|
+
}
|
|
2636
|
+
else {
|
|
2637
|
+
this.componentShow.emit();
|
|
2638
|
+
this.classList.delete('mg-message--hide');
|
|
2639
|
+
}
|
|
2640
|
+
this.hideWithDelay();
|
|
2641
|
+
}
|
|
2642
|
+
/*************
|
|
2643
|
+
* Lifecycle *
|
|
2644
|
+
*************/
|
|
2645
|
+
/**
|
|
2646
|
+
* Check if component props are well configured on init
|
|
2647
|
+
*/
|
|
2648
|
+
componentWillLoad() {
|
|
2649
|
+
this.validateVariant(this.variant);
|
|
2650
|
+
// Check if close button is an can be activated
|
|
2651
|
+
this.hasActions = this.element.querySelector('[slot="actions"]') !== null;
|
|
2652
|
+
this.validateCloseButton(this.closeButton);
|
|
2653
|
+
if (this.closeButton) {
|
|
2654
|
+
this.classList.add('mg-message--close-button');
|
|
2655
|
+
this.closeButtonId = `${this.identifier}-close-button`;
|
|
2656
|
+
}
|
|
2657
|
+
this.validateDelay(this.delay);
|
|
2658
|
+
this.validateHide(this.hide);
|
|
2659
|
+
}
|
|
2660
|
+
/**
|
|
2661
|
+
* Render
|
|
2662
|
+
*
|
|
2663
|
+
* @returns {HTMLElement} HTML Element
|
|
2664
|
+
*/
|
|
2665
|
+
render() {
|
|
2666
|
+
return (h("div", { id: this.identifier, class: this.classList.join(), role: this.variant === 'info' ? 'status' : 'alert' }, h("span", { class: "mg-message__icon" }, h("mg-icon", { icon: this.getIcon() })), h("div", { class: "mg-message__content" }, h("span", { class: "mg-message__content-slot" }, h("slot", null)), this.hasActions && h("span", { class: "mg-message__content-separator" }), this.hasActions && (h("span", { class: "mg-message__content-actions-slot" }, h("slot", { name: "actions" })))), this.closeButton && (h("span", { class: "mg-message__close-button" }, h("mg-button", { identifier: this.closeButtonId, "is-icon": true, variant: "flat", label: messages.message.closeButton, onClick: this.handleClose }, h("mg-icon", { icon: "cross" }))))));
|
|
2667
|
+
}
|
|
2668
|
+
get element() { return getElement(this); }
|
|
2669
|
+
static get watchers() { return {
|
|
2670
|
+
"delay": ["validateDelay"],
|
|
2671
|
+
"variant": ["validateVariant"],
|
|
2672
|
+
"closeButton": ["validateCloseButton"],
|
|
2673
|
+
"hide": ["validateHide"]
|
|
2674
|
+
}; }
|
|
2675
|
+
};
|
|
2676
|
+
MgMessage.style = mgMessageCss;
|
|
2677
|
+
|
|
2678
|
+
var NavigationAction;
|
|
2679
|
+
(function (NavigationAction) {
|
|
2680
|
+
NavigationAction["NEXT"] = "next";
|
|
2681
|
+
NavigationAction["PREVIOUS"] = "previous";
|
|
2682
|
+
})(NavigationAction || (NavigationAction = {}));
|
|
2683
|
+
|
|
2684
|
+
const mgPaginationCss = ".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-pagination__nav{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-direction:row;flex-direction:row}.mg-pagination__nav mg-input-select{margin-right:0.5rem}.mg-pagination__button{display:-ms-flexbox;display:flex}.mg-pagination__button:first-of-type{margin-right:1rem}.mg-pagination__button:last-of-type{margin-left:1rem}";
|
|
2685
|
+
|
|
2686
|
+
/**
|
|
2687
|
+
* Range generator
|
|
2688
|
+
*
|
|
2689
|
+
* start by get the range length, add "+ 1" to include last value, ex: Math.ceil((3 + 1 - 1) / 1) => 3
|
|
2690
|
+
* then with Array(Math.ceil...) we get the final array with empty values, ex: Array(Math.ceil(2 + 1 - 1) / 1)) => [empty, empty, empty]
|
|
2691
|
+
* then with Array(Math.ceil...).keys() we get the Array Iterator from empty values
|
|
2692
|
+
* then with Array.from(Array(...)) we get the complete array with "index" values instead of "empty" values
|
|
2693
|
+
* ex: Array.from(Array(Math.ceil((2 + 1 - 1) / 1) || 1).keys()) => [0, 1, 2]
|
|
2694
|
+
* finaly we map values from "start" range and apply the "step" coefficiant,
|
|
2695
|
+
* ex: Array.from(Array(Math.ceil((2 + 1 - 1) / 1) || 1).keys()).map(x => 1 + x * 1) => [1, 2, 3]
|
|
2696
|
+
*
|
|
2697
|
+
* range(1, 1) = [1]
|
|
2698
|
+
* range(1, 5) = [1, 2, 3, 4, 5]
|
|
2699
|
+
* range(10, 20, 2) = [10, 12, 14, 16, 18, 20]
|
|
2700
|
+
*
|
|
2701
|
+
* @param {number} start start range
|
|
2702
|
+
* @param {number} end start end
|
|
2703
|
+
* @param {number} step step size
|
|
2704
|
+
* @returns {number[]} range numbers
|
|
2705
|
+
*/
|
|
2706
|
+
const range = (start, end, step = 1) => Array.from(Array(Math.ceil((end + 1 - start) / step)).keys()).map(x => start + x * step);
|
|
2707
|
+
const MgPagination = class {
|
|
2708
|
+
constructor(hostRef) {
|
|
2709
|
+
registerInstance(this, hostRef);
|
|
2710
|
+
this.currentPageChange = createEvent(this, "current-page-change", 7);
|
|
2711
|
+
/**************
|
|
2712
|
+
* Decorators *
|
|
2713
|
+
**************/
|
|
2714
|
+
/**
|
|
2715
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
2716
|
+
* If not set, it will be created.
|
|
2717
|
+
*/
|
|
2718
|
+
this.identifier = createID('mg-pagination');
|
|
2719
|
+
/**
|
|
2720
|
+
* Panignation label. Is a short description.
|
|
2721
|
+
* Customize default value can be usefull to improve accessibility
|
|
2722
|
+
*/
|
|
2723
|
+
this.label = 'pagination';
|
|
2724
|
+
/**
|
|
2725
|
+
* Component total pages
|
|
2726
|
+
*/
|
|
2727
|
+
this.totalPages = 1;
|
|
2728
|
+
/**
|
|
2729
|
+
* Component current page
|
|
2730
|
+
*/
|
|
2731
|
+
this.currentPage = 1;
|
|
2732
|
+
/**
|
|
2733
|
+
* Change current page from target
|
|
2734
|
+
*
|
|
2735
|
+
* @param {number} target target page
|
|
2736
|
+
* @returns {void}
|
|
2737
|
+
*/
|
|
2738
|
+
this.goToPage = (target) => {
|
|
2739
|
+
this.currentPage = target;
|
|
2740
|
+
};
|
|
2741
|
+
/************
|
|
2742
|
+
* Handlers *
|
|
2743
|
+
************/
|
|
2744
|
+
/**
|
|
2745
|
+
* select handler
|
|
2746
|
+
*
|
|
2747
|
+
* @param {InputEvent} event value change event
|
|
2748
|
+
* @returns {void}
|
|
2749
|
+
*/
|
|
2750
|
+
this.handleSelect = (event) => {
|
|
2751
|
+
const to = Number(event.target.value);
|
|
2752
|
+
this.goToPage(to > 0 ? to : 1);
|
|
2753
|
+
};
|
|
2754
|
+
/**
|
|
2755
|
+
* Go to 'previous/next' page button handler
|
|
2756
|
+
*
|
|
2757
|
+
* @param {string} action navigation action
|
|
2758
|
+
* @returns {void}
|
|
2759
|
+
*/
|
|
2760
|
+
this.handleGoToPage = (action) => {
|
|
2761
|
+
this.goToPage(action === NavigationAction.NEXT ? this.currentPage + 1 : this.currentPage - 1);
|
|
2762
|
+
};
|
|
2763
|
+
}
|
|
2764
|
+
validateTotalPages(newValue) {
|
|
2765
|
+
if (newValue < 1) {
|
|
2766
|
+
throw new Error('<mg-pagination> prop "totalPages" must be greater than 0');
|
|
2767
|
+
}
|
|
2768
|
+
}
|
|
2769
|
+
validateCurrentPage(newValue) {
|
|
2770
|
+
if (newValue < 1) {
|
|
2771
|
+
throw new Error('<mg-pagination> prop "currentPage" must be greater than 0');
|
|
2772
|
+
}
|
|
2773
|
+
else if (newValue > this.totalPages) {
|
|
2774
|
+
throw new Error('<mg-pagination> prop "currentPage" can not be greater than total page');
|
|
2775
|
+
}
|
|
2776
|
+
this.currentPageChange.emit(newValue);
|
|
2777
|
+
}
|
|
2778
|
+
/*************
|
|
2779
|
+
* Lifecycle *
|
|
2780
|
+
*************/
|
|
2781
|
+
/**
|
|
2782
|
+
* Check if props are well configured on init
|
|
2783
|
+
*
|
|
2784
|
+
* @returns {void}
|
|
2785
|
+
*/
|
|
2786
|
+
componentWillLoad() {
|
|
2787
|
+
this.validateTotalPages(this.totalPages);
|
|
2788
|
+
this.validateCurrentPage(this.currentPage);
|
|
2789
|
+
}
|
|
2790
|
+
/**
|
|
2791
|
+
* Render
|
|
2792
|
+
*
|
|
2793
|
+
* @returns {HTMLElement} HTML Element
|
|
2794
|
+
*/
|
|
2795
|
+
render() {
|
|
2796
|
+
const navigationActionButton = (disabled, action) => (h("mg-button", { identifier: `${this.identifier}-button-${action}`, class: "mg-pagination__button", label: messages.pagination[`${action}Page`],
|
|
2797
|
+
// eslint-disable-next-line react/jsx-no-bind
|
|
2798
|
+
onClick: () => this.handleGoToPage(action), disabled: disabled, variant: "flat" }, action === NavigationAction.PREVIOUS && h("mg-icon", { icon: "chevron-left" }), messages.general[action], action === NavigationAction.NEXT && h("mg-icon", { icon: "chevron-right" })));
|
|
2799
|
+
return (h("nav", { "aria-label": this.label, id: this.identifier, class: "mg-pagination__nav" }, navigationActionButton(this.currentPage <= 1, NavigationAction.PREVIOUS), h("mg-input-select", { identifier: `${this.identifier}-select`, items: range(1, this.totalPages).map(page => page.toString()), label: messages.pagination.selectPage, "label-hide": true, "on-value-change": this.handleSelect, value: this.currentPage.toString(), "placeholder-hide": true }), h("span", { class: "sr-only" }, messages.pagination.page, " ", this.currentPage), h("span", null, "/ ", this.totalPages, " ", this.totalPages > 1 ? messages.pagination.pages : messages.pagination.page), navigationActionButton(this.currentPage >= this.totalPages, NavigationAction.NEXT)));
|
|
2800
|
+
}
|
|
2801
|
+
static get watchers() { return {
|
|
2802
|
+
"totalPages": ["validateTotalPages"],
|
|
2803
|
+
"currentPage": ["validateCurrentPage"]
|
|
2804
|
+
}; }
|
|
2805
|
+
};
|
|
2806
|
+
MgPagination.style = mgPaginationCss;
|
|
2807
|
+
|
|
2808
|
+
const mgPanelCss = ".mg-panel{background-color:hsl(var(--mg-panel-background));border-radius:var(--mg-panel-border-radius);-webkit-box-shadow:var(--box-shadow);box-shadow:var(--box-shadow)}.mg-panel__header{display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;-ms-flex-pack:justify;justify-content:space-between;padding:0 1rem 0 0.3rem;-ms-flex-align:center;align-items:center}.mg-panel__header-left,.mg-panel__header-right{display:-ms-flexbox;display:flex;-ms-flex-positive:1;flex-grow:1;margin:0.3rem 0}.mg-panel__header-left mg-input-text{-ms-flex-positive:1;flex-grow:1}.mg-panel__collapse-button{font-family:var(--font-family-heading);font-size:1.4rem;font-weight:500;margin:0 0.3rem 0 0}.mg-panel__content{padding:1.5rem}.mg-panel ::slotted([slot=header-right]){display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;gap:1rem;margin-left:auto}";
|
|
2809
|
+
|
|
2810
|
+
const MgPanel = class {
|
|
2811
|
+
constructor(hostRef) {
|
|
2812
|
+
registerInstance(this, hostRef);
|
|
2813
|
+
this.titleChange = createEvent(this, "title-change", 7);
|
|
2814
|
+
/**************
|
|
2815
|
+
* Decorators *
|
|
2816
|
+
**************/
|
|
2817
|
+
/**
|
|
2818
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
2819
|
+
* If not set, it will be created.
|
|
2820
|
+
*/
|
|
2821
|
+
this.identifier = createID('mg-panel');
|
|
2822
|
+
/**
|
|
2823
|
+
* Panel is opened
|
|
2824
|
+
*/
|
|
2825
|
+
this.expanded = false;
|
|
2826
|
+
/**
|
|
2827
|
+
* Panel title is editabled
|
|
2828
|
+
*/
|
|
2829
|
+
this.titleEditable = false;
|
|
2830
|
+
/**
|
|
2831
|
+
* Component classes
|
|
2832
|
+
*/
|
|
2833
|
+
this.classList = new ClassList(['mg-panel']);
|
|
2834
|
+
/**
|
|
2835
|
+
* Title is in edition mode
|
|
2836
|
+
*/
|
|
2837
|
+
this.isEditing = false;
|
|
2838
|
+
/************
|
|
2839
|
+
* Methods *
|
|
2840
|
+
************/
|
|
2841
|
+
/**
|
|
2842
|
+
* Toggle is editing state
|
|
2843
|
+
*
|
|
2844
|
+
* @returns {void}
|
|
2845
|
+
*/
|
|
2846
|
+
this.toggleIsEditing = () => {
|
|
2847
|
+
this.isEditing = !this.isEditing;
|
|
2848
|
+
};
|
|
2849
|
+
/************
|
|
2850
|
+
* Handlers *
|
|
2851
|
+
************/
|
|
2852
|
+
/**
|
|
2853
|
+
* Collapse button click handler
|
|
2854
|
+
*
|
|
2855
|
+
* @returns {void}
|
|
2856
|
+
*/
|
|
2857
|
+
this.handleCollapseButton = () => {
|
|
2858
|
+
this.expanded = !this.expanded;
|
|
2859
|
+
};
|
|
2860
|
+
/**
|
|
2861
|
+
* Edit button click handler
|
|
2862
|
+
*
|
|
2863
|
+
* @returns {void}
|
|
2864
|
+
*/
|
|
2865
|
+
this.handleEditButton = () => {
|
|
2866
|
+
this.toggleIsEditing();
|
|
2867
|
+
};
|
|
2868
|
+
/**
|
|
2869
|
+
* Update title handler
|
|
2870
|
+
*
|
|
2871
|
+
* @param {CustomEvent<string>} event input value change event
|
|
2872
|
+
* @returns {void}
|
|
2873
|
+
*/
|
|
2874
|
+
this.handleUpdateTitle = (event) => {
|
|
2875
|
+
this.updatedPanelTitle = event.detail;
|
|
2876
|
+
};
|
|
2877
|
+
/**
|
|
2878
|
+
* Cancel edition button handler
|
|
2879
|
+
*
|
|
2880
|
+
* @returns {void}
|
|
2881
|
+
*/
|
|
2882
|
+
this.handleCancelEditButton = () => {
|
|
2883
|
+
this.updatedPanelTitle = undefined;
|
|
2884
|
+
this.toggleIsEditing();
|
|
2885
|
+
};
|
|
2886
|
+
/**
|
|
2887
|
+
* Validate edition button handler
|
|
2888
|
+
*
|
|
2889
|
+
* @returns {void}
|
|
2890
|
+
*/
|
|
2891
|
+
this.handleValidateEditButton = () => {
|
|
2892
|
+
if (this.updatedPanelTitle !== undefined)
|
|
2893
|
+
this.panelTitle = this.updatedPanelTitle;
|
|
2894
|
+
this.toggleIsEditing();
|
|
2895
|
+
};
|
|
2896
|
+
/*************
|
|
2897
|
+
* Lifecycle *
|
|
2898
|
+
*************/
|
|
2899
|
+
/**
|
|
2900
|
+
* Header left conditional render
|
|
2901
|
+
*
|
|
2902
|
+
* @typedef {HTMLElement} HTMLMgButtonElement
|
|
2903
|
+
* @returns {HTMLMgButtonElement | HTMLElement | HTMLElement[]} header left element
|
|
2904
|
+
*/
|
|
2905
|
+
this.headerLeft = () => {
|
|
2906
|
+
const collapseButton = () => (h("mg-button", { onClick: this.handleCollapseButton, variant: "flat", class: "mg-panel__collapse-button", identifier: `${this.identifier}-collapse-button`, expanded: this.expanded, controls: `${this.identifier}-content` }, h("mg-icon", { icon: this.expanded ? 'chevron-up' : 'chevron-down' }), !this.isEditing && this.panelTitle));
|
|
2907
|
+
if (this.titleEditable && !this.isEditing) {
|
|
2908
|
+
return [
|
|
2909
|
+
collapseButton(),
|
|
2910
|
+
h("mg-button", { "is-icon": true, variant: "secondary", label: messages.panel.editLabel, onClick: this.handleEditButton, identifier: `${this.identifier}-edit-button` }, h("mg-icon", { icon: "pen" })),
|
|
2911
|
+
];
|
|
2912
|
+
}
|
|
2913
|
+
if (this.titleEditable && this.isEditing) {
|
|
2914
|
+
return [
|
|
2915
|
+
collapseButton(),
|
|
2916
|
+
h("mg-input-text", { label: messages.panel.editLabel, "label-hide": true, value: this.panelTitle, "onValue-change": this.handleUpdateTitle, displayCharacterLeft: false, identifier: `${this.identifier}-edition-input`, ref: el => (this.editInputElement = el) }, h("mg-button", { slot: "append-input", label: messages.general.cancel, "is-icon": true, variant: "secondary", onClick: this.handleCancelEditButton, identifier: `${this.identifier}-edition-button-cancel` }, h("mg-icon", { icon: "cross" })), h("mg-button", { slot: "append-input", label: messages.general.validate, "is-icon": true, variant: "secondary", onClick: this.handleValidateEditButton, identifier: `${this.identifier}-edition-button-validate` }, h("mg-icon", { icon: "check" }))),
|
|
2917
|
+
];
|
|
2918
|
+
}
|
|
2919
|
+
return collapseButton();
|
|
2920
|
+
};
|
|
2921
|
+
}
|
|
2922
|
+
handelTileChange(newValue) {
|
|
2923
|
+
this.titleChange.emit(newValue);
|
|
2924
|
+
}
|
|
2925
|
+
/**
|
|
2926
|
+
* Edit DOM after render
|
|
2927
|
+
*
|
|
2928
|
+
* @returns {void}
|
|
2929
|
+
*/
|
|
2930
|
+
componentDidRender() {
|
|
2931
|
+
// when we are editing we get focus on edition input
|
|
2932
|
+
if (this.isEditing) {
|
|
2933
|
+
this.editInputElement.setFocus();
|
|
2934
|
+
}
|
|
2935
|
+
}
|
|
2936
|
+
/**
|
|
2937
|
+
* Render component
|
|
2938
|
+
*
|
|
2939
|
+
* @returns {HTMLElement} html element
|
|
2940
|
+
*/
|
|
2941
|
+
render() {
|
|
2942
|
+
return (h("section", { class: this.classList.join(), id: this.identifier }, h("header", { class: "mg-panel__header", id: `${this.identifier}-header` }, h("div", { class: "mg-panel__header-left" }, this.headerLeft()), h("div", { class: "mg-panel__header-right" }, h("slot", { name: "header-right" }))), h("article", { class: "mg-panel__content", id: `${this.identifier}-content`, "aria-labelledby": `${this.identifier}-header`, hidden: !this.expanded }, h("slot", null))));
|
|
2943
|
+
}
|
|
2944
|
+
static get watchers() { return {
|
|
2945
|
+
"panelTitle": ["handelTileChange"]
|
|
2946
|
+
}; }
|
|
2947
|
+
};
|
|
2948
|
+
MgPanel.style = mgPanelCss;
|
|
2949
|
+
|
|
2950
|
+
/**
|
|
2951
|
+
* List of all possibles sizes
|
|
2952
|
+
*/
|
|
2953
|
+
const sizes = ['regular', 'large'];
|
|
2954
|
+
|
|
2955
|
+
const mgTabsCss = ".mg-tabs.mg-tabs--size-regular.sc-mg-tabs .mg-tabs__navigation-button.sc-mg-tabs{padding:calc(1rem + 0.3rem) calc(1rem * 1.3) 1rem}.mg-tabs.mg-tabs--size-large.sc-mg-tabs .mg-tabs__navigation-button.sc-mg-tabs{padding:calc(1.8rem + 0.3rem) calc(1.8rem * 1.3) 1.8rem}.mg-tabs__header.sc-mg-tabs{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-wrap:wrap;flex-wrap:wrap}.mg-tabs__navigation-button.sc-mg-tabs{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-webkit-column-gap:0.5rem;-moz-column-gap:0.5rem;column-gap:0.5rem;background:none;border:none;border-bottom:0.3rem solid transparent;color:hsl(var(--color-dark));line-height:var(--line-height);cursor:pointer}.mg-tabs__navigation-button.sc-mg-tabs:disabled,.mg-tabs__navigation-button--disabled.sc-mg-tabs{cursor:default;opacity:30%}.mg-tabs__navigation-button.sc-mg-tabs:hover:not(:disabled),.mg-tabs__navigation-button.sc-mg-tabs:focus:not(:disabled){background-color:hsla(var(--color-info-h), var(--color-info-s), var(--color-info-l), 10%)}.mg-tabs__navigation-button.mg-tabs__navigation-button--active.sc-mg-tabs{color:hsl(var(--color-info));border-bottom-color:hsl(var(--color-info));font-weight:700}.mg-tabs__content-container.sc-mg-tabs:focus-visible{outline:none}";
|
|
2956
|
+
|
|
2957
|
+
/**
|
|
2958
|
+
* type TabItem validation function
|
|
2959
|
+
*
|
|
2960
|
+
* @param {TabItem} tab tab item
|
|
2961
|
+
* @returns {boolean} tab item type is valid
|
|
2962
|
+
*/
|
|
2963
|
+
const isTabItem = (tab) => typeof tab === 'object' && typeof tab.label === 'string';
|
|
2964
|
+
const MgTabs = class {
|
|
2965
|
+
constructor(hostRef) {
|
|
2966
|
+
registerInstance(this, hostRef);
|
|
2967
|
+
/**
|
|
2968
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
2969
|
+
* If not set, it will be created.
|
|
2970
|
+
*/
|
|
2971
|
+
this.identifier = createID('mg-tabs');
|
|
2972
|
+
/**
|
|
2973
|
+
* Define tabs size
|
|
2974
|
+
*/
|
|
2975
|
+
this.size = 'regular';
|
|
2976
|
+
/**
|
|
2977
|
+
* Active tab number
|
|
2978
|
+
* default: first is 1
|
|
2979
|
+
*/
|
|
2980
|
+
this.activeTab = 1;
|
|
2981
|
+
/**
|
|
2982
|
+
* Component tabs
|
|
2983
|
+
*/
|
|
2984
|
+
this.tabs = [];
|
|
2985
|
+
/**
|
|
2986
|
+
* Component classes
|
|
2987
|
+
*/
|
|
2988
|
+
this.classList = new ClassList(['mg-tabs']);
|
|
2989
|
+
/**
|
|
2990
|
+
* Handle click events on tabs
|
|
2991
|
+
*
|
|
2992
|
+
* @param {MouseEvent} event mouse event
|
|
2993
|
+
*/
|
|
2994
|
+
this.handleClick = (event) => {
|
|
2995
|
+
const tabId = event.currentTarget.getAttribute('data-index');
|
|
2996
|
+
this.activeTab = Number(tabId);
|
|
2997
|
+
};
|
|
2998
|
+
/**
|
|
2999
|
+
* Handle keyboard event on tabs
|
|
3000
|
+
*
|
|
3001
|
+
* @param {MouseEvent} event mouse event
|
|
3002
|
+
* @returns {void}
|
|
3003
|
+
*/
|
|
3004
|
+
this.handleKeydown = (event) => {
|
|
3005
|
+
let tabId = Number(event.target.getAttribute('data-index'));
|
|
3006
|
+
const parent = event.target.parentElement;
|
|
3007
|
+
// change selected id from key code
|
|
3008
|
+
// /* IE FIX */ delete 'Right'
|
|
3009
|
+
if (['ArrowRight', 'Right'].includes(event.key)) {
|
|
3010
|
+
tabId++;
|
|
3011
|
+
// /* IE FIX */ delete 'Left'
|
|
3012
|
+
}
|
|
3013
|
+
else if (['ArrowLeft', 'Left'].includes(event.key)) {
|
|
3014
|
+
tabId--;
|
|
3015
|
+
}
|
|
3016
|
+
// get selected tab
|
|
3017
|
+
const selectedTab = parent.querySelector(`[data-index="${tabId}"]`);
|
|
3018
|
+
// apply selected tab if exist
|
|
3019
|
+
if (selectedTab !== null) {
|
|
3020
|
+
selectedTab.focus();
|
|
3021
|
+
this.activeTab = tabId;
|
|
3022
|
+
}
|
|
3023
|
+
};
|
|
3024
|
+
/**
|
|
3025
|
+
* Validate slots setting
|
|
3026
|
+
*/
|
|
3027
|
+
this.validateSlots = () => {
|
|
3028
|
+
const slots = Array.from(this.element.children).filter(slot => { var _a; return (_a = slot.getAttribute('slot')) === null || _a === void 0 ? void 0 : _a.includes('tab_content-'); });
|
|
3029
|
+
if (slots.length !== this.tabs.length) {
|
|
3030
|
+
throw new Error('<mg-tabs> Must have slots counts equal to tabs count.');
|
|
3031
|
+
}
|
|
3032
|
+
};
|
|
3033
|
+
}
|
|
3034
|
+
validateSize(newValue) {
|
|
3035
|
+
if (!sizes.includes(newValue)) {
|
|
3036
|
+
throw new Error(`<mg-tabs> prop "size" must be one of : ${sizes.join(', ')}`);
|
|
3037
|
+
}
|
|
3038
|
+
this.classList.add(`mg-tabs--size-${this.size}`);
|
|
3039
|
+
}
|
|
3040
|
+
validateItems(newValue) {
|
|
3041
|
+
// String array
|
|
3042
|
+
if (allItemsAreString(newValue)) {
|
|
3043
|
+
this.tabs = newValue.map(item => ({ label: item, disabled: false }));
|
|
3044
|
+
}
|
|
3045
|
+
// Object array
|
|
3046
|
+
else if (newValue && newValue.every(item => isTabItem(item))) {
|
|
3047
|
+
this.tabs = newValue;
|
|
3048
|
+
}
|
|
3049
|
+
else {
|
|
3050
|
+
throw new Error('<mg-tabs> prop "items" is required and all items must be the same type: TabItem.');
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
validateActiveTab(newValue) {
|
|
3054
|
+
if (Number(newValue) < 1 || Number(newValue) > this.tabs.length) {
|
|
3055
|
+
throw new Error('<mg-tabs> prop "activeTab" must be between 1 and tabs length.');
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3058
|
+
/*************
|
|
3059
|
+
* Lifecycle *
|
|
3060
|
+
*************/
|
|
3061
|
+
/**
|
|
3062
|
+
* Check if component props are well configured on init
|
|
3063
|
+
*
|
|
3064
|
+
* @returns {void}
|
|
3065
|
+
*/
|
|
3066
|
+
componentWillLoad() {
|
|
3067
|
+
// Check tabs format
|
|
3068
|
+
this.validateItems(this.items);
|
|
3069
|
+
this.validateActiveTab(this.activeTab);
|
|
3070
|
+
this.validateSize(this.size);
|
|
3071
|
+
this.validateSlots();
|
|
3072
|
+
}
|
|
3073
|
+
/**
|
|
3074
|
+
* Render
|
|
3075
|
+
*
|
|
3076
|
+
* @returns {HTMLElement} HTML Element
|
|
3077
|
+
*/
|
|
3078
|
+
render() {
|
|
3079
|
+
return (h(Host, null, h("div", { class: this.classList.join() }, h("header", { role: "tablist", "aria-label": this.label, class: "mg-tabs__header" }, this.tabs.map((tab, index) => {
|
|
3080
|
+
const tabIndex = index + 1;
|
|
3081
|
+
return (h("button", { role: "tab", id: `${this.identifier}-${tabIndex}`, class: {
|
|
3082
|
+
'mg-tabs__navigation-button': true,
|
|
3083
|
+
'mg-tabs__navigation-button--active': tabIndex === this.activeTab,
|
|
3084
|
+
'mg-tabs__navigation-button--disabled': tab.disabled,
|
|
3085
|
+
}, tabindex: tabIndex === this.activeTab ? 0 : -1, "aria-selected": (tabIndex === this.activeTab).toString(), "aria-controls": `pannel-${tabIndex}`, onClick: this.handleClick, onKeyDown: this.handleKeydown, "data-index": tabIndex, disabled: tab.disabled }, tab.icon !== undefined && h("mg-icon", { icon: tab.icon }), tab.label, tab.badge !== undefined && h("mg-badge", { variant: "info", value: tab.badge.value, label: tab.badge.label })));
|
|
3086
|
+
})), this.tabs.map((_tab, index) => {
|
|
3087
|
+
const tabIndex = index + 1;
|
|
3088
|
+
return (h("article", { role: "tabpanel", id: `pannel-${tabIndex}`, hidden: tabIndex !== this.activeTab, "aria-labelledby": `${this.identifier}-${this.activeTab}`, tabindex: tabIndex === this.activeTab ? 0 : -1, class: "mg-tabs__content-container" }, h("slot", { name: `tab_content-${tabIndex}` })));
|
|
3089
|
+
}))));
|
|
3090
|
+
}
|
|
3091
|
+
get element() { return getElement(this); }
|
|
3092
|
+
static get watchers() { return {
|
|
3093
|
+
"size": ["validateSize"],
|
|
3094
|
+
"items": ["validateItems"],
|
|
3095
|
+
"activeTab": ["validateActiveTab"]
|
|
3096
|
+
}; }
|
|
3097
|
+
};
|
|
3098
|
+
MgTabs.style = mgTabsCss;
|
|
3099
|
+
|
|
3100
|
+
/**
|
|
3101
|
+
* List of all possibles variants
|
|
3102
|
+
*/
|
|
3103
|
+
const variants = ['primary', 'secondary', 'success', 'warning', 'danger', 'info'];
|
|
3104
|
+
|
|
3105
|
+
const mgTagCss = ".mg-tag{padding:calc((var(--mg-tag-height) - 0.2rem - var(--mg-tag-font-size) * var(--line-height)) / 2) 0.6rem;min-height:var(--mg-tag-height);-webkit-box-sizing:border-box;box-sizing:border-box;border-radius:var(--mg-tag-border-radius);border:0.1rem solid;font-size:var(--mg-tag-font-size);font-weight:600;text-align:center}.mg-tag.mg-tag--primary{background-color:hsl(var(--color-dark));border-color:hsl(var(--color-dark));color:hsl(var(--color-light))}.mg-tag.mg-tag--primary.mg-tag--outline{background-color:transparent;color:hsl(var(--color-dark))}.mg-tag.mg-tag--secondary{background-color:hsl(var(--color-light));border-color:hsl(var(--color-light));color:hsl(var(--color-dark))}.mg-tag.mg-tag--secondary.mg-tag--outline{background-color:transparent;color:hsl(var(--color-light))}.mg-tag.mg-tag--success{background-color:hsl(var(--color-success));border-color:hsl(var(--color-success));color:hsl(var(--color-dark))}.mg-tag.mg-tag--success.mg-tag--outline{background-color:transparent;color:hsl(var(--color-success))}.mg-tag.mg-tag--warning{background-color:hsl(var(--color-warning));border-color:hsl(var(--color-warning));color:hsl(var(--color-dark))}.mg-tag.mg-tag--warning.mg-tag--outline{background-color:transparent;color:hsl(var(--color-warning))}.mg-tag.mg-tag--danger{background-color:hsl(var(--color-danger));border-color:hsl(var(--color-danger));color:hsl(var(--color-light))}.mg-tag.mg-tag--danger.mg-tag--outline{background-color:transparent;color:hsl(var(--color-danger))}.mg-tag.mg-tag--info{background-color:hsl(var(--color-info));border-color:hsl(var(--color-info));color:hsl(var(--color-light))}.mg-tag.mg-tag--info.mg-tag--outline{background-color:transparent;color:hsl(var(--color-info))}.mg-tag,mg-tag{display:inline-block;vertical-align:middle}";
|
|
3106
|
+
|
|
3107
|
+
const MgTag = class {
|
|
3108
|
+
constructor(hostRef) {
|
|
3109
|
+
registerInstance(this, hostRef);
|
|
3110
|
+
/**
|
|
3111
|
+
* Define button variant
|
|
3112
|
+
*/
|
|
3113
|
+
this.variant = variants[0]; // info
|
|
3114
|
+
/**
|
|
3115
|
+
* Component classes
|
|
3116
|
+
*/
|
|
3117
|
+
this.classList = new ClassList(['mg-tag']);
|
|
3118
|
+
}
|
|
3119
|
+
validateVariant(newValue) {
|
|
3120
|
+
if (!variants.includes(newValue)) {
|
|
3121
|
+
throw new Error(`<mg-tag> prop "variant" must be one of : ${variants.join(', ')}.`);
|
|
3122
|
+
}
|
|
3123
|
+
this.classList.add(`mg-tag--${this.variant}`);
|
|
3124
|
+
}
|
|
3125
|
+
validateOutline(newValue) {
|
|
3126
|
+
if (newValue)
|
|
3127
|
+
this.classList.add(`mg-tag--outline`);
|
|
3128
|
+
}
|
|
3129
|
+
/*************
|
|
3130
|
+
* Lifecycle *
|
|
3131
|
+
*************/
|
|
3132
|
+
/**
|
|
3133
|
+
* Check if props are well configured on init
|
|
3134
|
+
*
|
|
3135
|
+
* @returns {void}
|
|
3136
|
+
*/
|
|
3137
|
+
componentWillLoad() {
|
|
3138
|
+
this.validateVariant(this.variant);
|
|
3139
|
+
this.validateOutline(this.outline);
|
|
3140
|
+
}
|
|
3141
|
+
/**
|
|
3142
|
+
* Render
|
|
3143
|
+
*
|
|
3144
|
+
* @returns {HTMLElement} HTML Element
|
|
3145
|
+
*/
|
|
3146
|
+
render() {
|
|
3147
|
+
return (h("span", { class: this.classList.join() }, h("slot", null)));
|
|
3148
|
+
}
|
|
3149
|
+
static get watchers() { return {
|
|
3150
|
+
"variant": ["validateVariant"],
|
|
3151
|
+
"outline": ["validateOutline"]
|
|
3152
|
+
}; }
|
|
3153
|
+
};
|
|
3154
|
+
MgTag.style = mgTagCss;
|
|
3155
|
+
|
|
3156
|
+
const mgTooltipCss = ".sc-mg-tooltip-h{display:inline-block}.mg-tooltip.sc-mg-tooltip{display:none;padding:0.5rem 0.8rem;z-index:9999;border-radius:var(--mg-tooltip-border-radius);background-color:hsl(var(--mg-tooltip-background-color));color:hsl(var(--mg-tooltip-font-color));text-align:start}.mg-tooltip[data-show].sc-mg-tooltip{display:block}.mg-tooltip.sc-mg-tooltip .mg-tooltip__arrow.sc-mg-tooltip,.mg-tooltip.sc-mg-tooltip .mg-tooltip__arrow.sc-mg-tooltip::before{position:absolute;width:0.8rem;height:0.8rem;z-index:9999;background:inherit}.mg-tooltip.sc-mg-tooltip .mg-tooltip__arrow.sc-mg-tooltip{visibility:hidden}.mg-tooltip.sc-mg-tooltip .mg-tooltip__arrow.sc-mg-tooltip::before{visibility:visible;content:\"\";-webkit-transform:rotate(45deg);transform:rotate(45deg)}.mg-tooltip[data-popper-placement^=top].sc-mg-tooltip>.mg-tooltip__arrow.sc-mg-tooltip{bottom:-4px}.mg-tooltip[data-popper-placement^=bottom].sc-mg-tooltip>.mg-tooltip__arrow.sc-mg-tooltip{top:-4px}.mg-tooltip[data-popper-placement^=left].sc-mg-tooltip>.mg-tooltip__arrow.sc-mg-tooltip{right:-4px}.mg-tooltip[data-popper-placement^=right].sc-mg-tooltip>.mg-tooltip__arrow.sc-mg-tooltip{left:-4px}";
|
|
3157
|
+
|
|
3158
|
+
const MgTooltip = class {
|
|
3159
|
+
constructor(hostRef) {
|
|
3160
|
+
registerInstance(this, hostRef);
|
|
3161
|
+
/**
|
|
3162
|
+
* Sets an `id` attribute.
|
|
3163
|
+
* Needed by the input for accessibility `aria-decribedby`.
|
|
3164
|
+
*/
|
|
3165
|
+
this.identifier = createID('mg-tooltip');
|
|
3166
|
+
/**
|
|
3167
|
+
* Tooltip placement
|
|
3168
|
+
*/
|
|
3169
|
+
this.placement = 'bottom';
|
|
3170
|
+
/**
|
|
3171
|
+
* Display tooltip
|
|
3172
|
+
*/
|
|
3173
|
+
this.display = false;
|
|
3174
|
+
/**
|
|
3175
|
+
* Disable tooltip
|
|
3176
|
+
*/
|
|
3177
|
+
this.disabled = false;
|
|
3178
|
+
/**
|
|
3179
|
+
* Show tooltip
|
|
3180
|
+
*
|
|
3181
|
+
* @returns {void}
|
|
3182
|
+
*/
|
|
3183
|
+
this.show = () => {
|
|
3184
|
+
// Make the tooltip visible
|
|
3185
|
+
this.tooltip.setAttribute('data-show', '');
|
|
3186
|
+
// Enable the event listeners
|
|
3187
|
+
this.popper.setOptions(options => (Object.assign(Object.assign({}, options), { modifiers: [...options.modifiers, { name: 'eventListeners', enabled: true }] })));
|
|
3188
|
+
// Update its position
|
|
3189
|
+
this.popper.update();
|
|
3190
|
+
};
|
|
3191
|
+
/**
|
|
3192
|
+
* Hide tooltip
|
|
3193
|
+
*
|
|
3194
|
+
* @returns {void}
|
|
3195
|
+
*/
|
|
3196
|
+
this.hide = () => {
|
|
3197
|
+
// Hide the tooltip
|
|
3198
|
+
this.tooltip.removeAttribute('data-show');
|
|
3199
|
+
// Disable the event listeners
|
|
3200
|
+
this.popper.setOptions(options => (Object.assign(Object.assign({}, options), { modifiers: [...options.modifiers, { name: 'eventListeners', enabled: false }] })));
|
|
3201
|
+
};
|
|
3202
|
+
}
|
|
3203
|
+
handleDisplay(newVal) {
|
|
3204
|
+
if (newVal) {
|
|
3205
|
+
this.show();
|
|
3206
|
+
}
|
|
3207
|
+
else {
|
|
3208
|
+
this.hide();
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
/*************
|
|
3212
|
+
* Lifecycle *
|
|
3213
|
+
*************/
|
|
3214
|
+
/**
|
|
3215
|
+
* Get slotted element
|
|
3216
|
+
* Check if it already contain an interactive element, if not we need to add a tabIndex attribute
|
|
3217
|
+
* We need to attach the focused element to the tooltip (aria-describedby)
|
|
3218
|
+
*
|
|
3219
|
+
* @returns {void}
|
|
3220
|
+
*/
|
|
3221
|
+
componentDidLoad() {
|
|
3222
|
+
var _a;
|
|
3223
|
+
// Get tooltip element
|
|
3224
|
+
this.tooltip = this.element.querySelector(`#${this.identifier}`);
|
|
3225
|
+
// get slotted element
|
|
3226
|
+
const slotElement = this.element.firstElementChild;
|
|
3227
|
+
// Get interactive element
|
|
3228
|
+
const interactiveElements = ['a', 'button', 'input', 'textarea', 'select']; //! Might needs updates
|
|
3229
|
+
const interactiveElement = this.element.querySelector(interactiveElements.join(',')) || ((_a = slotElement.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector(interactiveElements.join(',')));
|
|
3230
|
+
// define selected element to become tooltip selector
|
|
3231
|
+
const tooltipedElement = interactiveElement || slotElement;
|
|
3232
|
+
// Add tabindex to slotted element if we can't find any interactive element
|
|
3233
|
+
if (interactiveElement === null || interactiveElement === undefined)
|
|
3234
|
+
slotElement.tabIndex = 0;
|
|
3235
|
+
// Set aria-describedby
|
|
3236
|
+
const ariaDescribedby = slotElement.getAttribute('aria-describedby');
|
|
3237
|
+
if (ariaDescribedby === null) {
|
|
3238
|
+
tooltipedElement.setAttribute('aria-describedby', this.identifier);
|
|
3239
|
+
}
|
|
3240
|
+
else {
|
|
3241
|
+
slotElement.setAttribute('aria-describedby', `${ariaDescribedby} ${this.identifier}`);
|
|
3242
|
+
}
|
|
3243
|
+
// Create popperjs tooltip
|
|
3244
|
+
this.popper = createPopper(tooltipedElement, this.tooltip, {
|
|
3245
|
+
placement: this.placement,
|
|
3246
|
+
modifiers: [
|
|
3247
|
+
{
|
|
3248
|
+
name: 'offset',
|
|
3249
|
+
options: {
|
|
3250
|
+
offset: [0, 8],
|
|
3251
|
+
},
|
|
3252
|
+
},
|
|
3253
|
+
],
|
|
3254
|
+
});
|
|
3255
|
+
// Add events
|
|
3256
|
+
['mouseenter', 'focus'].forEach(event => {
|
|
3257
|
+
tooltipedElement.addEventListener(event, () => {
|
|
3258
|
+
if (!this.disabled)
|
|
3259
|
+
this.display = true;
|
|
3260
|
+
});
|
|
3261
|
+
});
|
|
3262
|
+
['mouseleave', 'blur', 'keydown'].forEach(event => {
|
|
3263
|
+
tooltipedElement.addEventListener(event, (e) => {
|
|
3264
|
+
// we continue to process ONLY for KeyboardEvents 'Escape'
|
|
3265
|
+
if (e.type === 'keydown' && e.code !== 'Escape') {
|
|
3266
|
+
return;
|
|
3267
|
+
}
|
|
3268
|
+
if (!this.disabled)
|
|
3269
|
+
this.display = false;
|
|
3270
|
+
});
|
|
3271
|
+
});
|
|
3272
|
+
this.handleDisplay(this.display);
|
|
3273
|
+
}
|
|
3274
|
+
/**
|
|
3275
|
+
* Render
|
|
3276
|
+
*
|
|
3277
|
+
* @returns {HTMLElement} HTML Element
|
|
3278
|
+
*/
|
|
3279
|
+
render() {
|
|
3280
|
+
return (h(Host, null, h("slot", null), h("div", { role: "tooltip", id: this.identifier, class: "mg-tooltip", innerHTML: this.message }, h("div", { class: "mg-tooltip__arrow", "data-popper-arrow": true }))));
|
|
3281
|
+
}
|
|
3282
|
+
get element() { return getElement(this); }
|
|
3283
|
+
static get watchers() { return {
|
|
3284
|
+
"display": ["handleDisplay"]
|
|
3285
|
+
}; }
|
|
3286
|
+
};
|
|
3287
|
+
MgTooltip.style = mgTooltipCss;
|
|
3288
|
+
|
|
3289
|
+
export { MgBadge as mg_badge, MgButton as mg_button, MgCharacterLeft as mg_character_left, MgForm as mg_form, MgIcon as mg_icon, MgInputCheckbox as mg_input_checkbox, MgInputDate as mg_input_date, MgInputNumeric as mg_input_numeric, MgInputPassword as mg_input_password, MgInputRadio as mg_input_radio, MgInputSelect as mg_input_select, MgInputText as mg_input_text, MgInputTextarea as mg_input_textarea, MgInputTitle as mg_input_title, MgInputToggle as mg_input_toggle, MgMessage as mg_message, MgPagination as mg_pagination, MgPanel as mg_panel, MgTabs as mg_tabs, MgTag as mg_tag, MgTooltip as mg_tooltip };
|