@mgdis/mg-components 6.3.0 → 6.5.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/{index-a5b2cd1b.js → index-1a5a1081.js} +331 -162
- package/dist/cjs/index-1a5a1081.js.map +1 -0
- package/dist/cjs/{index-cc11af95.js → index-ede3b3dc.js} +3 -3
- package/dist/cjs/{index-cc11af95.js.map → index-ede3b3dc.js.map} +1 -1
- package/dist/cjs/{index.es-ac7c22e3.js → index.es-a112f649.js} +40 -40
- package/dist/cjs/index.es-a112f649.js.map +1 -0
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/mg-action-more_36.cjs.entry.js +3411 -2633
- package/dist/cjs/mg-action-more_36.cjs.entry.js.map +1 -1
- package/dist/cjs/mg-alert.cjs.entry.js +15 -12
- package/dist/cjs/mg-alert.cjs.entry.js.map +1 -1
- package/dist/cjs/mg-components.cjs.js +3 -3
- package/dist/cjs/mg-components.cjs.js.map +1 -1
- package/dist/cjs/mg-loader.cjs.entry.js +5 -7
- package/dist/cjs/mg-loader.cjs.entry.js.map +1 -1
- package/dist/cjs/mg-progress.cjs.entry.js +26 -11
- package/dist/cjs/mg-progress.cjs.entry.js.map +1 -1
- package/dist/collection/collection-manifest.json +2 -2
- package/dist/collection/components/atoms/internals/mg-character-left/mg-character-left.js +10 -3
- package/dist/collection/components/atoms/internals/mg-character-left/mg-character-left.js.map +1 -1
- package/dist/collection/components/atoms/internals/mg-input-title/mg-input-title.js +15 -4
- package/dist/collection/components/atoms/internals/mg-input-title/mg-input-title.js.map +1 -1
- package/dist/collection/components/atoms/mg-badge/mg-badge.js +15 -4
- package/dist/collection/components/atoms/mg-badge/mg-badge.js.map +1 -1
- package/dist/collection/components/atoms/mg-button/mg-button.js +50 -11
- package/dist/collection/components/atoms/mg-button/mg-button.js.map +1 -1
- package/dist/collection/components/atoms/mg-card/mg-card.js +1 -1
- package/dist/collection/components/atoms/mg-divider/mg-divider.js +9 -1
- package/dist/collection/components/atoms/mg-divider/mg-divider.js.map +1 -1
- package/dist/collection/components/atoms/mg-icon/mg-icon.js +22 -6
- package/dist/collection/components/atoms/mg-icon/mg-icon.js.map +1 -1
- package/dist/collection/components/atoms/mg-tag/mg-tag.js +14 -4
- package/dist/collection/components/atoms/mg-tag/mg-tag.js.map +1 -1
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip-content/mg-tooltip-content.js +3 -4
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip-content/mg-tooltip-content.js.map +1 -1
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.conf.js +1 -0
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.conf.js.map +1 -1
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +95 -43
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input/mg-input.js +50 -13
- package/dist/collection/components/molecules/inputs/mg-input/mg-input.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox-paginated/mg-input-checkbox-paginated.js +29 -11
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox-paginated/mg-input-checkbox-paginated.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +106 -33
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +99 -36
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +130 -35
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +87 -25
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +86 -26
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +92 -30
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +108 -31
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +109 -29
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +67 -21
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js.map +1 -1
- package/dist/collection/components/molecules/internals/mg-item-more/mg-item-more.js +16 -70
- package/dist/collection/components/molecules/internals/mg-item-more/mg-item-more.js.map +1 -1
- package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js +101 -89
- 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 +202 -157
- package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js.map +1 -1
- package/dist/collection/components/molecules/mg-action-more/mg-action-more.js +19 -8
- package/dist/collection/components/molecules/mg-action-more/mg-action-more.js.map +1 -1
- package/dist/collection/components/molecules/mg-alert/mg-alert.js +15 -6
- package/dist/collection/components/molecules/mg-alert/mg-alert.js.map +1 -1
- package/dist/collection/components/molecules/mg-details/mg-details.js +22 -5
- package/dist/collection/components/molecules/mg-details/mg-details.js.map +1 -1
- package/dist/collection/components/molecules/mg-form/mg-form.js +48 -16
- package/dist/collection/components/molecules/mg-form/mg-form.js.map +1 -1
- package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js +13 -3
- package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js.map +1 -1
- package/dist/collection/components/molecules/mg-loader/mg-loader.js +5 -5
- package/dist/collection/components/molecules/mg-loader/mg-loader.js.map +1 -1
- package/dist/collection/components/molecules/mg-message/mg-message.js +22 -6
- package/dist/collection/components/molecules/mg-message/mg-message.js.map +1 -1
- package/dist/collection/components/molecules/mg-modal/mg-modal.js +37 -9
- package/dist/collection/components/molecules/mg-modal/mg-modal.js.map +1 -1
- package/dist/collection/components/molecules/mg-pagination/mg-pagination.js +28 -9
- package/dist/collection/components/molecules/mg-pagination/mg-pagination.js.map +1 -1
- package/dist/collection/components/molecules/mg-panel/mg-panel.js +48 -13
- package/dist/collection/components/molecules/mg-panel/mg-panel.js.map +1 -1
- package/dist/collection/components/molecules/mg-popover/mg-popover-content/mg-popover-content.js +10 -2
- package/dist/collection/components/molecules/mg-popover/mg-popover-content/mg-popover-content.js.map +1 -1
- package/dist/collection/components/molecules/mg-popover/mg-popover.conf.js +2 -0
- package/dist/collection/components/molecules/mg-popover/mg-popover.conf.js.map +1 -0
- package/dist/collection/components/molecules/mg-popover/mg-popover.js +133 -52
- package/dist/collection/components/molecules/mg-popover/mg-popover.js.map +1 -1
- package/dist/collection/components/molecules/mg-progress/mg-progress.js +26 -1
- package/dist/collection/components/molecules/mg-progress/mg-progress.js.map +1 -1
- package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js +3 -2
- package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js.map +1 -1
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +28 -8
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.js.map +1 -1
- package/dist/collection/utils/behaviors.utils.js +44 -107
- package/dist/collection/utils/behaviors.utils.js.map +1 -1
- package/dist/collection/utils/floating-ui.utils.js +33 -0
- package/dist/collection/utils/floating-ui.utils.js.map +1 -0
- package/dist/components/floating-ui.utils.js +2099 -0
- package/dist/components/floating-ui.utils.js.map +1 -0
- package/dist/components/index.es.js +37 -37
- package/dist/components/index.es.js.map +1 -1
- package/dist/components/index2.js +2 -2
- package/dist/components/mg-action-more.js +15 -12
- package/dist/components/mg-action-more.js.map +1 -1
- package/dist/components/mg-alert.js +13 -10
- package/dist/components/mg-alert.js.map +1 -1
- package/dist/components/mg-badge2.js +12 -9
- package/dist/components/mg-badge2.js.map +1 -1
- package/dist/components/mg-button2.js +36 -15
- package/dist/components/mg-button2.js.map +1 -1
- package/dist/components/mg-card2.js +2 -2
- package/dist/components/mg-card2.js.map +1 -1
- package/dist/components/mg-character-left2.js +8 -7
- package/dist/components/mg-character-left2.js.map +1 -1
- package/dist/components/mg-details.js +14 -5
- package/dist/components/mg-details.js.map +1 -1
- package/dist/components/mg-divider2.js +7 -1
- package/dist/components/mg-divider2.js.map +1 -1
- package/dist/components/mg-form.js +35 -21
- package/dist/components/mg-form.js.map +1 -1
- package/dist/components/mg-icon2.js +17 -11
- package/dist/components/mg-icon2.js.map +1 -1
- package/dist/components/mg-illustrated-message.js +12 -6
- package/dist/components/mg-illustrated-message.js.map +1 -1
- package/dist/components/mg-input-checkbox-paginated2.js +14 -10
- package/dist/components/mg-input-checkbox-paginated2.js.map +1 -1
- package/dist/components/mg-input-checkbox.js +69 -36
- package/dist/components/mg-input-checkbox.js.map +1 -1
- package/dist/components/mg-input-date.js +75 -44
- package/dist/components/mg-input-date.js.map +1 -1
- package/dist/components/mg-input-numeric.js +88 -43
- package/dist/components/mg-input-numeric.js.map +1 -1
- package/dist/components/mg-input-password.js +54 -26
- package/dist/components/mg-input-password.js.map +1 -1
- package/dist/components/mg-input-radio.js +58 -30
- package/dist/components/mg-input-radio.js.map +1 -1
- package/dist/components/mg-input-select2.js +58 -34
- package/dist/components/mg-input-select2.js.map +1 -1
- package/dist/components/mg-input-text2.js +67 -36
- package/dist/components/mg-input-text2.js.map +1 -1
- package/dist/components/mg-input-textarea.js +69 -33
- package/dist/components/mg-input-textarea.js.map +1 -1
- package/dist/components/mg-input-title2.js +10 -7
- package/dist/components/mg-input-title2.js.map +1 -1
- package/dist/components/mg-input-toggle.js +42 -24
- package/dist/components/mg-input-toggle.js.map +1 -1
- package/dist/components/mg-input2.js +35 -18
- package/dist/components/mg-input2.js.map +1 -1
- package/dist/components/mg-item-more2.js +146 -270
- package/dist/components/mg-item-more2.js.map +1 -1
- package/dist/components/mg-loader.js +3 -5
- package/dist/components/mg-loader.js.map +1 -1
- package/dist/components/mg-menu-item2.js +200 -148
- package/dist/components/mg-menu-item2.js.map +1 -1
- package/dist/components/mg-message2.js +22 -10
- package/dist/components/mg-message2.js.map +1 -1
- package/dist/components/mg-modal.js +33 -15
- package/dist/components/mg-modal.js.map +1 -1
- package/dist/components/mg-pagination2.js +21 -14
- package/dist/components/mg-pagination2.js.map +1 -1
- package/dist/components/mg-panel.js +37 -20
- package/dist/components/mg-panel.js.map +1 -1
- package/dist/components/mg-popover-content2.js +11 -5
- package/dist/components/mg-popover-content2.js.map +1 -1
- package/dist/components/mg-popover2.js +119 -52
- package/dist/components/mg-popover2.js.map +1 -1
- package/dist/components/mg-progress.js +25 -10
- package/dist/components/mg-progress.js.map +1 -1
- package/dist/components/mg-skip-links.js +0 -1
- package/dist/components/mg-skip-links.js.map +1 -1
- package/dist/components/mg-tabs.js +26 -16
- package/dist/components/mg-tabs.js.map +1 -1
- package/dist/components/mg-tag.js +11 -7
- package/dist/components/mg-tag.js.map +1 -1
- package/dist/components/mg-tooltip-content2.js +2 -3
- package/dist/components/mg-tooltip-content2.js.map +1 -1
- package/dist/components/mg-tooltip2.js +86 -45
- package/dist/components/mg-tooltip2.js.map +1 -1
- package/dist/esm/{index-eb0e1053.js → index-5059254f.js} +331 -162
- package/dist/esm/index-5059254f.js.map +1 -0
- package/dist/esm/{index-f3d3fb70.js → index-a7c3b5c5.js} +3 -3
- package/dist/esm/{index-f3d3fb70.js.map → index-a7c3b5c5.js.map} +1 -1
- package/dist/esm/{index.es-940821a9.js → index.es-5e0101ac.js} +38 -38
- package/dist/esm/index.es-5e0101ac.js.map +1 -0
- package/dist/esm/loader.js +3 -3
- package/dist/esm/mg-action-more_36.entry.js +3411 -2633
- package/dist/esm/mg-action-more_36.entry.js.map +1 -1
- package/dist/esm/mg-alert.entry.js +15 -12
- package/dist/esm/mg-alert.entry.js.map +1 -1
- package/dist/esm/mg-components.js +4 -4
- package/dist/esm/mg-components.js.map +1 -1
- package/dist/esm/mg-loader.entry.js +5 -7
- package/dist/esm/mg-loader.entry.js.map +1 -1
- package/dist/esm/mg-progress.entry.js +26 -11
- package/dist/esm/mg-progress.entry.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-1a162791.entry.js +2 -0
- package/dist/mg-components/{p-d0086664.entry.js.map → p-1a162791.entry.js.map} +1 -1
- package/dist/mg-components/p-2403e01d.entry.js +2 -0
- package/dist/mg-components/p-2403e01d.entry.js.map +1 -0
- package/dist/mg-components/p-6c831a83.entry.js +2 -0
- package/dist/mg-components/p-6c831a83.entry.js.map +1 -0
- package/dist/mg-components/p-ad64ab4a.entry.js +2 -0
- package/dist/mg-components/p-ad64ab4a.entry.js.map +1 -0
- package/dist/mg-components/{p-ee51ec5e.js → p-b6c1a6ce.js} +2 -2
- package/dist/mg-components/p-b6c1a6ce.js.map +1 -0
- package/dist/mg-components/{p-a49e2b74.js → p-d9731ebc.js} +2 -2
- package/dist/mg-components/p-e39791fa.js +3 -0
- package/dist/mg-components/p-e39791fa.js.map +1 -0
- package/dist/types/components/atoms/mg-tooltip/mg-tooltip.conf.d.ts +6 -0
- package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +7 -6
- package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +6 -0
- package/dist/types/components/molecules/internals/mg-item-more/mg-item-more.d.ts +1 -15
- package/dist/types/components/molecules/menu/mg-menu/mg-menu.d.ts +14 -30
- package/dist/types/components/molecules/menu/mg-menu-item/mg-menu-item.d.ts +54 -39
- package/dist/types/components/molecules/mg-details/mg-details.d.ts +4 -0
- package/dist/types/components/molecules/mg-popover/mg-popover.conf.d.ts +6 -0
- package/dist/types/components/molecules/mg-popover/mg-popover.d.ts +13 -8
- package/dist/types/components.d.ts +8 -11
- package/dist/types/utils/behaviors.utils.d.ts +15 -44
- package/dist/types/utils/floating-ui.utils.d.ts +19 -0
- package/ide/intellij/web-types.json +3 -7
- package/ide/vscode/html-custom-data.json +2 -2
- package/package.json +24 -24
- package/dist/cjs/index-a5b2cd1b.js.map +0 -1
- package/dist/cjs/index.es-ac7c22e3.js.map +0 -1
- package/dist/components/popper.js +0 -1794
- package/dist/components/popper.js.map +0 -1
- package/dist/esm/index-eb0e1053.js.map +0 -1
- package/dist/esm/index.es-940821a9.js.map +0 -1
- package/dist/mg-components/p-15b6849a.js +0 -3
- package/dist/mg-components/p-15b6849a.js.map +0 -1
- package/dist/mg-components/p-3aecf564.entry.js +0 -2
- package/dist/mg-components/p-3aecf564.entry.js.map +0 -1
- package/dist/mg-components/p-6f3d70b2.entry.js +0 -2
- package/dist/mg-components/p-6f3d70b2.entry.js.map +0 -1
- package/dist/mg-components/p-a17ea0af.entry.js +0 -2
- package/dist/mg-components/p-a17ea0af.entry.js.map +0 -1
- package/dist/mg-components/p-d0086664.entry.js +0 -2
- package/dist/mg-components/p-ee51ec5e.js.map +0 -1
- /package/dist/mg-components/{p-a49e2b74.js.map → p-d9731ebc.js.map} +0 -0
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
import { Host, h } from "@stencil/core";
|
|
2
2
|
import { createID, getWindows, isValideID, toString } from "@mgdis/stencil-helpers";
|
|
3
|
-
import {
|
|
3
|
+
import { computePosition, autoUpdate, flip, shift, limitShift, offset, arrow } from "@floating-ui/dom";
|
|
4
|
+
import { isFloatingUIPlacement, sides } from "./mg-popover.conf";
|
|
4
5
|
/**
|
|
5
6
|
* @slot - Element that will display the popover
|
|
6
7
|
* @slot content - popover content
|
|
7
8
|
*/
|
|
8
9
|
export class MgPopover {
|
|
9
10
|
constructor() {
|
|
11
|
+
/**
|
|
12
|
+
* Sets an `id` attribute.
|
|
13
|
+
* Needed by the input for accessibility `aria-decribedby`.
|
|
14
|
+
*/
|
|
15
|
+
this.identifier = createID('mg-popover');
|
|
16
|
+
/**
|
|
17
|
+
* Popover placement
|
|
18
|
+
*/
|
|
19
|
+
this.placement = 'bottom';
|
|
20
|
+
/**
|
|
21
|
+
* Hide popover arrow
|
|
22
|
+
*/
|
|
23
|
+
this.arrowHide = false;
|
|
24
|
+
/**
|
|
25
|
+
* Define if popover has a cross button
|
|
26
|
+
*/
|
|
27
|
+
this.closeButton = false;
|
|
28
|
+
/**
|
|
29
|
+
* Display popover
|
|
30
|
+
*/
|
|
31
|
+
this.display = false;
|
|
32
|
+
/**
|
|
33
|
+
* Disable popover
|
|
34
|
+
*/
|
|
35
|
+
this.disabled = false;
|
|
10
36
|
/**
|
|
11
37
|
* Check if clicked outside of component
|
|
12
38
|
* @param event - mouse event
|
|
@@ -22,8 +48,6 @@ export class MgPopover {
|
|
|
22
48
|
this.show = () => {
|
|
23
49
|
// Make the popover visible
|
|
24
50
|
this.mgPopover.dataset.show = '';
|
|
25
|
-
// Enable the event listeners
|
|
26
|
-
this.setPopperListeners(true);
|
|
27
51
|
// hide when click outside
|
|
28
52
|
// setTimeout is used to prevent event to trigger after creation
|
|
29
53
|
setTimeout(() => {
|
|
@@ -36,18 +60,9 @@ export class MgPopover {
|
|
|
36
60
|
this.hide = () => {
|
|
37
61
|
// Hide the popover
|
|
38
62
|
this.mgPopover.removeAttribute('data-show');
|
|
39
|
-
// Disable the event listeners
|
|
40
|
-
this.setPopperListeners(false);
|
|
41
63
|
// Remove event listener
|
|
42
64
|
this.manageClickOutsideListeners('removeEventListener');
|
|
43
65
|
};
|
|
44
|
-
/**
|
|
45
|
-
* Set popper listeners
|
|
46
|
-
* @param newValue - if true enable popper listners
|
|
47
|
-
*/
|
|
48
|
-
this.setPopperListeners = (newValue) => {
|
|
49
|
-
this.popper.setOptions(options => (Object.assign(Object.assign({}, options), { modifiers: [...options.modifiers, { name: 'eventListeners', enabled: newValue }] })));
|
|
50
|
-
};
|
|
51
66
|
/**
|
|
52
67
|
* Manage all clickOustside listeners
|
|
53
68
|
* @param action - top process on elements listeners
|
|
@@ -85,7 +100,7 @@ export class MgPopover {
|
|
|
85
100
|
this.mgPopoverContent.addEventListener('hide-content', this.handleHideContent);
|
|
86
101
|
const arrow = document.createElement('div');
|
|
87
102
|
arrow.setAttribute('slot', 'arrow');
|
|
88
|
-
arrow.dataset.
|
|
103
|
+
arrow.dataset.floatingArrow = '';
|
|
89
104
|
this.mgPopoverContent.appendChild(arrow);
|
|
90
105
|
// insert elements in DOM
|
|
91
106
|
['[slot="title"]', '[slot="content"]:not(mg-popover-content)'].forEach(slotType => {
|
|
@@ -99,12 +114,61 @@ export class MgPopover {
|
|
|
99
114
|
mgPopoverContent.setAttribute('id', this.identifier);
|
|
100
115
|
}
|
|
101
116
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this.
|
|
107
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Set up Floating UI positioning and arrow behavior
|
|
119
|
+
* @param interactiveElement - Element that triggers the popover
|
|
120
|
+
*/
|
|
121
|
+
this.setFloatingUI = (interactiveElement) => {
|
|
122
|
+
const fallbackPlacements = (this.element.dataset.fallbackPlacement || '').split(',').map(t => t.trim());
|
|
123
|
+
this.floatingUICleanup = autoUpdate(interactiveElement, this.mgPopover, () => {
|
|
124
|
+
computePosition(interactiveElement, this.mgPopover, {
|
|
125
|
+
placement: this.placement,
|
|
126
|
+
strategy: 'fixed',
|
|
127
|
+
middleware: [
|
|
128
|
+
offset(0),
|
|
129
|
+
flip({
|
|
130
|
+
fallbackPlacements: Array.from(new Set([...fallbackPlacements, ...sides]).values()).filter(isFloatingUIPlacement), // simulate "auto" placement with default fallback values
|
|
131
|
+
}),
|
|
132
|
+
shift({
|
|
133
|
+
limiter: limitShift(),
|
|
134
|
+
}),
|
|
135
|
+
arrow({
|
|
136
|
+
element: this.mgPopover.querySelector('[data-floating-arrow]'),
|
|
137
|
+
}),
|
|
138
|
+
],
|
|
139
|
+
}).then(({ x, y, placement, middlewareData }) => {
|
|
140
|
+
Object.assign(this.mgPopover.style, {
|
|
141
|
+
position: 'fixed',
|
|
142
|
+
top: '0',
|
|
143
|
+
left: '0',
|
|
144
|
+
transform: `translate(${Math.round(x)}px, ${Math.round(y)}px)`,
|
|
145
|
+
});
|
|
146
|
+
// Update arrow style
|
|
147
|
+
const staticSide = {
|
|
148
|
+
top: 'bottom',
|
|
149
|
+
right: 'left',
|
|
150
|
+
bottom: 'top',
|
|
151
|
+
left: 'right',
|
|
152
|
+
}[placement.split('-')[0]];
|
|
153
|
+
const arrowElement = this.mgPopover.querySelector('[data-floating-arrow]');
|
|
154
|
+
const { x: arrowX, y: arrowY } = middlewareData.arrow;
|
|
155
|
+
// https://floating-ui.com/docs/arrow
|
|
156
|
+
// Unlike the floating element, which has both coordinates defined at all times, the arrow only has one defined.
|
|
157
|
+
// Due to this, either x or y will be undefined, depending on the side of placement.
|
|
158
|
+
// The above code uses `isNaN` to check for null and undefined simultaneously.
|
|
159
|
+
// Don’t remove `isNaN`, because either value can be falsy (0), causing a bug!
|
|
160
|
+
const numberToPx = (number) => !isNaN(number) ? `${number}px` : '';
|
|
161
|
+
if (arrowElement !== null)
|
|
162
|
+
Object.assign(arrowElement.style, {
|
|
163
|
+
position: 'absolute',
|
|
164
|
+
left: numberToPx(arrowX),
|
|
165
|
+
top: numberToPx(arrowY),
|
|
166
|
+
[staticSide]: '1px',
|
|
167
|
+
});
|
|
168
|
+
this.mgPopover.setAttribute('data-placement', placement);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
108
172
|
}
|
|
109
173
|
validateIdentifier(newValue) {
|
|
110
174
|
if (!isValideID(newValue)) {
|
|
@@ -113,6 +177,10 @@ export class MgPopover {
|
|
|
113
177
|
// use renderPopoverContent to update popover-content id
|
|
114
178
|
this.renderPopoverContent();
|
|
115
179
|
}
|
|
180
|
+
watchPlacement(newValue) {
|
|
181
|
+
if (!isFloatingUIPlacement(newValue))
|
|
182
|
+
this.placement = 'bottom';
|
|
183
|
+
}
|
|
116
184
|
validateArrowHide(newValue) {
|
|
117
185
|
if (newValue)
|
|
118
186
|
this.mgPopoverContent.dataset.arrowHide = '';
|
|
@@ -138,7 +206,7 @@ export class MgPopover {
|
|
|
138
206
|
* update popper position after props change on component did update hook to benefit from render ended
|
|
139
207
|
*/
|
|
140
208
|
componentDidUpdate() {
|
|
141
|
-
this.
|
|
209
|
+
this.floatingUICleanup();
|
|
142
210
|
}
|
|
143
211
|
/**
|
|
144
212
|
* Check if component props are well configured on init
|
|
@@ -151,6 +219,7 @@ export class MgPopover {
|
|
|
151
219
|
this.validateCloseButton(this.closeButton);
|
|
152
220
|
this.validateIdentifier(this.identifier);
|
|
153
221
|
this.validateArrowHide(this.arrowHide);
|
|
222
|
+
this.watchPlacement(this.placement);
|
|
154
223
|
}
|
|
155
224
|
/**
|
|
156
225
|
* Check if component props are well configured on init
|
|
@@ -158,38 +227,22 @@ export class MgPopover {
|
|
|
158
227
|
componentDidLoad() {
|
|
159
228
|
// Get popover content
|
|
160
229
|
this.mgPopover = this.element.querySelector(`#${this.identifier}`);
|
|
161
|
-
//Get interactive element (first element without slot attribute)
|
|
230
|
+
// Get interactive element (first element without slot attribute)
|
|
162
231
|
const interactiveElement = this.element.querySelector(':not([slot])');
|
|
163
232
|
// Add aria attributes
|
|
164
233
|
interactiveElement.setAttribute('aria-controls', this.identifier);
|
|
165
234
|
interactiveElement.setAttribute('aria-expanded', `${this.display}`);
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
// Create popperjs popover
|
|
171
|
-
this.popper = createPopper(interactiveElement, this.mgPopover, {
|
|
172
|
-
placement: this.placement,
|
|
173
|
-
strategy: 'fixed',
|
|
174
|
-
modifiers: [
|
|
175
|
-
{
|
|
176
|
-
name: 'offset',
|
|
177
|
-
options: {
|
|
178
|
-
offset: [0, 0],
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
name: 'flip',
|
|
183
|
-
options: {
|
|
184
|
-
fallbackPlacements: [...fallbackPlacements, 'auto'],
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
],
|
|
235
|
+
// Initial styles configuration
|
|
236
|
+
Object.assign(this.mgPopover.style, {
|
|
237
|
+
position: 'fixed',
|
|
188
238
|
});
|
|
189
|
-
//
|
|
190
|
-
|
|
239
|
+
// Create Floating UI instance
|
|
240
|
+
this.setFloatingUI(interactiveElement);
|
|
241
|
+
// Add resize observer
|
|
242
|
+
[interactiveElement, this.mgPopoverContent].forEach(element => {
|
|
191
243
|
new ResizeObserver(() => {
|
|
192
|
-
this.
|
|
244
|
+
this.floatingUICleanup();
|
|
245
|
+
this.setFloatingUI(interactiveElement);
|
|
193
246
|
}).observe(element);
|
|
194
247
|
});
|
|
195
248
|
// Add events to toggle display
|
|
@@ -197,6 +250,12 @@ export class MgPopover {
|
|
|
197
250
|
if (!this.disabled)
|
|
198
251
|
this.display = !this.display;
|
|
199
252
|
});
|
|
253
|
+
this.element.addEventListener('click', (event) => {
|
|
254
|
+
const target = event.target.closest('[popovertargetaction]');
|
|
255
|
+
if (this.display === true && target !== null && target.getAttribute('popovertargetaction') === 'hide') {
|
|
256
|
+
this.display = false;
|
|
257
|
+
}
|
|
258
|
+
});
|
|
200
259
|
// Add events to hide popover
|
|
201
260
|
this.element.addEventListener('keydown', e => {
|
|
202
261
|
if (!this.disabled && e.code === 'Escape') {
|
|
@@ -207,12 +266,19 @@ export class MgPopover {
|
|
|
207
266
|
});
|
|
208
267
|
this.handleDisplay(this.display);
|
|
209
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Cleanup when component is disconnected
|
|
271
|
+
*/
|
|
272
|
+
disconnectedCallback() {
|
|
273
|
+
// Cleanup Floating UI instance
|
|
274
|
+
this.floatingUICleanup();
|
|
275
|
+
}
|
|
210
276
|
/**
|
|
211
277
|
* Render
|
|
212
278
|
* @returns HTML Element
|
|
213
279
|
*/
|
|
214
280
|
render() {
|
|
215
|
-
return (h(Host, { key: '
|
|
281
|
+
return (h(Host, { key: 'dcb411338bed9dcc0758af157359b69f639020d2' }, h("slot", { key: '807fd80367febef76b14553b5b04f6246ca7dce8' }), h("slot", { key: '39ac969b6ed9903f37131778e884c81a912a762d', name: "content" })));
|
|
216
282
|
}
|
|
217
283
|
static get is() { return "mg-popover"; }
|
|
218
284
|
static get encapsulation() { return "shadow"; }
|
|
@@ -242,21 +308,23 @@ export class MgPopover {
|
|
|
242
308
|
"tags": [],
|
|
243
309
|
"text": "Sets an `id` attribute.\nNeeded by the input for accessibility `aria-decribedby`."
|
|
244
310
|
},
|
|
311
|
+
"getter": false,
|
|
312
|
+
"setter": false,
|
|
245
313
|
"attribute": "identifier",
|
|
246
314
|
"reflect": false,
|
|
247
315
|
"defaultValue": "createID('mg-popover')"
|
|
248
316
|
},
|
|
249
317
|
"placement": {
|
|
250
318
|
"type": "string",
|
|
251
|
-
"mutable":
|
|
319
|
+
"mutable": true,
|
|
252
320
|
"complexType": {
|
|
253
|
-
"original": "
|
|
321
|
+
"original": "PopoverPlacementType",
|
|
254
322
|
"resolved": "\"auto\" | \"auto-end\" | \"auto-start\" | \"bottom\" | \"bottom-end\" | \"bottom-start\" | \"left\" | \"left-end\" | \"left-start\" | \"right\" | \"right-end\" | \"right-start\" | \"top\" | \"top-end\" | \"top-start\"",
|
|
255
323
|
"references": {
|
|
256
|
-
"
|
|
324
|
+
"PopoverPlacementType": {
|
|
257
325
|
"location": "import",
|
|
258
|
-
"path": "
|
|
259
|
-
"id": "
|
|
326
|
+
"path": "./mg-popover.conf",
|
|
327
|
+
"id": "src/components/molecules/mg-popover/mg-popover.conf.tsx::PopoverPlacementType"
|
|
260
328
|
}
|
|
261
329
|
}
|
|
262
330
|
},
|
|
@@ -266,6 +334,8 @@ export class MgPopover {
|
|
|
266
334
|
"tags": [],
|
|
267
335
|
"text": "Popover placement"
|
|
268
336
|
},
|
|
337
|
+
"getter": false,
|
|
338
|
+
"setter": false,
|
|
269
339
|
"attribute": "placement",
|
|
270
340
|
"reflect": false,
|
|
271
341
|
"defaultValue": "'bottom'"
|
|
@@ -284,6 +354,8 @@ export class MgPopover {
|
|
|
284
354
|
"tags": [],
|
|
285
355
|
"text": "Hide popover arrow"
|
|
286
356
|
},
|
|
357
|
+
"getter": false,
|
|
358
|
+
"setter": false,
|
|
287
359
|
"attribute": "arrow-hide",
|
|
288
360
|
"reflect": false,
|
|
289
361
|
"defaultValue": "false"
|
|
@@ -302,6 +374,8 @@ export class MgPopover {
|
|
|
302
374
|
"tags": [],
|
|
303
375
|
"text": "Define if popover has a cross button"
|
|
304
376
|
},
|
|
377
|
+
"getter": false,
|
|
378
|
+
"setter": false,
|
|
305
379
|
"attribute": "close-button",
|
|
306
380
|
"reflect": false,
|
|
307
381
|
"defaultValue": "false"
|
|
@@ -320,6 +394,8 @@ export class MgPopover {
|
|
|
320
394
|
"tags": [],
|
|
321
395
|
"text": "Display popover"
|
|
322
396
|
},
|
|
397
|
+
"getter": false,
|
|
398
|
+
"setter": false,
|
|
323
399
|
"attribute": "display",
|
|
324
400
|
"reflect": false,
|
|
325
401
|
"defaultValue": "false"
|
|
@@ -338,6 +414,8 @@ export class MgPopover {
|
|
|
338
414
|
"tags": [],
|
|
339
415
|
"text": "Disable popover"
|
|
340
416
|
},
|
|
417
|
+
"getter": false,
|
|
418
|
+
"setter": false,
|
|
341
419
|
"attribute": "disabled",
|
|
342
420
|
"reflect": false,
|
|
343
421
|
"defaultValue": "false"
|
|
@@ -387,6 +465,9 @@ export class MgPopover {
|
|
|
387
465
|
return [{
|
|
388
466
|
"propName": "identifier",
|
|
389
467
|
"methodName": "validateIdentifier"
|
|
468
|
+
}, {
|
|
469
|
+
"propName": "placement",
|
|
470
|
+
"methodName": "watchPlacement"
|
|
390
471
|
}, {
|
|
391
472
|
"propName": "arrowHide",
|
|
392
473
|
"methodName": "validateArrowHide"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mg-popover.js","sourceRoot":"","sources":["../../../../src/components/molecules/mg-popover/mg-popover.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAgB,KAAK,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAA8B,YAAY,EAAa,MAAM,gBAAgB,CAAC;AAErF;;;GAGG;AAMH,MAAM,OAAO,SAAS;;QAsFpB;;;WAGG;QACK,iBAAY,GAAG,CAAC,KAA2C,EAAQ,EAAE;YAC3E,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,2BAA2B,IAAI,CAAC,UAAU,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC3J,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACvB,CAAC;QACH,CAAC,CAAC;QAEF;;WAEG;QACK,SAAI,GAAG,GAAS,EAAE;YACxB,2BAA2B;YAC3B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC;YACjC,6BAA6B;YAC7B,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;YAC9B,0BAA0B;YAC1B,gEAAgE;YAChE,UAAU,CAAC,GAAG,EAAE;gBACd,IAAI,CAAC,2BAA2B,CAAC,kBAAkB,CAAC,CAAC;YACvD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QAEF;;WAEG;QACK,SAAI,GAAG,GAAS,EAAE;YACxB,mBAAmB;YACnB,IAAI,CAAC,SAAS,CAAC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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, Host, h, Prop, Watch, EventEmitter, Event } from '@stencil/core';\nimport { createID, getWindows, isValideID, toString } from '@mgdis/stencil-helpers';\nimport { Instance as PopperInstance, createPopper, Placement } from '@popperjs/core';\n\n/**\n * @slot - Element that will display the popover\n * @slot content - popover content\n */\n@Component({\n tag: 'mg-popover',\n styleUrl: '../../../../node_modules/@mgdis/styles/dist/components/mg-popover.css',\n shadow: true,\n})\nexport class MgPopover {\n /************\n * Internal *\n ************/\n\n private popper: PopperInstance;\n private mgPopover: HTMLElement;\n private mgPopoverContent: HTMLMgPopoverContentElement;\n private windows: Window[];\n\n /**************\n * Decorators *\n **************/\n\n /**\n * Get component DOM element\n */\n @Element() element: HTMLMgPopoverElement;\n\n /**\n * Sets an `id` attribute.\n * Needed by the input for accessibility `aria-decribedby`.\n */\n @Prop() identifier: string = createID('mg-popover');\n @Watch('identifier')\n validateIdentifier(newValue: MgPopover['identifier']): void {\n if (!isValideID(newValue)) {\n throw new Error(`<mg-popover> prop \"identifier\" value is invalid. Passed value: ${toString(newValue)}.`);\n }\n // use renderPopoverContent to update popover-content id\n this.renderPopoverContent();\n }\n\n /**\n * Popover placement\n */\n @Prop() placement: Placement = 'bottom';\n\n /**\n * Hide popover arrow\n */\n @Prop() arrowHide = false;\n @Watch('arrowHide')\n validateArrowHide(newValue: MgPopover['arrowHide']): void {\n if (newValue) this.mgPopoverContent.dataset.arrowHide = '';\n else delete this.mgPopoverContent.dataset.arrowHide;\n }\n\n /**\n * Define if popover has a cross button\n */\n @Prop() closeButton = false;\n @Watch('closeButton')\n validateCloseButton(newValue: MgPopover['closeButton']): void {\n this.mgPopoverContent.closeButton = newValue;\n }\n\n /**\n * Display popover\n */\n @Prop({ mutable: true }) display = false;\n @Watch('display')\n handleDisplay(newValue: boolean): void {\n if (newValue) {\n this.show();\n } else {\n this.hide();\n }\n this.displayChange.emit(newValue);\n }\n\n /**\n * Disable popover\n */\n @Prop() disabled = false;\n\n /**\n * Emited event when display value change\n */\n @Event({ eventName: 'display-change' }) displayChange: EventEmitter<HTMLMgPopoverElement['display']>;\n\n /**\n * Emmited event when popover is closed\n */\n @Event({ eventName: 'component-close' }) componentClose: EventEmitter<void>;\n\n /**\n * Check if clicked outside of component\n * @param event - mouse event\n */\n private clickOutside = (event: MouseEvent & { target: HTMLElement }): void => {\n if (!this.disabled && event.target.closest('mg-popover') !== this.element && event.target.closest(`[data-mg-popover-guard=\"${this.identifier}\"]`) === null) {\n this.display = false;\n }\n };\n\n /**\n * Show popover\n */\n private show = (): void => {\n // Make the popover visible\n this.mgPopover.dataset.show = '';\n // Enable the event listeners\n this.setPopperListeners(true);\n // hide when click outside\n // setTimeout is used to prevent event to trigger after creation\n setTimeout(() => {\n this.manageClickOutsideListeners('addEventListener');\n });\n };\n\n /**\n * Hide popover\n */\n private hide = (): void => {\n // Hide the popover\n this.mgPopover.removeAttribute('data-show');\n // Disable the event listeners\n this.setPopperListeners(false);\n // Remove event listener\n this.manageClickOutsideListeners('removeEventListener');\n };\n\n /**\n * Set popper listeners\n * @param newValue - if true enable popper listners\n */\n private setPopperListeners = (newValue: boolean): void => {\n this.popper.setOptions(options => ({\n ...options,\n modifiers: [...options.modifiers, { name: 'eventListeners', enabled: newValue }],\n }));\n };\n\n /**\n * Manage all clickOustside listeners\n * @param action - top process on elements listeners\n */\n private manageClickOutsideListeners = (action: 'removeEventListener' | 'addEventListener'): void => {\n // clickOutside listeners need to bind windows\n // AND as shawdowDom content is not include on windows listeners `event.target` we need to include popover guard content DOM if it's a web-component\n // by doing this we can get and parse all needeed document DOM elements in clickOutside callback event.details.\n // This result in the givern junction :\n // Windows > document > [data-mg-popover-guard] + [data-mg-popover-guard] > shadowRoot = Windows > document > [data-mg-popover-guard] > shadowRoot\n const guardChildren = Array.from(document.querySelector(`[data-mg-popover-guard=\"${this.identifier}\"]`)?.shadowRoot?.children || new Set());\n [...guardChildren, ...this.windows].forEach((element: Window | HTMLElement) => {\n if (element !== null) {\n element[action]('click', this.clickOutside, false);\n }\n });\n };\n\n /**\n * Handle content hide event\n */\n private handleHideContent = (): void => {\n this.display = false;\n this.componentClose.emit();\n };\n\n /**\n * Render popover content element\n */\n private renderPopoverContent = (): void => {\n const mgPopoverContent = this.element.querySelector('mg-popover-content');\n if (mgPopoverContent === null) {\n this.mgPopoverContent = document.createElement('mg-popover-content');\n this.mgPopoverContent.setAttribute('slot', 'content');\n this.mgPopoverContent.setAttribute('id', this.identifier);\n this.mgPopoverContent.addEventListener('hide-content', this.handleHideContent);\n\n const arrow = document.createElement('div');\n arrow.setAttribute('slot', 'arrow');\n arrow.dataset.popperArrow = '';\n this.mgPopoverContent.appendChild(arrow);\n\n // insert elements in DOM\n ['[slot=\"title\"]', '[slot=\"content\"]:not(mg-popover-content)'].forEach(slotType => {\n Array.from(this.element.querySelectorAll(slotType)).forEach(slot => {\n this.mgPopoverContent.appendChild(slot);\n });\n });\n this.element.appendChild(this.mgPopoverContent);\n } else {\n mgPopoverContent.setAttribute('id', this.identifier);\n }\n };\n\n /*************\n * Lifecycle *\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 * Check if component props are well configured on init\n */\n componentWillLoad(): void {\n // Get windows to attach events\n this.windows = getWindows(window);\n // render mg-popover-content slot\n this.renderPopoverContent();\n this.validateCloseButton(this.closeButton);\n this.validateIdentifier(this.identifier);\n this.validateArrowHide(this.arrowHide);\n }\n\n /**\n * Check if component props are well configured on init\n */\n componentDidLoad(): void {\n // Get popover content\n this.mgPopover = this.element.querySelector(`#${this.identifier}`);\n\n //Get interactive element (first element without slot attribute)\n const interactiveElement: HTMLElement = this.element.querySelector(':not([slot])');\n // Add aria attributes\n interactiveElement.setAttribute('aria-controls', this.identifier);\n interactiveElement.setAttribute('aria-expanded', `${this.display}`);\n const fallbackPlacements = [];\n if (this.element.dataset.fallbackPlacement !== undefined) {\n fallbackPlacements.push(this.element.dataset.fallbackPlacement);\n }\n\n // Create popperjs popover\n this.popper = createPopper(interactiveElement, this.mgPopover, {\n placement: this.placement,\n strategy: 'fixed',\n modifiers: [\n {\n name: 'offset',\n options: {\n offset: [0, 0],\n },\n },\n {\n name: 'flip',\n options: {\n fallbackPlacements: [...fallbackPlacements, 'auto'],\n },\n },\n ],\n });\n\n // add resize observer\n [interactiveElement, this.element.querySelector('mg-popover-content')].forEach(element => {\n new ResizeObserver(() => {\n this.popper.update();\n }).observe(element);\n });\n\n // Add events to toggle display\n interactiveElement.addEventListener('click', () => {\n if (!this.disabled) this.display = !this.display;\n });\n\n // Add events to hide popover\n this.element.addEventListener('keydown', e => {\n if (!this.disabled && e.code === 'Escape') {\n this.display = false;\n this.componentClose.emit();\n interactiveElement.focus();\n }\n });\n\n this.handleDisplay(this.display);\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"]}
|
|
1
|
+
{"version":3,"file":"mg-popover.js","sourceRoot":"","sources":["../../../../src/components/molecules/mg-popover/mg-popover.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAgB,KAAK,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAkB,MAAM,kBAAkB,CAAC;AACvH,OAAO,EAAE,qBAAqB,EAA6B,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE5F;;;GAGG;AAMH,MAAM,OAAO,SAAS;IALtB;QAwBE;;;WAGG;QAC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AAC,OAAO,GAAG,KAAK,CAAC;gBACrB,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;gBAC3B,kBAAkB,CAAC,KAAK,EAAE,CAAC;YAC7B,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,+BAA+B;QAC/B,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,MAAM;QACJ,OAAO,CACL,EAAC,IAAI;YACH,8DAAa;YACb,6DAAM,IAAI,EAAC,SAAS,GAAQ,CACvB,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, Host, h, Prop, Watch, EventEmitter, Event } from '@stencil/core';\nimport { createID, getWindows, isValideID, toString } from '@mgdis/stencil-helpers';\nimport { computePosition, autoUpdate, flip, shift, limitShift, offset, arrow, type Placement } from '@floating-ui/dom';\nimport { isFloatingUIPlacement, type PopoverPlacementType, sides } from './mg-popover.conf';\n\n/**\n * @slot - Element that will display the popover\n * @slot content - popover content\n */\n@Component({\n tag: 'mg-popover',\n styleUrl: '../../../../node_modules/@mgdis/styles/dist/components/mg-popover.css',\n shadow: true,\n})\nexport class MgPopover {\n /************\n * Internal *\n ************/\n\n private mgPopover: HTMLElement;\n private mgPopoverContent: HTMLMgPopoverContentElement;\n private windows: Window[];\n private floatingUICleanup: ReturnType<typeof autoUpdate>;\n\n /**************\n * Decorators *\n **************/\n\n /**\n * Get component DOM element\n */\n @Element() element: HTMLMgPopoverElement;\n\n /**\n * Sets an `id` attribute.\n * Needed by the input for accessibility `aria-decribedby`.\n */\n @Prop() identifier: string = createID('mg-popover');\n @Watch('identifier')\n validateIdentifier(newValue: MgPopover['identifier']): void {\n if (!isValideID(newValue)) {\n throw new Error(`<mg-popover> prop \"identifier\" value is invalid. Passed value: ${toString(newValue)}.`);\n }\n // use renderPopoverContent to update popover-content id\n this.renderPopoverContent();\n }\n\n /**\n * Popover placement\n */\n @Prop({ mutable: true }) placement: PopoverPlacementType = 'bottom';\n @Watch('placement')\n watchPlacement(newValue) :void {\n if(!isFloatingUIPlacement(newValue)) this.placement = 'bottom';\n }\n\n /**\n * Hide popover arrow\n */\n @Prop() arrowHide = false;\n @Watch('arrowHide')\n validateArrowHide(newValue: MgPopover['arrowHide']): void {\n if (newValue) this.mgPopoverContent.dataset.arrowHide = '';\n else delete this.mgPopoverContent.dataset.arrowHide;\n }\n\n /**\n * Define if popover has a cross button\n */\n @Prop() closeButton = false;\n @Watch('closeButton')\n validateCloseButton(newValue: MgPopover['closeButton']): void {\n this.mgPopoverContent.closeButton = newValue;\n }\n\n /**\n * Display popover\n */\n @Prop({ mutable: true }) display = false;\n @Watch('display')\n handleDisplay(newValue: boolean): void {\n if (newValue) {\n this.show();\n } else {\n this.hide();\n }\n this.displayChange.emit(newValue);\n }\n\n /**\n * Disable popover\n */\n @Prop() disabled = false;\n\n /**\n * Emited event when display value change\n */\n @Event({ eventName: 'display-change' }) displayChange: EventEmitter<HTMLMgPopoverElement['display']>;\n\n /**\n * Emmited event when popover is closed\n */\n @Event({ eventName: 'component-close' }) componentClose: EventEmitter<void>;\n\n /**\n * Check if clicked outside of component\n * @param event - mouse event\n */\n private clickOutside = (event: MouseEvent & { target: HTMLElement }): void => {\n if (!this.disabled && event.target.closest('mg-popover') !== this.element && event.target.closest(`[data-mg-popover-guard=\"${this.identifier}\"]`) === null) {\n this.display = false;\n }\n };\n\n /**\n * Show popover\n */\n private show = (): void => {\n // Make the popover visible\n this.mgPopover.dataset.show = '';\n // hide when click outside\n // setTimeout is used to prevent event to trigger after creation\n setTimeout(() => {\n this.manageClickOutsideListeners('addEventListener');\n });\n };\n\n /**\n * Hide popover\n */\n private hide = (): void => {\n // Hide the popover\n this.mgPopover.removeAttribute('data-show');\n // Remove event listener\n this.manageClickOutsideListeners('removeEventListener');\n };\n\n /**\n * Manage all clickOustside listeners\n * @param action - top process on elements listeners\n */\n private manageClickOutsideListeners = (action: 'removeEventListener' | 'addEventListener'): void => {\n // clickOutside listeners need to bind windows\n // AND as shawdowDom content is not include on windows listeners `event.target` we need to include popover guard content DOM if it's a web-component\n // by doing this we can get and parse all needeed document DOM elements in clickOutside callback event.details.\n // This result in the givern junction :\n // Windows > document > [data-mg-popover-guard] + [data-mg-popover-guard] > shadowRoot = Windows > document > [data-mg-popover-guard] > shadowRoot\n const guardChildren = Array.from(document.querySelector(`[data-mg-popover-guard=\"${this.identifier}\"]`)?.shadowRoot?.children || new Set());\n [...guardChildren, ...this.windows].forEach((element: Window | HTMLElement) => {\n if (element !== null) {\n element[action]('click', this.clickOutside, false);\n }\n });\n };\n\n /**\n * Handle content hide event\n */\n private handleHideContent = (): void => {\n this.display = false;\n this.componentClose.emit();\n };\n\n /**\n * Render popover content element\n */\n private renderPopoverContent = (): void => {\n const mgPopoverContent = this.element.querySelector('mg-popover-content');\n if (mgPopoverContent === null) {\n this.mgPopoverContent = document.createElement('mg-popover-content');\n this.mgPopoverContent.setAttribute('slot', 'content');\n this.mgPopoverContent.setAttribute('id', this.identifier);\n this.mgPopoverContent.addEventListener('hide-content', this.handleHideContent);\n\n const arrow = document.createElement('div');\n arrow.setAttribute('slot', 'arrow');\n arrow.dataset.floatingArrow = '';\n this.mgPopoverContent.appendChild(arrow);\n\n // insert elements in DOM\n ['[slot=\"title\"]', '[slot=\"content\"]:not(mg-popover-content)'].forEach(slotType => {\n Array.from(this.element.querySelectorAll(slotType)).forEach(slot => {\n this.mgPopoverContent.appendChild(slot);\n });\n });\n this.element.appendChild(this.mgPopoverContent);\n } else {\n mgPopoverContent.setAttribute('id', this.identifier);\n }\n };\n\n /**\n * Set up Floating UI positioning and arrow behavior\n * @param interactiveElement - Element that triggers the popover\n */\n private setFloatingUI = (interactiveElement: HTMLElement): void => {\n const fallbackPlacements = (this.element.dataset.fallbackPlacement || '').split(',').map(t => t.trim());\n\n this.floatingUICleanup = autoUpdate(interactiveElement, this.mgPopover, () => {\n computePosition(interactiveElement, this.mgPopover, {\n placement: this.placement as Placement,\n strategy: 'fixed',\n middleware: [\n offset(0),\n flip({\n fallbackPlacements: Array.from(new Set([...fallbackPlacements, ...sides]).values()).filter(isFloatingUIPlacement), // simulate \"auto\" placement with default fallback values\n }),\n shift({\n limiter: limitShift(),\n }),\n arrow({\n element: this.mgPopover.querySelector('[data-floating-arrow]'),\n }),\n ],\n }).then(({ x, y, placement, middlewareData }) => {\n Object.assign(this.mgPopover.style, {\n position: 'fixed',\n top: '0',\n left: '0',\n transform: `translate(${Math.round(x)}px, ${Math.round(y)}px)`,\n });\n\n // Update arrow style\n const staticSide = {\n top: 'bottom',\n right: 'left',\n bottom: 'top',\n left: 'right',\n }[placement.split('-')[0]];\n\n const arrowElement: HTMLElement = this.mgPopover.querySelector('[data-floating-arrow]');\n const { x: arrowX, y: arrowY } = middlewareData.arrow;\n // https://floating-ui.com/docs/arrow \n // Unlike the floating element, which has both coordinates defined at all times, the arrow only has one defined.\n // Due to this, either x or y will be undefined, depending on the side of placement.\n // The above code uses `isNaN` to check for null and undefined simultaneously.\n // Don’t remove `isNaN`, because either value can be falsy (0), causing a bug!\n const numberToPx = (number: number): string => !isNaN(number) ? `${number}px` : '';\n\n if (arrowElement !== null)\n Object.assign(arrowElement.style, {\n position: 'absolute',\n left: numberToPx(arrowX),\n top: numberToPx(arrowY),\n [staticSide]: '1px',\n });\n\n this.mgPopover.setAttribute('data-placement', placement);\n });\n });\n };\n\n /*************\n * Lifecycle *\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.floatingUICleanup();\n }\n\n /**\n * Check if component props are well configured on init\n */\n componentWillLoad(): void {\n // Get windows to attach events\n this.windows = getWindows(window);\n // render mg-popover-content slot\n this.renderPopoverContent();\n this.validateCloseButton(this.closeButton);\n this.validateIdentifier(this.identifier);\n this.validateArrowHide(this.arrowHide);\n this.watchPlacement(this.placement)\n }\n\n /**\n * Check if component props are well configured on init\n */\n componentDidLoad(): void {\n // Get popover content\n this.mgPopover = this.element.querySelector(`#${this.identifier}`);\n\n // Get interactive element (first element without slot attribute)\n const interactiveElement: HTMLElement = this.element.querySelector(':not([slot])');\n\n // Add aria attributes\n interactiveElement.setAttribute('aria-controls', this.identifier);\n interactiveElement.setAttribute('aria-expanded', `${this.display}`);\n\n // Initial styles configuration\n Object.assign(this.mgPopover.style, {\n position: 'fixed',\n });\n\n // Create Floating UI instance\n this.setFloatingUI(interactiveElement);\n\n // Add resize observer\n [interactiveElement, this.mgPopoverContent].forEach(element => {\n new ResizeObserver(() => {\n this.floatingUICleanup();\n this.setFloatingUI(interactiveElement);\n }).observe(element);\n });\n\n // Add events to toggle display\n interactiveElement.addEventListener('click', () => {\n if (!this.disabled) this.display = !this.display;\n });\n\n this.element.addEventListener('click', (event: MouseEvent & { target: HTMLElement }): void => {\n const target = event.target.closest('[popovertargetaction]');\n if (this.display === true && target !== null && target.getAttribute('popovertargetaction') === 'hide') {\n this.display = false;\n }\n });\n\n // Add events to hide popover\n this.element.addEventListener('keydown', e => {\n if (!this.disabled && e.code === 'Escape') {\n this.display = false;\n this.componentClose.emit();\n interactiveElement.focus();\n }\n });\n\n this.handleDisplay(this.display);\n }\n\n /**\n * Cleanup when component is disconnected\n */\n disconnectedCallback(): void {\n // Cleanup Floating UI instance\n this.floatingUICleanup();\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"]}
|
|
@@ -3,10 +3,25 @@ import { isValidNumber, isValidString, toString } from "@mgdis/stencil-helpers";
|
|
|
3
3
|
import { roles } from "./mg-progress.conf";
|
|
4
4
|
export class MgProgress {
|
|
5
5
|
constructor() {
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Define progress role
|
|
8
|
+
* - `progressbar` to indicate a progress, such as loading or percent completion of a task
|
|
9
|
+
* - `meter` to indicate a graphical display of a numeric value that varies within a defined range
|
|
10
|
+
*/
|
|
7
11
|
this.ariaRole = 'progressbar';
|
|
12
|
+
/**
|
|
13
|
+
* Define current value
|
|
14
|
+
* By default, it will be displayed as a percentage value.
|
|
15
|
+
* If you don’t specify the min and max props, the value should be a number within the range of 0 to 100.
|
|
16
|
+
*/
|
|
8
17
|
this.value = 0;
|
|
18
|
+
/**
|
|
19
|
+
* Define the minimum value in the range
|
|
20
|
+
*/
|
|
9
21
|
this.min = 0;
|
|
22
|
+
/**
|
|
23
|
+
* Define the maximum value in the range
|
|
24
|
+
*/
|
|
10
25
|
this.max = 100;
|
|
11
26
|
}
|
|
12
27
|
watchLabel(newValue) {
|
|
@@ -82,6 +97,8 @@ export class MgProgress {
|
|
|
82
97
|
"tags": [],
|
|
83
98
|
"text": "Define label"
|
|
84
99
|
},
|
|
100
|
+
"getter": false,
|
|
101
|
+
"setter": false,
|
|
85
102
|
"attribute": "label",
|
|
86
103
|
"reflect": false
|
|
87
104
|
},
|
|
@@ -105,6 +122,8 @@ export class MgProgress {
|
|
|
105
122
|
"tags": [],
|
|
106
123
|
"text": "Define progress role\n- `progressbar` to indicate a progress, such as loading or percent completion of a task\n- `meter` to indicate a graphical display of a numeric value that varies within a defined range"
|
|
107
124
|
},
|
|
125
|
+
"getter": false,
|
|
126
|
+
"setter": false,
|
|
108
127
|
"attribute": "aria-role",
|
|
109
128
|
"reflect": false,
|
|
110
129
|
"defaultValue": "'progressbar'"
|
|
@@ -123,6 +142,8 @@ export class MgProgress {
|
|
|
123
142
|
"tags": [],
|
|
124
143
|
"text": "Define current value\nBy default, it will be displayed as a percentage value.\nIf you don\u2019t specify the min and max props, the value should be a number within the range of 0 to 100."
|
|
125
144
|
},
|
|
145
|
+
"getter": false,
|
|
146
|
+
"setter": false,
|
|
126
147
|
"attribute": "value",
|
|
127
148
|
"reflect": false,
|
|
128
149
|
"defaultValue": "0"
|
|
@@ -141,6 +162,8 @@ export class MgProgress {
|
|
|
141
162
|
"tags": [],
|
|
142
163
|
"text": "Define the minimum value in the range"
|
|
143
164
|
},
|
|
165
|
+
"getter": false,
|
|
166
|
+
"setter": false,
|
|
144
167
|
"attribute": "min",
|
|
145
168
|
"reflect": false,
|
|
146
169
|
"defaultValue": "0"
|
|
@@ -159,6 +182,8 @@ export class MgProgress {
|
|
|
159
182
|
"tags": [],
|
|
160
183
|
"text": "Define the maximum value in the range"
|
|
161
184
|
},
|
|
185
|
+
"getter": false,
|
|
186
|
+
"setter": false,
|
|
162
187
|
"attribute": "max",
|
|
163
188
|
"reflect": false,
|
|
164
189
|
"defaultValue": "100"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mg-progress.js","sourceRoot":"","sources":["../../../../src/components/molecules/mg-progress/mg-progress.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAgB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAOzD,MAAM,OAAO,UAAU
|
|
1
|
+
{"version":3,"file":"mg-progress.js","sourceRoot":"","sources":["../../../../src/components/molecules/mg-progress/mg-progress.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,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GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG;yBACjF,GACI,CACH,CACF,CACD,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, h, Host, Prop, Watch } from '@stencil/core';\nimport { isValidNumber, isValidString, toString } from '@mgdis/stencil-helpers';\nimport { AriaRoleType, roles } from './mg-progress.conf';\n\n@Component({\n tag: 'mg-progress',\n styleUrl: '../../../../node_modules/@mgdis/styles/dist/components/mg-progress.css',\n shadow: true,\n})\nexport class MgProgress {\n /**************\n * Decorators *\n **************/\n\n /**\n * Define label\n */\n @Prop() label!: string;\n @Watch('label')\n watchLabel(newValue: MgProgress['label']): void {\n if (!isValidString(newValue)) {\n throw new Error(`<mg-progress> prop \"label\" must be a valid string. Passed value: ${toString(newValue)}.`);\n }\n }\n\n /**\n * Define progress role\n * - `progressbar` to indicate a progress, such as loading or percent completion of a task\n * - `meter` to indicate a graphical display of a numeric value that varies within a defined range\n */\n @Prop() ariaRole?: AriaRoleType = 'progressbar';\n @Watch('ariaRole')\n watchAriaRole(newValue: MgProgress['ariaRole']): void {\n if (newValue && !roles.includes(newValue)) {\n throw new Error(`<mg-progress> prop \"ariaRole\" must be one of: ${roles.join(', ')}. Passed value: ${toString(newValue)}.`);\n }\n }\n\n /**\n * Define current value\n * By default, it will be displayed as a percentage value.\n * If you don’t specify the min and max props, the value should be a number within the range of 0 to 100.\n */\n @Prop() value?: number = 0;\n @Watch('value')\n watchValue(newValue: MgProgress['value']): void {\n if (newValue !== undefined && (!isValidNumber(newValue) || !(newValue >= this.min && newValue <= this.max)))\n throw new Error(`<mg-progress> prop “value” must be a number within the range ${this.min} to ${this.max}. Passed value: ${toString(newValue)}.`);\n }\n\n /**\n * Define the minimum value in the range\n */\n @Prop() min?: number = 0;\n @Watch('min')\n watchMin(newValue: MgProgress['min']): void {\n if (newValue !== 0 && newValue !== undefined && (!isValidNumber(newValue) || newValue >= this.max))\n throw new Error(`<mg-progress> prop “min” must be a number lower than: ${this.max}. Passed value: ${toString(newValue)}.`);\n }\n\n /**\n * Define the maximum value in the range\n */\n @Prop() max?: number = 100;\n @Watch('max')\n watchMax(newValue: MgProgress['max']): void {\n if (newValue !== 100 && newValue !== undefined && (!isValidNumber(newValue) || newValue <= this.min))\n throw new Error(`<mg-progress> prop “max” must be a number greater than: ${this.min}. Passed value: ${toString(newValue)}.`);\n }\n\n /*************\n * Lifecycle *\n *************/\n\n /**\n * Check if component props are well configured on init\n */\n componentWillLoad(): void {\n // validate props\n this.watchLabel(this.label);\n this.watchAriaRole(this.ariaRole);\n this.watchMin(this.min);\n this.watchMax(this.max);\n this.watchValue(this.value);\n }\n\n /**\n * Render\n * @returns HTML Element\n */\n render(): HTMLElement {\n return (\n <Host role={this.ariaRole} aria-label={this.label} aria-valuenow={this.value} aria-valuemin={this.min} aria-valuemax={this.max}>\n <div class=\"mg-c-progress\">\n <div class={{ 'mg-c-progress__bar': true, 'mg-c-progress__bar--active': this.value > this.min }}>\n <div\n class=\"mg-c-progress__fill\"\n style={{\n width: `${Math.round(((this.value - this.min) / (this.max - this.min)) * 100)}%`,\n }}\n ></div>\n </div>\n </div>\n </Host>\n );\n }\n}\n"]}
|
|
@@ -14,7 +14,6 @@ export class MgSkipLinks {
|
|
|
14
14
|
event.currentTarget.blur();
|
|
15
15
|
this.goToAnchor.emit(event.currentTarget.getAttribute('href'));
|
|
16
16
|
};
|
|
17
|
-
this.links = undefined;
|
|
18
17
|
}
|
|
19
18
|
validateLinks(links) {
|
|
20
19
|
if (links === undefined || links.length === 0 || links.some(link => !isValidString(link.href) || !link.href.startsWith('#') || !isValidString(link.label))) {
|
|
@@ -71,7 +70,9 @@ export class MgSkipLinks {
|
|
|
71
70
|
"docs": {
|
|
72
71
|
"tags": [],
|
|
73
72
|
"text": "Skip links"
|
|
74
|
-
}
|
|
73
|
+
},
|
|
74
|
+
"getter": false,
|
|
75
|
+
"setter": false
|
|
75
76
|
}
|
|
76
77
|
};
|
|
77
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mg-skip-links.js","sourceRoot":"","sources":["../../../../src/components/molecules/mg-skip-links/mg-skip-links.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAgB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAExF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAOvD,MAAM,OAAO,WAAW;;
|
|
1
|
+
{"version":3,"file":"mg-skip-links.js","sourceRoot":"","sources":["../../../../src/components/molecules/mg-skip-links/mg-skip-links.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAgB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAExF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAOvD,MAAM,OAAO,WAAW;IALxB;QAqCE;;oBAEY;QAEZ;;;WAGG;QACK,oBAAe,GAAG,CAAC,KAAkD,EAAQ,EAAE;YACrF,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;YAC3B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;QACjE,CAAC,C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kipLink } from './mg-skip-links.conf';\nimport { initLocales } from '../../../locales';\nimport { isValidString } from '@mgdis/stencil-helpers';\n\n@Component({\n tag: 'mg-skip-links',\n styleUrl: '../../../../node_modules/@mgdis/styles/dist/components/mg-skip-links.css',\n shadow: true,\n})\nexport class MgSkipLinks {\n /************\n * Internal *\n ************/\n\n private messages;\n\n /**************\n * Decorators *\n **************/\n\n /**\n * Get component DOM element\n */\n @Element() element: HTMLMgSkipLinksElement;\n\n /**\n * Skip links\n */\n @Prop() links: SkipLink[];\n @Watch('links')\n validateLinks(links: SkipLink[]): void {\n if (links === undefined || links.length === 0 || links.some(link => !isValidString(link.href) || !link.href.startsWith('#') || !isValidString(link.label))) {\n 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.`);\n }\n }\n\n /**\n * Emited event when link is clicked\n */\n @Event({ eventName: 'go-to-anchor' }) goToAnchor: EventEmitter<string>;\n\n /***********\n * Methods *\n **********/\n\n /**\n * Handle link click and emit go-to-anchor event\n * @param event - mouse event\n */\n private handleLinkCLick = (event: MouseEvent & { currentTarget: HTMLElement }): void => {\n event.currentTarget.blur();\n this.goToAnchor.emit(event.currentTarget.getAttribute('href'));\n };\n\n /*************\n * Lifecycle *\n *************/\n\n /**\n * Check if props are well configured on init\n */\n componentWillLoad(): void {\n this.validateLinks(this.links);\n this.messages = initLocales(this.element).messages;\n }\n\n /**\n * Render\n * @returns HTML Element\n */\n render(): HTMLElement {\n return (\n <nav class=\"mg-c-skip-links\" role=\"navigation\" aria-label={this.messages.skipLinks.navLabel}>\n <ul class=\"mg-c-skip-links__list\" role=\"list\">\n {this.links.map(link => (\n <li key={link.href}>\n <a class=\"mg-c-skip-links__link\" href={link.href} onClick={this.handleLinkCLick}>\n {link.label}\n </a>\n </li>\n ))}\n </ul>\n </nav>\n );\n }\n}\n"]}
|