@mgdis/mg-components 5.27.2 → 5.27.4
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/{index-00072168.js → index-11b35234.js} +76 -36
- package/dist/cjs/index-11b35234.js.map +1 -0
- package/dist/cjs/index-3198e64e.js +1688 -0
- package/dist/cjs/index-3198e64e.js.map +1 -0
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/mg-action-more_36.cjs.entry.js +270 -216
- package/dist/cjs/mg-action-more_36.cjs.entry.js.map +1 -1
- package/dist/cjs/mg-components.cjs.js +10 -10
- package/dist/cjs/mg-components.cjs.js.map +1 -1
- package/dist/cjs/mg-loader.cjs.entry.js +3 -3
- package/dist/collection/collection-manifest.json +1 -1
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +124 -97
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input/mg-input.conf.js +1 -0
- package/dist/collection/components/molecules/inputs/mg-input/mg-input.conf.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/MgInputCheckboxList.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/MgInputCheckboxList.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.conf.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +21 -3
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js.map +1 -1
- package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js +21 -18
- package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js.map +1 -1
- package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js +2 -1
- package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js.map +1 -1
- package/dist/collection/components/molecules/mg-item-more/mg-item-more.js +4 -4
- package/dist/collection/components/molecules/mg-item-more/mg-item-more.js.map +1 -1
- package/dist/collection/components/molecules/mg-popover/mg-popover.js +6 -2
- package/dist/collection/components/molecules/mg-popover/mg-popover.js.map +1 -1
- package/dist/components/index.es.js +65 -25
- package/dist/components/index.es.js.map +1 -1
- package/dist/components/index2.js +2 -2
- package/dist/components/mg-action-more.js +2 -2
- package/dist/components/mg-badge2.js +3 -3
- package/dist/components/mg-button2.js +4 -4
- package/dist/components/mg-card2.js +2 -2
- package/dist/components/mg-details.js +2 -2
- package/dist/components/mg-form.js +3 -3
- package/dist/components/mg-icon2.js +2 -2
- package/dist/components/mg-illustrated-message.js +2 -2
- package/dist/components/mg-input-checkbox-paginated2.js +1 -1
- package/dist/components/mg-input-checkbox-paginated2.js.map +1 -1
- package/dist/components/mg-input-checkbox.js +25 -7
- package/dist/components/mg-input-checkbox.js.map +1 -1
- package/dist/components/mg-input-date.js +11 -11
- package/dist/components/mg-input-numeric.js +5 -5
- package/dist/components/mg-input-password.js +3 -3
- package/dist/components/mg-input-radio.js +4 -4
- package/dist/components/mg-input-select2.js +6 -6
- package/dist/components/mg-input-text2.js +6 -6
- package/dist/components/mg-input-textarea.js +6 -6
- package/dist/components/mg-input-title2.js +2 -2
- package/dist/components/mg-input-toggle.js +4 -4
- package/dist/components/mg-input2.js +4 -3
- package/dist/components/mg-input2.js.map +1 -1
- package/dist/components/mg-item-more2.js +26 -23
- package/dist/components/mg-item-more2.js.map +1 -1
- package/dist/components/mg-loader.js +2 -2
- package/dist/components/mg-menu-item2.js +8 -7
- package/dist/components/mg-menu-item2.js.map +1 -1
- package/dist/components/mg-message.js +3 -3
- package/dist/components/mg-modal.js +6 -6
- package/dist/components/mg-pagination2.js +2 -2
- package/dist/components/mg-panel.js +4 -4
- package/dist/components/mg-popover-content2.js +3 -3
- package/dist/components/mg-popover2.js +9 -5
- package/dist/components/mg-popover2.js.map +1 -1
- package/dist/components/mg-skip-links.js +2 -2
- package/dist/components/mg-tabs.js +6 -6
- package/dist/components/mg-tag.js +3 -3
- package/dist/components/mg-tooltip2.js +134 -107
- package/dist/components/mg-tooltip2.js.map +1 -1
- package/dist/esm/{index-8d5d1bfd.js → index-00abd8c1.js} +67 -27
- package/dist/esm/index-00abd8c1.js.map +1 -0
- package/dist/esm/index-99317ec3.js +1659 -0
- package/dist/esm/index-99317ec3.js.map +1 -0
- package/dist/esm/loader.js +3 -3
- package/dist/esm/mg-action-more_36.entry.js +270 -216
- package/dist/esm/mg-action-more_36.entry.js.map +1 -1
- package/dist/esm/mg-components.js +11 -11
- package/dist/esm/mg-components.js.map +1 -1
- package/dist/esm/mg-loader.entry.js +3 -3
- package/dist/mg-components/index.esm.js.map +1 -1
- package/dist/mg-components/mg-components.esm.js +1 -1
- package/dist/mg-components/mg-components.esm.js.map +1 -1
- package/dist/mg-components/p-48c0a0bf.entry.js +2 -0
- package/dist/mg-components/p-48c0a0bf.entry.js.map +1 -0
- package/dist/mg-components/p-4cfcbdc2.js +2 -0
- package/dist/mg-components/p-4cfcbdc2.js.map +1 -0
- package/dist/mg-components/p-815362e4.js +3 -0
- package/dist/mg-components/p-815362e4.js.map +1 -0
- package/dist/mg-components/{p-99e2f42a.entry.js → p-d3e15dd7.entry.js} +2 -2
- package/dist/mg-components/{p-99e2f42a.entry.js.map → p-d3e15dd7.entry.js.map} +1 -1
- package/dist/mg-components/p-e1255160.js.map +1 -1
- package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +25 -12
- package/dist/types/components/molecules/inputs/mg-input/mg-input.conf.d.ts +2 -1
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.conf.d.ts +2 -0
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +8 -0
- package/dist/types/components/molecules/menu/mg-menu/mg-menu.d.ts +1 -5
- package/dist/types/stencil-public-runtime.d.ts +3 -8
- package/ide/intellij/web-types.json +1 -1
- package/ide/vscode/html-custom-data.json +1 -1
- package/loader/cdn.js +1 -3
- package/loader/index.cjs.js +1 -3
- package/loader/index.es2017.js +1 -3
- package/loader/index.js +1 -3
- package/package.json +25 -25
- package/dist/cjs/index-00072168.js.map +0 -1
- package/dist/cjs/index-7e27c7ae.js +0 -2561
- package/dist/cjs/index-7e27c7ae.js.map +0 -1
- package/dist/esm/index-8d5d1bfd.js.map +0 -1
- package/dist/esm/index-e479d5ae.js +0 -2532
- package/dist/esm/index-e479d5ae.js.map +0 -1
- package/dist/esm/polyfills/core-js.js +0 -11
- package/dist/esm/polyfills/dom.js +0 -79
- package/dist/esm/polyfills/es5-html-element.js +0 -1
- package/dist/esm/polyfills/index.js +0 -34
- package/dist/esm/polyfills/system.js +0 -6
- package/dist/mg-components/p-7315d4a6.js +0 -3
- package/dist/mg-components/p-7315d4a6.js.map +0 -1
- package/dist/mg-components/p-8800813b.js +0 -2
- package/dist/mg-components/p-8800813b.js.map +0 -1
- package/dist/mg-components/p-f9ac8927.entry.js +0 -2
- package/dist/mg-components/p-f9ac8927.entry.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
|
|
2
2
|
import { i as initLocales } from './index2.js';
|
|
3
|
-
import {
|
|
3
|
+
import { I as Ie } from './index.es.js';
|
|
4
4
|
|
|
5
5
|
const mgSkipLinksCss = ".mg-c-skip-links{position:absolute;background:hsl(var(--color-light));opacity:0;transform:translateY(-100%)}.mg-c-skip-links:focus-within{position:relative;opacity:1;transform:translateY(0)}.mg-c-skip-links__list{display:flex;flex-wrap:wrap;align-items:center;padding:.64rem 1.8rem;margin:0;gap:.6rem;list-style:none}.mg-c-skip-links__link{display:inline-block;padding:1.2rem;color:hsl(var(--color-dark))}.mg-c-skip-links__link:hover{background:hsl(var(--color-dark)/10%)}";
|
|
6
6
|
const MgSkipLinksStyle0 = mgSkipLinksCss;
|
|
@@ -25,7 +25,7 @@ const MgSkipLinks$1 = /*@__PURE__*/ proxyCustomElement(class MgSkipLinks extends
|
|
|
25
25
|
this.links = undefined;
|
|
26
26
|
}
|
|
27
27
|
validateLinks(links) {
|
|
28
|
-
if (links === undefined || links.length === 0 || links.some(link => !
|
|
28
|
+
if (links === undefined || links.length === 0 || links.some(link => !Ie(link.href) || !link.href.startsWith('#') || !Ie(link.label))) {
|
|
29
29
|
throw new Error(`<mg-skip-links> prop "links": Cannot be empty and each link must contains an href starting with a "#" and a non empty label attributes.`);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
|
|
2
|
-
import {
|
|
2
|
+
import { G as Ge, C as Ce, H as He, I as Ie, P as Pe } from './index.es.js';
|
|
3
3
|
import { d as defineCustomElement$3 } from './mg-badge2.js';
|
|
4
4
|
import { d as defineCustomElement$2 } from './mg-icon2.js';
|
|
5
5
|
|
|
@@ -129,7 +129,7 @@ const MgTabs$1 = /*@__PURE__*/ proxyCustomElement(class MgTabs extends HTMLEleme
|
|
|
129
129
|
*/
|
|
130
130
|
this.resetFocus = () => {
|
|
131
131
|
// update asynchronously tabindex to prevent get focus on new tabindex at then end of event process
|
|
132
|
-
|
|
132
|
+
Ge(() => {
|
|
133
133
|
this.tabFocus = undefined;
|
|
134
134
|
Array.from(this.element.shadowRoot.querySelectorAll('[data-index]')).forEach((tab, index) => {
|
|
135
135
|
tab.setAttribute('tabindex', this.activeTab - this.startIndex !== index ? '-1' : '0');
|
|
@@ -144,16 +144,16 @@ const MgTabs$1 = /*@__PURE__*/ proxyCustomElement(class MgTabs extends HTMLEleme
|
|
|
144
144
|
if (slots.length !== this.tabs.length)
|
|
145
145
|
throw new Error('<mg-tabs> Must have slots counts equal to tabs count.');
|
|
146
146
|
};
|
|
147
|
-
this.identifier =
|
|
147
|
+
this.identifier = Ce('mg-tabs');
|
|
148
148
|
this.label = undefined;
|
|
149
149
|
this.size = 'regular';
|
|
150
150
|
this.items = undefined;
|
|
151
151
|
this.activeTab = undefined;
|
|
152
152
|
this.tabs = [];
|
|
153
|
-
this.classCollection = new
|
|
153
|
+
this.classCollection = new He(['mg-c-tabs']);
|
|
154
154
|
}
|
|
155
155
|
validateLabel(newValue) {
|
|
156
|
-
if (!
|
|
156
|
+
if (!Ie(newValue)) {
|
|
157
157
|
throw new Error('<mg-tabs> prop "label" is required.');
|
|
158
158
|
}
|
|
159
159
|
}
|
|
@@ -165,7 +165,7 @@ const MgTabs$1 = /*@__PURE__*/ proxyCustomElement(class MgTabs extends HTMLEleme
|
|
|
165
165
|
}
|
|
166
166
|
validateItems(newValue) {
|
|
167
167
|
// String array
|
|
168
|
-
if (
|
|
168
|
+
if (Pe(newValue))
|
|
169
169
|
this.tabs = newValue.map(item => ({ label: item, status: Status.VISIBLE }));
|
|
170
170
|
// Object array
|
|
171
171
|
else if (Array.isArray(newValue) && newValue.length > 0 && newValue.every(isTabItem))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
|
|
2
|
-
import {
|
|
2
|
+
import { H as He, I as Ie } from './index.es.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* List of all possibles variants
|
|
@@ -23,7 +23,7 @@ const MgTag$1 = /*@__PURE__*/ proxyCustomElement(class MgTag extends HTMLElement
|
|
|
23
23
|
this.variant = variants[0];
|
|
24
24
|
this.outline = undefined;
|
|
25
25
|
this.soft = undefined;
|
|
26
|
-
this.classCollection = new
|
|
26
|
+
this.classCollection = new He(['mg-c-tag']);
|
|
27
27
|
}
|
|
28
28
|
validateVariant(newValue, oldValue) {
|
|
29
29
|
if (!variants.includes(newValue)) {
|
|
@@ -60,7 +60,7 @@ const MgTag$1 = /*@__PURE__*/ proxyCustomElement(class MgTag extends HTMLElement
|
|
|
60
60
|
* @param textContent - html element textContent property
|
|
61
61
|
*/
|
|
62
62
|
validateTextContent(textContent) {
|
|
63
|
-
if (!
|
|
63
|
+
if (!Ie(textContent))
|
|
64
64
|
throw new Error('<mg-tag> slot must contain a text content.');
|
|
65
65
|
}
|
|
66
66
|
/*************
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
|
|
2
|
-
import {
|
|
2
|
+
import { G as Ge, C as Ce, I as Ie, z as ze, W as We } from './index.es.js';
|
|
3
3
|
import { d as defineCustomElement$1 } from './mg-tooltip-content2.js';
|
|
4
4
|
import { c as createPopper } from './popper.js';
|
|
5
5
|
|
|
@@ -34,10 +34,10 @@ const MgTooltip = /*@__PURE__*/ proxyCustomElement(class MgTooltip extends HTMLE
|
|
|
34
34
|
// Enable the event listeners
|
|
35
35
|
this.popper.setOptions(options => (Object.assign(Object.assign({}, options), { modifiers: [...options.modifiers, { name: 'eventListeners', enabled: true }] })));
|
|
36
36
|
// hide when click outside on nextTick to prevent event to trigger after creation
|
|
37
|
-
|
|
37
|
+
Ge(() => {
|
|
38
38
|
this.windows.forEach((localWindow) => {
|
|
39
|
-
localWindow.addEventListener('click', this.
|
|
40
|
-
localWindow.addEventListener('keydown', this.
|
|
39
|
+
localWindow.addEventListener('click', this.handleClickOutside, false);
|
|
40
|
+
localWindow.addEventListener('keydown', this.handlePressEscape, false);
|
|
41
41
|
});
|
|
42
42
|
});
|
|
43
43
|
};
|
|
@@ -51,15 +51,15 @@ const MgTooltip = /*@__PURE__*/ proxyCustomElement(class MgTooltip extends HTMLE
|
|
|
51
51
|
this.popper.setOptions(options => (Object.assign(Object.assign({}, options), { modifiers: [...options.modifiers, { name: 'eventListeners', enabled: false }] })));
|
|
52
52
|
// Remove event listener
|
|
53
53
|
this.windows.forEach((localWindow) => {
|
|
54
|
-
localWindow.removeEventListener('click', this.
|
|
55
|
-
localWindow.removeEventListener('keyboard', this.
|
|
54
|
+
localWindow.removeEventListener('click', this.handleClickOutside, false);
|
|
55
|
+
localWindow.removeEventListener('keyboard', this.handlePressEscape, false);
|
|
56
56
|
});
|
|
57
57
|
};
|
|
58
58
|
/**
|
|
59
59
|
* Check if clicked outside of component and hidde tooltip
|
|
60
60
|
* @param event - mouse event
|
|
61
61
|
*/
|
|
62
|
-
this.
|
|
62
|
+
this.handleClickOutside = (event) => {
|
|
63
63
|
if (event.target.closest('mg-tooltip') !== this.element)
|
|
64
64
|
this.setDisplay(false);
|
|
65
65
|
};
|
|
@@ -67,7 +67,7 @@ const MgTooltip = /*@__PURE__*/ proxyCustomElement(class MgTooltip extends HTMLE
|
|
|
67
67
|
* Check if 'Escape' key is pressed of component and hidde tooltip
|
|
68
68
|
* @param event - keyboard event
|
|
69
69
|
*/
|
|
70
|
-
this.
|
|
70
|
+
this.handlePressEscape = (event) => {
|
|
71
71
|
if (event.code === 'Escape') {
|
|
72
72
|
this.setDisplay(false);
|
|
73
73
|
this.resetGuard();
|
|
@@ -85,23 +85,25 @@ const MgTooltip = /*@__PURE__*/ proxyCustomElement(class MgTooltip extends HTMLE
|
|
|
85
85
|
/**
|
|
86
86
|
* Action for tooltip element and tooltiped element mouse listener
|
|
87
87
|
* @param elementGuard - tooltip element guard
|
|
88
|
-
* @param
|
|
88
|
+
* @param eventName - event name
|
|
89
89
|
* @param conditionalGuard - guard condition
|
|
90
90
|
*/
|
|
91
|
-
this.tooltipMouseListenerAction = (elementGuard,
|
|
92
|
-
//
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
91
|
+
this.tooltipMouseListenerAction = (elementGuard, eventName, conditionalGuard) => {
|
|
92
|
+
// active FOCUS guard cancel process
|
|
93
|
+
if ([Guard.FOCUS, Guard.DISABLE_ON_CLICK].includes(this.guard)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// Update guard by element guard
|
|
97
|
+
this.guard = elementGuard;
|
|
98
|
+
if (eventName !== 'mouseenter') {
|
|
99
|
+
// process action in the next event loop macro task
|
|
100
|
+
setTimeout(() => {
|
|
101
|
+
this.setDisplay(false, this.guard !== conditionalGuard);
|
|
102
|
+
this.resetGuard();
|
|
103
|
+
}, 100);
|
|
104
|
+
}
|
|
105
|
+
else if (this.guard === Guard.HOVER_TOOLTIPED_ELEMENT) {
|
|
106
|
+
this.setDisplay(true);
|
|
105
107
|
}
|
|
106
108
|
};
|
|
107
109
|
/**
|
|
@@ -128,27 +130,9 @@ const MgTooltip = /*@__PURE__*/ proxyCustomElement(class MgTooltip extends HTMLE
|
|
|
128
130
|
}
|
|
129
131
|
};
|
|
130
132
|
/**
|
|
131
|
-
*
|
|
132
|
-
* @param slotElement - slotted element
|
|
133
|
-
* @param interactiveElement - interactive element
|
|
133
|
+
* Set popper instance
|
|
134
134
|
*/
|
|
135
|
-
this.
|
|
136
|
-
// Add tabindex to slotted element if we can't find any interactive element
|
|
137
|
-
if (!this.disabled && !interactiveElement) {
|
|
138
|
-
this.hasCustomTabIndex = true;
|
|
139
|
-
slotElement.tabIndex = 0;
|
|
140
|
-
// Add role on non-interactive element to work with "aria-describedby" for screen readers
|
|
141
|
-
slotElement.setAttribute('role', 'button');
|
|
142
|
-
}
|
|
143
|
-
// Set aria-describedby
|
|
144
|
-
const ariaDescribedby = slotElement.getAttribute('aria-describedby');
|
|
145
|
-
if (ariaDescribedby === null) {
|
|
146
|
-
this.tooltipedElement.setAttribute('aria-describedby', this.identifier);
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
// We ensure to have uniq ids
|
|
150
|
-
slotElement.setAttribute('aria-describedby', `${[...new Set([...ariaDescribedby.split(' '), this.identifier])].join(' ')}`);
|
|
151
|
-
}
|
|
135
|
+
this.setPopper = () => {
|
|
152
136
|
// use element data attribute: `data-popper-strategy`, in order to get popper strategy configuration
|
|
153
137
|
const strategy = (this.element.dataset.popperStrategy || 'fixed');
|
|
154
138
|
// Create popperjs tooltip
|
|
@@ -170,13 +154,14 @@ const MgTooltip = /*@__PURE__*/ proxyCustomElement(class MgTooltip extends HTMLE
|
|
|
170
154
|
},
|
|
171
155
|
],
|
|
172
156
|
});
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Define selected element to become tooltip selector and init listeners
|
|
160
|
+
* @param element - tooltiped element
|
|
161
|
+
*/
|
|
162
|
+
this.setTooltipedElement = (element) => {
|
|
163
|
+
this.tooltipedElement = element;
|
|
164
|
+
// Manage tooltipedElement focus events
|
|
180
165
|
this.tooltipedElement.addEventListener('focus', () => {
|
|
181
166
|
this.guard = Guard.FOCUS;
|
|
182
167
|
this.setDisplay(true);
|
|
@@ -191,37 +176,71 @@ const MgTooltip = /*@__PURE__*/ proxyCustomElement(class MgTooltip extends HTMLE
|
|
|
191
176
|
this.resetGuard();
|
|
192
177
|
this.setDisplay(false);
|
|
193
178
|
});
|
|
194
|
-
document.addEventListener('keydown', this.pressEscape);
|
|
195
179
|
// manage tooltipElement & tooltipedElement mouseenter/mouseleave events
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
].forEach(({ element, action }) => {
|
|
202
|
-
element.addEventListener(eventType, () => {
|
|
203
|
-
action();
|
|
204
|
-
});
|
|
205
|
-
});
|
|
180
|
+
this.tooltipedElement.addEventListener('mouseenter', () => {
|
|
181
|
+
this.tooltipMouseListenerAction(Guard.HOVER_TOOLTIPED_ELEMENT, 'mouseenter', Guard.HOVER_TOOLTIP_ELEMENT);
|
|
182
|
+
});
|
|
183
|
+
this.tooltipedElement.addEventListener('mouseleave', () => {
|
|
184
|
+
this.tooltipMouseListenerAction(Guard.HOVER_TOOLTIPED_ELEMENT, 'mouseleave', Guard.HOVER_TOOLTIP_ELEMENT);
|
|
206
185
|
});
|
|
207
186
|
};
|
|
208
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Set button mutation observer
|
|
189
|
+
* @param mgButton - mg-button to observe
|
|
190
|
+
*/
|
|
191
|
+
this.setMgButtonMutationObserver = (mgButton) => {
|
|
192
|
+
new MutationObserver(mutationList => {
|
|
193
|
+
// stop process when none of mutations attributed is disabled
|
|
194
|
+
if (!mutationList.some(mutation => ['aria-disabled', 'disabled'].includes(mutation.attributeName)))
|
|
195
|
+
return;
|
|
196
|
+
// set guard when one of mutations is for a disabled with disabled-on-click
|
|
197
|
+
if (mutationList.some((mutation) => mutation.target.disabled && mutation.target.disableOnClick)) {
|
|
198
|
+
this.guard = Guard.DISABLE_ON_CLICK;
|
|
199
|
+
}
|
|
200
|
+
// when the disabled-on-click guard is running we stop process
|
|
201
|
+
if (this.guard === Guard.DISABLE_ON_CLICK)
|
|
202
|
+
return;
|
|
203
|
+
// update button wrapper
|
|
204
|
+
this.setMgButtonWrapper(mgButton);
|
|
205
|
+
// Since Firefox doesn't trigger a "blur" event when the "disabled" attribute is added or removed from a button
|
|
206
|
+
// we have to manually unlock the guard because the "blur" handler of the tooltipedElement won't do it.
|
|
207
|
+
this.resetGuard();
|
|
208
|
+
// update popper instance
|
|
209
|
+
this.popper.update();
|
|
210
|
+
}).observe(mgButton, { attributes: true });
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Set tooltiped element aria-describedby
|
|
214
|
+
* @param element - element to update
|
|
215
|
+
*/
|
|
216
|
+
this.setAriaDescribedby = (element) => {
|
|
217
|
+
// Set aria-describedby
|
|
218
|
+
const ariaDescribedby = element.getAttribute('aria-describedby');
|
|
219
|
+
if (ariaDescribedby === null) {
|
|
220
|
+
this.tooltipedElement.setAttribute('aria-describedby', this.identifier);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
// We ensure to have uniq ids
|
|
224
|
+
element.setAttribute('aria-describedby', `${[...new Set([...ariaDescribedby.split(' '), this.identifier])].join(' ')}`);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
this.identifier = Ce('mg-tooltip');
|
|
209
228
|
this.message = undefined;
|
|
210
229
|
this.placement = 'bottom';
|
|
211
230
|
this.display = false;
|
|
212
231
|
this.disabled = false;
|
|
213
232
|
}
|
|
214
|
-
|
|
233
|
+
watchIdentifier() {
|
|
215
234
|
// use renderTooltipContent to update tooltip-content id
|
|
216
235
|
this.renderTooltipContent();
|
|
217
236
|
}
|
|
218
|
-
|
|
219
|
-
if (!
|
|
237
|
+
watchMessage(newValue) {
|
|
238
|
+
if (!Ie(newValue)) {
|
|
220
239
|
throw new Error('<mg-tooltip> prop "message" is required.');
|
|
221
240
|
}
|
|
222
241
|
this.mgTooltipContent.message = newValue;
|
|
223
242
|
}
|
|
224
|
-
|
|
243
|
+
watchDisplay(newValue) {
|
|
225
244
|
if (newValue) {
|
|
226
245
|
this.show();
|
|
227
246
|
}
|
|
@@ -229,7 +248,7 @@ const MgTooltip = /*@__PURE__*/ proxyCustomElement(class MgTooltip extends HTMLE
|
|
|
229
248
|
this.hide();
|
|
230
249
|
}
|
|
231
250
|
}
|
|
232
|
-
|
|
251
|
+
watchDisabled(newValue) {
|
|
233
252
|
if (this.hasCustomTabIndex) {
|
|
234
253
|
if (newValue)
|
|
235
254
|
this.tooltipedElement.removeAttribute('tabindex');
|
|
@@ -238,23 +257,29 @@ const MgTooltip = /*@__PURE__*/ proxyCustomElement(class MgTooltip extends HTMLE
|
|
|
238
257
|
}
|
|
239
258
|
}
|
|
240
259
|
/**
|
|
241
|
-
* Render tooltip content element
|
|
260
|
+
* Render tooltip content element and init listeners
|
|
242
261
|
*/
|
|
243
262
|
renderTooltipContent() {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
mgTooltipContent.
|
|
263
|
+
if (this.mgTooltipContent) {
|
|
264
|
+
this.mgTooltipContent.setAttribute('id', this.identifier);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
this.mgTooltipContent = document.createElement('mg-tooltip-content');
|
|
268
|
+
this.mgTooltipContent.setAttribute('slot', 'content');
|
|
269
|
+
this.mgTooltipContent.setAttribute('id', this.identifier);
|
|
249
270
|
const arrow = document.createElement('div');
|
|
250
271
|
arrow.setAttribute('slot', 'arrow');
|
|
251
272
|
arrow.dataset.popperArrow = '';
|
|
252
|
-
mgTooltipContent.appendChild(arrow);
|
|
273
|
+
this.mgTooltipContent.appendChild(arrow);
|
|
274
|
+
// manage tooltipElement & tooltipedElement mouseenter/mouseleave events
|
|
275
|
+
this.mgTooltipContent.addEventListener('mouseenter', () => {
|
|
276
|
+
this.tooltipMouseListenerAction(Guard.HOVER_TOOLTIP_ELEMENT, 'mouseenter', Guard.HOVER_TOOLTIPED_ELEMENT);
|
|
277
|
+
});
|
|
278
|
+
this.mgTooltipContent.addEventListener('mouseleave', () => {
|
|
279
|
+
this.tooltipMouseListenerAction(Guard.HOVER_TOOLTIP_ELEMENT, 'mouseleave', Guard.HOVER_TOOLTIPED_ELEMENT);
|
|
280
|
+
});
|
|
253
281
|
// append tooltip element to component
|
|
254
|
-
this.element.appendChild(mgTooltipContent);
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
mgTooltipContent.setAttribute('id', this.identifier);
|
|
282
|
+
this.element.appendChild(this.mgTooltipContent);
|
|
258
283
|
}
|
|
259
284
|
}
|
|
260
285
|
/*************
|
|
@@ -265,14 +290,13 @@ const MgTooltip = /*@__PURE__*/ proxyCustomElement(class MgTooltip extends HTMLE
|
|
|
265
290
|
*/
|
|
266
291
|
componentWillLoad() {
|
|
267
292
|
// Get windows to attach events
|
|
268
|
-
this.windows =
|
|
293
|
+
this.windows = ze(window);
|
|
269
294
|
// Get tooltip element
|
|
270
295
|
this.renderTooltipContent();
|
|
271
|
-
this.mgTooltipContent = this.element.querySelector(`#${this.identifier}`);
|
|
272
296
|
//validate properties
|
|
273
|
-
this.
|
|
274
|
-
this.
|
|
275
|
-
this.
|
|
297
|
+
this.watchDisabled(this.disabled);
|
|
298
|
+
this.watchMessage(this.message);
|
|
299
|
+
this.watchIdentifier();
|
|
276
300
|
}
|
|
277
301
|
/**
|
|
278
302
|
* Get slotted element
|
|
@@ -284,26 +308,29 @@ const MgTooltip = /*@__PURE__*/ proxyCustomElement(class MgTooltip extends HTMLE
|
|
|
284
308
|
// get slotted element wich is not the tooltip
|
|
285
309
|
const slotElement = this.element.querySelector(`*:not(#${this.identifier})`);
|
|
286
310
|
// Get interactive element
|
|
287
|
-
const interactiveElement = slotElement.matches(
|
|
288
|
-
|
|
289
|
-
this.tooltipedElement = interactiveElement || slotElement;
|
|
311
|
+
const interactiveElement = slotElement.matches(We) ? slotElement : (_a = slotElement.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector(We);
|
|
312
|
+
this.setTooltipedElement(interactiveElement || slotElement);
|
|
290
313
|
// Check if slotted element is a disabled mg-button
|
|
291
314
|
// In this case we wrap the mg-button into a div to enable the tooltip
|
|
292
315
|
if (isButton(slotElement)) {
|
|
293
|
-
|
|
294
|
-
if (mutationList.some(mutation => ['aria-disabled', 'disabled'].includes(mutation.attributeName)) && this.guard !== Guard.DISABLE_ON_CLICK) {
|
|
295
|
-
this.setMgButtonWrapper(slotElement);
|
|
296
|
-
// Since Firefox doesn't trigger a "blur" event when the "disabled" attribute is added or removed from a button
|
|
297
|
-
// we have to manually unlock the guard because the "blur" handler of the tooltipedElement won't do it.
|
|
298
|
-
this.resetGuard();
|
|
299
|
-
this.initTooltip(slotElement, interactiveElement);
|
|
300
|
-
}
|
|
301
|
-
}).observe(slotElement, { attributes: true });
|
|
316
|
+
this.setMgButtonMutationObserver(slotElement);
|
|
302
317
|
this.setMgButtonWrapper(slotElement);
|
|
303
318
|
}
|
|
304
|
-
//
|
|
305
|
-
this.
|
|
306
|
-
|
|
319
|
+
// Add tabindex to slotted element if we can't find any interactive element
|
|
320
|
+
if (!this.disabled && !interactiveElement) {
|
|
321
|
+
this.hasCustomTabIndex = true;
|
|
322
|
+
slotElement.tabIndex = 0;
|
|
323
|
+
// Add role on non-interactive element to work with "aria-describedby" for screen readers
|
|
324
|
+
slotElement.setAttribute('role', 'button');
|
|
325
|
+
}
|
|
326
|
+
// apply a11y aria
|
|
327
|
+
this.setAriaDescribedby(slotElement);
|
|
328
|
+
// set Tooltip
|
|
329
|
+
this.setPopper();
|
|
330
|
+
// add document keyboard handler
|
|
331
|
+
document.addEventListener('keydown', this.handlePressEscape);
|
|
332
|
+
// check props
|
|
333
|
+
this.watchDisplay(this.display);
|
|
307
334
|
}
|
|
308
335
|
/**
|
|
309
336
|
* update popper position after props change on component did update hook to benefit from render ended
|
|
@@ -316,14 +343,14 @@ const MgTooltip = /*@__PURE__*/ proxyCustomElement(class MgTooltip extends HTMLE
|
|
|
316
343
|
* @returns HTML Element
|
|
317
344
|
*/
|
|
318
345
|
render() {
|
|
319
|
-
return (h(Host, { key: '
|
|
346
|
+
return (h(Host, { key: '9d7c428ba22f6b8e41ad1b62837d7b369e38314d' }, h("slot", { key: 'f5bdcac81a64674dd57e88e1c00b540dd49310f6' }), h("slot", { key: '8d40b6f4f1d3f385dcdf582509f89b3ec0dbd676', name: "content" })));
|
|
320
347
|
}
|
|
321
348
|
get element() { return this; }
|
|
322
349
|
static get watchers() { return {
|
|
323
|
-
"identifier": ["
|
|
324
|
-
"message": ["
|
|
325
|
-
"display": ["
|
|
326
|
-
"disabled": ["
|
|
350
|
+
"identifier": ["watchIdentifier"],
|
|
351
|
+
"message": ["watchMessage"],
|
|
352
|
+
"display": ["watchDisplay"],
|
|
353
|
+
"disabled": ["watchDisabled"]
|
|
327
354
|
}; }
|
|
328
355
|
static get style() { return MgTooltipStyle0; }
|
|
329
356
|
}, [1, "mg-tooltip", {
|
|
@@ -333,10 +360,10 @@ const MgTooltip = /*@__PURE__*/ proxyCustomElement(class MgTooltip extends HTMLE
|
|
|
333
360
|
"display": [1028],
|
|
334
361
|
"disabled": [4]
|
|
335
362
|
}, undefined, {
|
|
336
|
-
"identifier": ["
|
|
337
|
-
"message": ["
|
|
338
|
-
"display": ["
|
|
339
|
-
"disabled": ["
|
|
363
|
+
"identifier": ["watchIdentifier"],
|
|
364
|
+
"message": ["watchMessage"],
|
|
365
|
+
"display": ["watchDisplay"],
|
|
366
|
+
"disabled": ["watchDisabled"]
|
|
340
367
|
}]);
|
|
341
368
|
function defineCustomElement() {
|
|
342
369
|
if (typeof customElements === "undefined") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"mg-tooltip2.js","mappings":";;;;;AAAA,IAAY,KAKX;AALD,WAAY,KAAK;IACf,wBAAe,CAAA;IACf,oDAA2C,CAAA;IAC3C,wDAA+C,CAAA;IAC/C,4CAAmC,CAAA;AACrC,CAAC,EALW,KAAK,KAAL,KAAK;;ACAjB,MAAM,YAAY,GAAG,0HAA0H,CAAC;AAChJ,wBAAe,YAAY;;ACI3B;;;;;AAKA,MAAM,QAAQ,GAAG,CAAC,OAAgB,KAAqC,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAE,OAAmB,CAAC,OAAO,CAAC,CAAC;MAWxJ,SAAS;;;;;;;;QA+EZ,SAAI,GAAG;;YAEb,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC;;YAExC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,qCACzB,OAAO,KACV,SAAS,EAAE,CAAC,GAAG,OAAO,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,IAC5E,CAAC,CAAC;;YAEJA,EAAQ,CAAC;gBACP,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,WAAmB;oBACvC,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;oBAChE,WAAW,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;iBAClE,CAAC,CAAC;aACJ,CAAC,CAAC;SACJ,CAA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,IAAI,gBAAgB,CAAC,YAAY;gBAC/B,IAAI,YAAY,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC,gBAAgB,EAAE;oBAC1I,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;;;oBAGrC,IAAI,CAAC,UAAU,EAAE,CAAC;oBAClB,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;iBACnD;aACF,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;YAC9C,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;SACtC;;QAGD,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;QAElD,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;KAClC;;;;IAKD,kBAAkB;QAChB,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;KACtB;;;;;IAMD,MAAM;QACJ,QACE,EAAC,IAAI,uDACH,8DAAa,EACb,6DAAM,IAAI,EAAC,SAAS,GAAQ,CACvB,EACP;KACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["nextTick","createID","isValidString","getWindows","focusableElements"],"sources":["src/components/atoms/mg-tooltip/mg-tooltip.conf.tsx","../styles/dist/components/mg-tooltip.css?tag=mg-tooltip&encapsulation=shadow","src/components/atoms/mg-tooltip/mg-tooltip.tsx"],"sourcesContent":["export enum Guard {\n FOCUS = 'focus',\n HOVER_TOOLTIP_ELEMENT = 'hoverTooltipGuard',\n HOVER_TOOLTIPED_ELEMENT = 'hoverTooltipedGuard',\n DISABLE_ON_CLICK = 'disableOnClick',\n}\n",":host{display:inline-block}mg-tooltip-content{font-family:var(--font-family);font-size:var(--font-size);font-weight:200}/*# sourceMappingURL=mg-tooltip.css.map */\n","import { Component, Element, h, Host, Prop, Watch } from '@stencil/core';\nimport { createID, focusableElements, getWindows, isValidString, nextTick } from '@mgdis/stencil-helpers';\nimport { Instance as PopperInstance, createPopper, Placement, PositioningStrategy } from '@popperjs/core';\nimport { Guard } from './mg-tooltip.conf';\n\n/**\n * HTMLMgButtonElement type guard\n * @param element - element to check\n * @returns return true if type is HTMLMgButtonElement\n */\nconst isButton = (element: unknown): element is HTMLMgButtonElement => typeof element === 'object' && ['MG-BUTTON', 'BUTTON'].includes((element as Element).tagName);\n\n/**\n * @slot - Element that will display the tooltip\n * @slot content - Tooltip content\n */\n@Component({\n tag: 'mg-tooltip',\n styleUrl: '../../../../node_modules/@mgdis/styles/dist/components/mg-tooltip.css',\n shadow: true,\n})\nexport class MgTooltip {\n /************\n * Internal *\n ************/\n\n private popper: PopperInstance;\n private mgTooltipContent: HTMLMgTooltipContentElement;\n private tooltipedElement: HTMLElement;\n private windows: Window[];\n private hasCustomTabIndex: boolean;\n\n // tooltip actions guards\n private guard: Guard;\n\n /**************\n * Decorators *\n **************/\n\n /**\n * Get component DOM element\n */\n @Element() element: HTMLMgTooltipElement;\n\n /**\n * Sets an `id` attribute.\n * Needed by the input for accessibility `aria-decribedby`.\n */\n @Prop() identifier: string = createID('mg-tooltip');\n @Watch('identifier')\n validateIdentifier(): void {\n // use renderTooltipContent to update tooltip-content id\n this.renderTooltipContent();\n }\n\n /**\n * Displayed message in the tooltip\n */\n @Prop() message!: string;\n @Watch('message')\n validateMessage(newValue: MgTooltip['message']): void {\n if (!isValidString(newValue)) {\n throw new Error('<mg-tooltip> prop \"message\" is required.');\n }\n this.mgTooltipContent.message = newValue;\n }\n\n /**\n * Tooltip placement\n */\n @Prop() placement: Placement = 'bottom';\n\n /**\n * Display tooltip\n */\n @Prop({ mutable: true }) display = false;\n @Watch('display')\n handleDisplay(newValue: MgTooltip['display']): void {\n if (newValue) {\n this.show();\n } else {\n this.hide();\n }\n }\n\n /**\n * Disable tooltip\n */\n @Prop() disabled = false;\n @Watch('disabled')\n validateDisabled(newValue: MgTooltip['disabled']): void {\n if (this.hasCustomTabIndex) {\n if (newValue) this.tooltipedElement.removeAttribute('tabindex');\n else if (this.tooltipedElement.getAttribute('tabindex') === null) this.tooltipedElement.setAttribute('tabindex', '0');\n }\n }\n\n /**\n * Show tooltip\n */\n private show = (): void => {\n // Make the tooltip visible\n this.mgTooltipContent.dataset.show = '';\n // Enable the event listeners\n this.popper.setOptions(options => ({\n ...options,\n modifiers: [...options.modifiers, { name: 'eventListeners', enabled: true }],\n }));\n // hide when click outside on nextTick to prevent event to trigger after creation\n nextTick(() => {\n this.windows.forEach((localWindow: Window) => {\n localWindow.addEventListener('click', this.clickOutside, false);\n localWindow.addEventListener('keydown', this.pressEscape, false);\n });\n });\n };\n\n /**\n * Hide tooltip\n */\n private hide = (): void => {\n // Hide the tooltip\n this.mgTooltipContent.removeAttribute('data-show');\n // Disable the event listeners\n this.popper.setOptions(options => ({\n ...options,\n modifiers: [...options.modifiers, { name: 'eventListeners', enabled: false }],\n }));\n // Remove event listener\n this.windows.forEach((localWindow: Window) => {\n localWindow.removeEventListener('click', this.clickOutside, false);\n localWindow.removeEventListener('keyboard', this.pressEscape, false);\n });\n };\n\n /**\n * Check if clicked outside of component and hidde tooltip\n * @param event - mouse event\n */\n private clickOutside = (event: MouseEvent & { target: HTMLElement }): void => {\n if (event.target.closest('mg-tooltip') !== this.element) this.setDisplay(false);\n };\n\n /**\n * Check if 'Escape' key is pressed of component and hidde tooltip\n * @param event - keyboard event\n */\n private pressEscape = (event: KeyboardEvent): void => {\n if (event.code === 'Escape') {\n this.setDisplay(false);\n this.resetGuard();\n }\n };\n\n /**\n * Method to set display prop\n * @param newValue - display prop new value\n * @param condition - additionnal condition to apply display prop newValue\n */\n private setDisplay = (newValue: MgTooltip['display'], condition = true): void => {\n if (!this.disabled && condition) this.display = newValue;\n };\n\n /**\n * Action for tooltip element and tooltiped element mouse listener\n * @param elementGuard - tooltip element guard\n * @param isMouseenter - mouseenter validation\n * @param conditionalGuard - guard condition\n */\n private tooltipMouseListenerAction = (elementGuard: Guard, isMouseenter: boolean, conditionalGuard: Guard): void => {\n // we mutate elementGuard\n if (![Guard.FOCUS, Guard.DISABLE_ON_CLICK].includes(this.guard)) {\n this.guard = elementGuard;\n if (!isMouseenter) {\n // process action in the next event loop macro task\n setTimeout(() => {\n this.setDisplay(isMouseenter, this.guard !== conditionalGuard);\n this.resetGuard();\n }, 100);\n } else if (this.guard === Guard.HOVER_TOOLTIPED_ELEMENT) {\n this.setDisplay(isMouseenter);\n }\n }\n };\n\n /**\n * Method to reset guard value\n */\n private resetGuard = (): void => {\n this.guard = undefined;\n };\n\n /**\n * Update slot content when it is a mg-button\n * @param mgButton - slotted mg-button\n */\n private setMgButtonWrapper = (mgButton: HTMLMgButtonElement): void => {\n if (mgButton.disabled) {\n const div = document.createElement('div');\n div.classList.add('mg-c-tooltip__mg-button-wrapper');\n mgButton.parentNode.insertBefore(div, mgButton);\n div.appendChild(mgButton);\n this.tooltipedElement = div;\n } else if (mgButton.parentElement.classList.contains('mg-c-tooltip__mg-button-wrapper')) {\n this.element.firstElementChild.replaceWith(mgButton);\n this.tooltipedElement = mgButton;\n }\n };\n\n /**\n * Init tooltip\n * @param slotElement - slotted element\n * @param interactiveElement - interactive element\n */\n private initTooltip = (slotElement: HTMLElement, interactiveElement: HTMLElement): void => {\n // Add tabindex to slotted element if we can't find any interactive element\n if (!this.disabled && !interactiveElement) {\n this.hasCustomTabIndex = true;\n slotElement.tabIndex = 0;\n // Add role on non-interactive element to work with \"aria-describedby\" for screen readers\n slotElement.setAttribute('role', 'button');\n }\n // Set aria-describedby\n const ariaDescribedby = slotElement.getAttribute('aria-describedby');\n\n if (ariaDescribedby === null) {\n this.tooltipedElement.setAttribute('aria-describedby', this.identifier);\n } else {\n // We ensure to have uniq ids\n slotElement.setAttribute('aria-describedby', `${[...new Set([...ariaDescribedby.split(' '), this.identifier])].join(' ')}`);\n }\n\n // use element data attribute: `data-popper-strategy`, in order to get popper strategy configuration\n const strategy = (this.element.dataset.popperStrategy || 'fixed') as PositioningStrategy;\n\n // Create popperjs tooltip\n this.popper = createPopper(this.tooltipedElement, this.mgTooltipContent, {\n placement: this.placement,\n strategy,\n modifiers: [\n {\n name: 'offset',\n options: {\n offset: [0, 8],\n },\n },\n {\n name: 'flip',\n options: {\n fallbackPlacements: ['auto'],\n },\n },\n ],\n });\n\n // Manage tooltipedElement focus/blur events\n this.tooltipedElement.addEventListener('disabled-change', (event: CustomEvent & { target: HTMLMgButtonElement }) => {\n if (event.target.disableOnClick) {\n this.guard = event.detail ? Guard.DISABLE_ON_CLICK : null;\n }\n });\n\n // Manage tooltipedElement focus/blur events\n this.tooltipedElement.addEventListener('focus', () => {\n this.guard = Guard.FOCUS;\n this.setDisplay(true);\n });\n\n // as `click` event is the composition of `mousedown` and `mouseup` event,\n // and `click` event trigger `focus` event after a success `mousedown` wich set the `guard` to `Guard.FOCUS`\n // we reset the guard on `mouseup` event to unlock tooltip\n this.tooltipedElement.addEventListener('mouseup', () => {\n this.resetGuard();\n });\n\n this.tooltipedElement.addEventListener('blur', () => {\n this.resetGuard();\n this.setDisplay(false);\n });\n\n document.addEventListener('keydown', this.pressEscape);\n\n // manage tooltipElement & tooltipedElement mouseenter/mouseleave events\n ['mouseenter', 'mouseleave'].forEach(eventType => {\n const isMouseenter = eventType === 'mouseenter';\n [\n { element: this.mgTooltipContent, action: () => this.tooltipMouseListenerAction(Guard.HOVER_TOOLTIP_ELEMENT, isMouseenter, Guard.HOVER_TOOLTIPED_ELEMENT) },\n { element: this.tooltipedElement, action: () => this.tooltipMouseListenerAction(Guard.HOVER_TOOLTIPED_ELEMENT, isMouseenter, Guard.HOVER_TOOLTIP_ELEMENT) },\n ].forEach(({ element, action }) => {\n element.addEventListener(eventType, () => {\n action();\n });\n });\n });\n };\n\n /**\n * Render tooltip content element\n */\n private renderTooltipContent(): void {\n const mgTooltipContent = this.element.querySelector('mg-tooltip-content');\n if (mgTooltipContent === null) {\n const mgTooltipContent = document.createElement('mg-tooltip-content');\n mgTooltipContent.setAttribute('slot', 'content');\n mgTooltipContent.setAttribute('id', this.identifier);\n\n const arrow = document.createElement('div');\n arrow.setAttribute('slot', 'arrow');\n arrow.dataset.popperArrow = '';\n mgTooltipContent.appendChild(arrow);\n\n // append tooltip element to component\n this.element.appendChild(mgTooltipContent);\n } else {\n mgTooltipContent.setAttribute('id', this.identifier);\n }\n }\n\n /*************\n * Lifecycle *\n *************/\n\n /**\n * set variables\n */\n componentWillLoad(): void {\n // Get windows to attach events\n this.windows = getWindows(window);\n\n // Get tooltip element\n this.renderTooltipContent();\n this.mgTooltipContent = this.element.querySelector(`#${this.identifier}`);\n\n //validate properties\n this.validateDisabled(this.disabled);\n this.validateMessage(this.message);\n this.validateIdentifier();\n }\n\n /**\n * Get slotted element\n * Check if it already contain an interactive element, if not we need to add a tabIndex attribute\n * We need to attach the focused element to the tooltip (aria-describedby)\n */\n componentDidLoad(): void {\n // get slotted element wich is not the tooltip\n const slotElement: HTMLElement = this.element.querySelector(`*:not(#${this.identifier})`);\n\n // Get interactive element\n const interactiveElement: HTMLElement = slotElement.matches(focusableElements) ? slotElement : slotElement.shadowRoot?.querySelector(focusableElements);\n\n // define selected element to become tooltip selector\n this.tooltipedElement = interactiveElement || slotElement;\n\n // Check if slotted element is a disabled mg-button\n // In this case we wrap the mg-button into a div to enable the tooltip\n if (isButton(slotElement)) {\n new MutationObserver(mutationList => {\n if (mutationList.some(mutation => ['aria-disabled', 'disabled'].includes(mutation.attributeName)) && this.guard !== Guard.DISABLE_ON_CLICK) {\n this.setMgButtonWrapper(slotElement);\n // Since Firefox doesn't trigger a \"blur\" event when the \"disabled\" attribute is added or removed from a button\n // we have to manually unlock the guard because the \"blur\" handler of the tooltipedElement won't do it.\n this.resetGuard();\n this.initTooltip(slotElement, interactiveElement);\n }\n }).observe(slotElement, { attributes: true });\n this.setMgButtonWrapper(slotElement);\n }\n\n // Init Tooltip\n this.initTooltip(slotElement, interactiveElement);\n\n this.handleDisplay(this.display);\n }\n\n /**\n * update popper position after props change on component did update hook to benefit from render ended\n */\n componentDidUpdate(): void {\n this.popper.update();\n }\n\n /**\n * Render\n * @returns HTML Element\n */\n render(): HTMLElement {\n return (\n <Host>\n <slot></slot>\n <slot name=\"content\"></slot>\n </Host>\n );\n }\n}\n"],"version":3}
|
|
1
|
+
{"file":"mg-tooltip2.js","mappings":";;;;;AAAA,IAAY,KAKX;AALD,WAAY,KAAK;IACf,wBAAe,CAAA;IACf,oDAA2C,CAAA;IAC3C,wDAA+C,CAAA;IAC/C,4CAAmC,CAAA;AACrC,CAAC,EALW,KAAK,KAAL,KAAK;;ACAjB,MAAM,YAAY,GAAG,0HAA0H,CAAC;AAChJ,wBAAe,YAAY;;ACI3B;;;;;AAKA,MAAM,QAAQ,GAAG,CAAC,OAAgB,KAAqC,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAE,OAAmB,CAAC,OAAO,CAAC,CAAC;MAWxJ,SAAS;;;;;;;;QA+EZ,SAAI,GAAG;;YAEb,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC;;YAExC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,qCACzB,OAAO,KACV,SAAS,EAAE,CAAC,GAAG,OAAO,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,IAC5E,CAAC,CAAC;;YAEJA,EAAQ,CAAC;gBACP,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,WAAmB;oBACvC,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;oBACtE,WAAW,CAAC,gBAAgB,CAAC,SAAS,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mg-tooltip.conf.tsx","../styles/dist/components/mg-tooltip.css?tag=mg-tooltip&encapsulation=shadow","src/components/atoms/mg-tooltip/mg-tooltip.tsx"],"sourcesContent":["export enum Guard {\n FOCUS = 'focus',\n HOVER_TOOLTIP_ELEMENT = 'hoverTooltipGuard',\n HOVER_TOOLTIPED_ELEMENT = 'hoverTooltipedGuard',\n DISABLE_ON_CLICK = 'disableOnClick',\n}\n",":host{display:inline-block}mg-tooltip-content{font-family:var(--font-family);font-size:var(--font-size);font-weight:200}/*# sourceMappingURL=mg-tooltip.css.map */\n","import { Component, Element, h, Host, Prop, Watch } from '@stencil/core';\nimport { createID, focusableElements, getWindows, isValidString, nextTick } from '@mgdis/stencil-helpers';\nimport { Instance as PopperInstance, createPopper, Placement, PositioningStrategy } from '@popperjs/core';\nimport { Guard } from './mg-tooltip.conf';\n\n/**\n * HTMLMgButtonElement type guard\n * @param element - element to check\n * @returns return true if type is HTMLMgButtonElement\n */\nconst isButton = (element: unknown): element is HTMLMgButtonElement => typeof element === 'object' && ['MG-BUTTON', 'BUTTON'].includes((element as Element).tagName);\n\n/**\n * @slot - Element that will display the tooltip\n * @slot content - Tooltip content\n */\n@Component({\n tag: 'mg-tooltip',\n styleUrl: '../../../../node_modules/@mgdis/styles/dist/components/mg-tooltip.css',\n shadow: true,\n})\nexport class MgTooltip {\n /************\n * Internal *\n ************/\n\n private popper: PopperInstance;\n private mgTooltipContent: HTMLMgTooltipContentElement;\n private tooltipedElement: HTMLElement;\n private windows: Window[];\n private hasCustomTabIndex: boolean;\n\n // tooltip actions guards\n private guard: Guard;\n\n /**************\n * Decorators *\n **************/\n\n /**\n * Get component DOM element\n */\n @Element() element: HTMLMgTooltipElement;\n\n /**\n * Sets an `id` attribute.\n * Needed by the input for accessibility `aria-decribedby`.\n */\n @Prop() identifier: string = createID('mg-tooltip');\n @Watch('identifier')\n watchIdentifier(): void {\n // use renderTooltipContent to update tooltip-content id\n this.renderTooltipContent();\n }\n\n /**\n * Displayed message in the tooltip\n */\n @Prop() message!: string;\n @Watch('message')\n watchMessage(newValue: MgTooltip['message']): void {\n if (!isValidString(newValue)) {\n throw new Error('<mg-tooltip> prop \"message\" is required.');\n }\n this.mgTooltipContent.message = newValue;\n }\n\n /**\n * Tooltip placement\n */\n @Prop() placement: Placement = 'bottom';\n\n /**\n * Display tooltip\n */\n @Prop({ mutable: true }) display = false;\n @Watch('display')\n watchDisplay(newValue: MgTooltip['display']): void {\n if (newValue) {\n this.show();\n } else {\n this.hide();\n }\n }\n\n /**\n * Disable tooltip\n */\n @Prop() disabled = false;\n @Watch('disabled')\n watchDisabled(newValue: MgTooltip['disabled']): void {\n if (this.hasCustomTabIndex) {\n if (newValue) this.tooltipedElement.removeAttribute('tabindex');\n else if (this.tooltipedElement.getAttribute('tabindex') === null) this.tooltipedElement.setAttribute('tabindex', '0');\n }\n }\n\n /**\n * Show tooltip\n */\n private show = (): void => {\n // Make the tooltip visible\n this.mgTooltipContent.dataset.show = '';\n // Enable the event listeners\n this.popper.setOptions(options => ({\n ...options,\n modifiers: [...options.modifiers, { name: 'eventListeners', enabled: true }],\n }));\n // hide when click outside on nextTick to prevent event to trigger after creation\n nextTick(() => {\n this.windows.forEach((localWindow: Window) => {\n localWindow.addEventListener('click', this.handleClickOutside, false);\n localWindow.addEventListener('keydown', this.handlePressEscape, false);\n });\n });\n };\n\n /**\n * Hide tooltip\n */\n private hide = (): void => {\n // Hide the tooltip\n this.mgTooltipContent.removeAttribute('data-show');\n // Disable the event listeners\n this.popper.setOptions(options => ({\n ...options,\n modifiers: [...options.modifiers, { name: 'eventListeners', enabled: false }],\n }));\n // Remove event listener\n this.windows.forEach((localWindow: Window) => {\n localWindow.removeEventListener('click', this.handleClickOutside, false);\n localWindow.removeEventListener('keyboard', this.handlePressEscape, false);\n });\n };\n\n /**\n * Check if clicked outside of component and hidde tooltip\n * @param event - mouse event\n */\n private handleClickOutside = (event: MouseEvent & { target: HTMLElement }): void => {\n if (event.target.closest('mg-tooltip') !== this.element) this.setDisplay(false);\n };\n\n /**\n * Check if 'Escape' key is pressed of component and hidde tooltip\n * @param event - keyboard event\n */\n private handlePressEscape = (event: KeyboardEvent): void => {\n if (event.code === 'Escape') {\n this.setDisplay(false);\n this.resetGuard();\n }\n };\n\n /**\n * Method to set display prop\n * @param newValue - display prop new value\n * @param condition - additionnal condition to apply display prop newValue\n */\n private setDisplay = (newValue: MgTooltip['display'], condition = true): void => {\n if (!this.disabled && condition) this.display = newValue;\n };\n\n /**\n * Action for tooltip element and tooltiped element mouse listener\n * @param elementGuard - tooltip element guard\n * @param eventName - event name\n * @param conditionalGuard - guard condition\n */\n private tooltipMouseListenerAction = (elementGuard: Guard, eventName: 'mouseenter' | 'mouseleave', conditionalGuard: Guard): void => {\n // active FOCUS guard cancel process\n if ([Guard.FOCUS, Guard.DISABLE_ON_CLICK].includes(this.guard)) {\n return;\n }\n\n // Update guard by element guard\n this.guard = elementGuard;\n\n if (eventName !== 'mouseenter') {\n // process action in the next event loop macro task\n setTimeout(() => {\n this.setDisplay(false, this.guard !== conditionalGuard);\n this.resetGuard();\n }, 100);\n } else if (this.guard === Guard.HOVER_TOOLTIPED_ELEMENT) {\n this.setDisplay(true);\n }\n };\n\n /**\n * Method to reset guard value\n */\n private resetGuard = (): void => {\n this.guard = undefined;\n };\n\n /**\n * Update slot content when it is a mg-button\n * @param mgButton - slotted mg-button\n */\n private setMgButtonWrapper = (mgButton: HTMLMgButtonElement): void => {\n if (mgButton.disabled) {\n const div = document.createElement('div');\n div.classList.add('mg-c-tooltip__mg-button-wrapper');\n mgButton.parentNode.insertBefore(div, mgButton);\n div.appendChild(mgButton);\n this.tooltipedElement = div;\n } else if (mgButton.parentElement.classList.contains('mg-c-tooltip__mg-button-wrapper')) {\n this.element.firstElementChild.replaceWith(mgButton);\n this.tooltipedElement = mgButton;\n }\n };\n\n /**\n * Set popper instance\n */\n private setPopper = (): void => {\n // use element data attribute: `data-popper-strategy`, in order to get popper strategy configuration\n const strategy = (this.element.dataset.popperStrategy || 'fixed') as PositioningStrategy;\n\n // Create popperjs tooltip\n this.popper = createPopper(this.tooltipedElement, this.mgTooltipContent, {\n placement: this.placement,\n strategy,\n modifiers: [\n {\n name: 'offset',\n options: {\n offset: [0, 8],\n },\n },\n {\n name: 'flip',\n options: {\n fallbackPlacements: ['auto'],\n },\n },\n ],\n });\n };\n\n /**\n * Define selected element to become tooltip selector and init listeners\n * @param element - tooltiped element\n */\n private setTooltipedElement = (element: HTMLElement): void => {\n this.tooltipedElement = element;\n\n // Manage tooltipedElement focus events\n this.tooltipedElement.addEventListener('focus', () => {\n this.guard = Guard.FOCUS;\n this.setDisplay(true);\n });\n\n // as `click` event is the composition of `mousedown` and `mouseup` event,\n // and `click` event trigger `focus` event after a success `mousedown` wich set the `guard` to `Guard.FOCUS`\n // we reset the guard on `mouseup` event to unlock tooltip\n this.tooltipedElement.addEventListener('mouseup', () => {\n this.resetGuard();\n });\n\n this.tooltipedElement.addEventListener('blur', () => {\n this.resetGuard();\n this.setDisplay(false);\n });\n\n // manage tooltipElement & tooltipedElement mouseenter/mouseleave events\n this.tooltipedElement.addEventListener('mouseenter', () => {\n this.tooltipMouseListenerAction(Guard.HOVER_TOOLTIPED_ELEMENT, 'mouseenter', Guard.HOVER_TOOLTIP_ELEMENT);\n });\n\n this.tooltipedElement.addEventListener('mouseleave', () => {\n this.tooltipMouseListenerAction(Guard.HOVER_TOOLTIPED_ELEMENT, 'mouseleave', Guard.HOVER_TOOLTIP_ELEMENT);\n });\n };\n\n /**\n * Set button mutation observer\n * @param mgButton - mg-button to observe\n */\n private setMgButtonMutationObserver = (mgButton: HTMLMgButtonElement): void => {\n new MutationObserver(mutationList => {\n // stop process when none of mutations attributed is disabled\n if (!mutationList.some(mutation => ['aria-disabled', 'disabled'].includes(mutation.attributeName))) return;\n\n // set guard when one of mutations is for a disabled with disabled-on-click\n if (mutationList.some((mutation: MutationRecord & { target: HTMLMgButtonElement }) => mutation.target.disabled && mutation.target.disableOnClick)) {\n this.guard = Guard.DISABLE_ON_CLICK;\n }\n\n // when the disabled-on-click guard is running we stop process\n if (this.guard === Guard.DISABLE_ON_CLICK) return;\n\n // update button wrapper\n this.setMgButtonWrapper(mgButton);\n\n // Since Firefox doesn't trigger a \"blur\" event when the \"disabled\" attribute is added or removed from a button\n // we have to manually unlock the guard because the \"blur\" handler of the tooltipedElement won't do it.\n this.resetGuard();\n\n // update popper instance\n this.popper.update();\n }).observe(mgButton, { attributes: true });\n };\n\n /**\n * Set tooltiped element aria-describedby\n * @param element - element to update\n */\n private setAriaDescribedby = (element: HTMLElement): void => {\n // Set aria-describedby\n const ariaDescribedby = element.getAttribute('aria-describedby');\n\n if (ariaDescribedby === null) {\n this.tooltipedElement.setAttribute('aria-describedby', this.identifier);\n } else {\n // We ensure to have uniq ids\n element.setAttribute('aria-describedby', `${[...new Set([...ariaDescribedby.split(' '), this.identifier])].join(' ')}`);\n }\n };\n\n /**\n * Render tooltip content element and init listeners\n */\n private renderTooltipContent(): void {\n if (this.mgTooltipContent) {\n this.mgTooltipContent.setAttribute('id', this.identifier);\n } else {\n this.mgTooltipContent = document.createElement('mg-tooltip-content');\n this.mgTooltipContent.setAttribute('slot', 'content');\n this.mgTooltipContent.setAttribute('id', this.identifier);\n\n const arrow = document.createElement('div');\n arrow.setAttribute('slot', 'arrow');\n arrow.dataset.popperArrow = '';\n this.mgTooltipContent.appendChild(arrow);\n\n // manage tooltipElement & tooltipedElement mouseenter/mouseleave events\n this.mgTooltipContent.addEventListener('mouseenter', () => {\n this.tooltipMouseListenerAction(Guard.HOVER_TOOLTIP_ELEMENT, 'mouseenter', Guard.HOVER_TOOLTIPED_ELEMENT);\n });\n this.mgTooltipContent.addEventListener('mouseleave', () => {\n this.tooltipMouseListenerAction(Guard.HOVER_TOOLTIP_ELEMENT, 'mouseleave', Guard.HOVER_TOOLTIPED_ELEMENT);\n });\n\n // append tooltip element to component\n this.element.appendChild(this.mgTooltipContent);\n }\n }\n\n /*************\n * Lifecycle *\n *************/\n\n /**\n * set variables\n */\n componentWillLoad(): void {\n // Get windows to attach events\n this.windows = getWindows(window);\n\n // Get tooltip element\n this.renderTooltipContent();\n\n //validate properties\n this.watchDisabled(this.disabled);\n this.watchMessage(this.message);\n this.watchIdentifier();\n }\n\n /**\n * Get slotted element\n * Check if it already contain an interactive element, if not we need to add a tabIndex attribute\n * We need to attach the focused element to the tooltip (aria-describedby)\n */\n componentDidLoad(): void {\n // get slotted element wich is not the tooltip\n const slotElement: HTMLElement = this.element.querySelector(`*:not(#${this.identifier})`);\n\n // Get interactive element\n const interactiveElement: HTMLElement = slotElement.matches(focusableElements) ? slotElement : slotElement.shadowRoot?.querySelector(focusableElements);\n\n this.setTooltipedElement(interactiveElement || slotElement);\n\n // Check if slotted element is a disabled mg-button\n // In this case we wrap the mg-button into a div to enable the tooltip\n if (isButton(slotElement)) {\n this.setMgButtonMutationObserver(slotElement);\n this.setMgButtonWrapper(slotElement);\n }\n\n // Add tabindex to slotted element if we can't find any interactive element\n if (!this.disabled && !interactiveElement) {\n this.hasCustomTabIndex = true;\n slotElement.tabIndex = 0;\n // Add role on non-interactive element to work with \"aria-describedby\" for screen readers\n slotElement.setAttribute('role', 'button');\n }\n\n // apply a11y aria\n this.setAriaDescribedby(slotElement);\n\n // set Tooltip\n this.setPopper();\n\n // add document keyboard handler\n document.addEventListener('keydown', this.handlePressEscape);\n\n // check props\n this.watchDisplay(this.display);\n }\n\n /**\n * update popper position after props change on component did update hook to benefit from render ended\n */\n componentDidUpdate(): void {\n this.popper.update();\n }\n\n /**\n * Render\n * @returns HTML Element\n */\n render(): HTMLElement {\n return (\n <Host>\n <slot></slot>\n <slot name=\"content\"></slot>\n </Host>\n );\n }\n}\n"],"version":3}
|