@mgdis/mg-components 4.2.1 → 5.1.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.
Files changed (105) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/{mg-badge_23.cjs.entry.js → mg-badge_27.cjs.entry.js} +2590 -121
  3. package/dist/cjs/mg-components.cjs.js +1 -1
  4. package/dist/collection/collection-manifest.json +2 -0
  5. package/dist/collection/components/atoms/mg-badge/mg-badge.js +1 -3
  6. package/dist/collection/components/atoms/mg-button/doc/mg-button.stories.js +1 -2
  7. package/dist/collection/components/atoms/mg-button/mg-button.css +113 -67
  8. package/dist/collection/components/atoms/mg-button/mg-button.js +89 -64
  9. package/dist/collection/components/atoms/mg-card/doc/mg-card.stories.js +18 -0
  10. package/dist/collection/components/atoms/mg-card/mg-card.css +7 -0
  11. package/dist/collection/components/atoms/mg-card/mg-card.js +26 -0
  12. package/dist/collection/components/atoms/mg-divider/doc/mg-divider.stories.js +18 -0
  13. package/dist/collection/components/atoms/mg-divider/mg-divider.css +9 -0
  14. package/dist/collection/components/atoms/mg-divider/mg-divider.js +57 -0
  15. package/dist/collection/components/atoms/mg-icon/mg-icon.conf.js +3 -0
  16. package/dist/collection/components/atoms/mg-input-title/mg-input-title.js +1 -3
  17. package/dist/collection/components/atoms/mg-tooltip/doc/mg-tooltip.stories.js +0 -5
  18. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.conf.js +0 -20
  19. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.css +1 -1
  20. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +6 -7
  21. package/dist/collection/components/molecules/inputs/MgInput.js +1 -3
  22. package/dist/collection/components/molecules/mg-details/doc/mg-details.stories.js +1 -0
  23. package/dist/collection/components/molecules/mg-details/mg-details.css +29 -0
  24. package/dist/collection/components/molecules/mg-details/mg-details.js +26 -4
  25. package/dist/collection/components/molecules/mg-form/mg-form.js +2 -3
  26. package/dist/collection/components/molecules/mg-illustrated-message/doc/mg-illustrated-message.stories.js +2 -1
  27. package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.css +15 -7
  28. package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js +27 -2
  29. package/dist/collection/components/molecules/mg-modal/doc/mg-modal.stories.js +1 -1
  30. package/dist/collection/components/molecules/mg-modal/mg-modal.css +2 -1
  31. package/dist/collection/components/molecules/mg-modal/mg-modal.js +53 -7
  32. package/dist/collection/components/molecules/mg-pagination/mg-pagination.js +4 -3
  33. package/dist/collection/components/molecules/mg-panel/doc/mg-panel.stories.js +1 -1
  34. package/dist/collection/components/molecules/mg-panel/mg-panel.css +12 -20
  35. package/dist/collection/components/molecules/mg-panel/mg-panel.js +2 -4
  36. package/dist/collection/components/molecules/mg-popover/doc/mg-popover.stories.js +0 -5
  37. package/dist/collection/components/molecules/mg-popover/mg-popover.css +3 -3
  38. package/dist/collection/components/molecules/mg-popover/mg-popover.js +10 -10
  39. package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +1 -3
  40. package/dist/collection/utils/components.utils.js +10 -6
  41. package/dist/collection/variables.css +22 -1
  42. package/dist/components/MgInput.js +1 -3
  43. package/dist/components/components.utils.js +11 -7
  44. package/dist/components/index.d.ts +2 -0
  45. package/dist/components/index.js +2 -0
  46. package/dist/components/mg-badge2.js +1 -3
  47. package/dist/components/mg-button2.js +63 -13
  48. package/dist/components/mg-card.d.ts +11 -0
  49. package/dist/components/mg-card.js +42 -0
  50. package/dist/components/mg-details.js +8 -3
  51. package/dist/components/mg-divider.d.ts +11 -0
  52. package/dist/components/mg-divider.js +51 -0
  53. package/dist/components/mg-form.js +2 -3
  54. package/dist/components/mg-icon2.js +3 -0
  55. package/dist/components/mg-illustrated-message.js +12 -4
  56. package/dist/components/mg-input-title2.js +1 -3
  57. package/dist/components/mg-modal.js +54 -8
  58. package/dist/components/mg-pagination.js +4 -3
  59. package/dist/components/mg-panel.js +3 -5
  60. package/dist/components/mg-popover.js +11 -10
  61. package/dist/components/mg-tabs.js +1 -3
  62. package/dist/components/mg-tooltip2.js +7 -10
  63. package/dist/esm/loader.js +1 -1
  64. package/dist/esm/{mg-badge_23.entry.js → mg-badge_27.entry.js} +2538 -73
  65. package/dist/esm/mg-components.js +1 -1
  66. package/dist/mg-components/mg-components.css +1 -1
  67. package/dist/mg-components/mg-components.esm.js +1 -1
  68. package/dist/mg-components/p-e131701a.entry.js +1 -0
  69. package/dist/mg-components/variables.css +22 -1
  70. package/dist/types/components/atoms/mg-button/doc/mg-button.stories.d.ts +2 -2
  71. package/dist/types/components/atoms/mg-button/mg-button.conf.d.ts +5 -1
  72. package/dist/types/components/atoms/mg-button/mg-button.d.ts +25 -17
  73. package/dist/types/components/atoms/mg-card/doc/mg-card.stories.d.ts +6 -0
  74. package/dist/types/components/atoms/mg-card/mg-card.d.ts +11 -0
  75. package/dist/types/components/atoms/mg-divider/doc/mg-divider.stories.d.ts +6 -0
  76. package/dist/types/components/atoms/mg-divider/mg-divider.d.ts +15 -0
  77. package/dist/types/components/atoms/mg-tooltip/doc/mg-tooltip.stories.d.ts +0 -6
  78. package/dist/types/components/atoms/mg-tooltip/mg-tooltip.conf.d.ts +0 -8
  79. package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +1 -1
  80. package/dist/types/components/molecules/mg-details/mg-details.d.ts +4 -0
  81. package/dist/types/components/molecules/mg-illustrated-message/mg-illustrated-message.d.ts +4 -0
  82. package/dist/types/components/molecules/mg-modal/mg-modal.d.ts +8 -0
  83. package/dist/types/components/molecules/mg-pagination/mg-pagination.d.ts +1 -0
  84. package/dist/types/components/molecules/mg-popover/doc/mg-popover.stories.d.ts +0 -6
  85. package/dist/types/components/molecules/mg-popover/mg-popover.d.ts +1 -1
  86. package/dist/types/components.d.ts +64 -31
  87. package/dist/types/utils/components.utils.d.ts +7 -3
  88. package/package.json +4 -3
  89. package/dist/cjs/index-179621c8.js +0 -244
  90. package/dist/cjs/mg-modal.cjs.entry.js +0 -130
  91. package/dist/cjs/mg-popover.cjs.entry.js +0 -171
  92. package/dist/cjs/popper-11d5f714.js +0 -1801
  93. package/dist/collection/components/molecules/mg-popover/mg-popover.conf.js +0 -20
  94. package/dist/collection/variables.scss +0 -212
  95. package/dist/esm/index-7efedd97.js +0 -238
  96. package/dist/esm/mg-modal.entry.js +0 -126
  97. package/dist/esm/mg-popover.entry.js +0 -167
  98. package/dist/esm/popper-f860750c.js +0 -1799
  99. package/dist/mg-components/p-25452f60.entry.js +0 -1
  100. package/dist/mg-components/p-5f89600c.js +0 -1
  101. package/dist/mg-components/p-a20fc541.entry.js +0 -1
  102. package/dist/mg-components/p-e08bc19a.entry.js +0 -1
  103. package/dist/mg-components/p-ec26fc38.js +0 -1
  104. package/dist/mg-components/variables.scss +0 -212
  105. package/dist/types/components/molecules/mg-popover/mg-popover.conf.d.ts +0 -8
@@ -1,244 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Create random ID
5
- *
6
- * @param {string} prefix add prefix to created ID
7
- * @param {number} length ID length
8
- * @returns {string} ID
9
- */
10
- function createID(prefix = '', length = 10) {
11
- let ID = '';
12
- const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
13
- const charsLength = chars.length;
14
- for (let i = 0; i < length; i++) {
15
- ID += chars.charAt(Math.floor(Math.random() * charsLength));
16
- }
17
- return (prefix !== '' ? `${prefix}-` : '') + ID;
18
- }
19
- /**
20
- * Class to manage component classlist
21
- * Set() are not working when imported in project
22
- */
23
- class ClassList {
24
- constructor(classlist = []) {
25
- /**
26
- * Add class
27
- *
28
- * @param {string} className class name to add
29
- * @returns {void}
30
- */
31
- this.add = (className) => {
32
- if (!this.has(className)) {
33
- this.classes.push(className);
34
- }
35
- };
36
- /**
37
- * Delete class
38
- *
39
- * @param {string} className class name to delete
40
- * @returns {void}
41
- */
42
- this.delete = (className) => {
43
- const index = this.classes.indexOf(className);
44
- if (index > -1) {
45
- this.classes.splice(index, 1);
46
- }
47
- };
48
- /**
49
- * Check if class exist in list
50
- *
51
- * @param {string} className class name to check
52
- * @returns {boolean} class name is in the list
53
- */
54
- this.has = (className) => {
55
- return this.classes.includes(className);
56
- };
57
- /**
58
- * Join classes seperated by spaces
59
- *
60
- * @returns {string} joined values
61
- */
62
- this.join = () => {
63
- return this.classes.join(' ');
64
- };
65
- this.classes = classlist;
66
- }
67
- }
68
- /**
69
- * Check if all items are string
70
- *
71
- * @param {string[]} items items to check
72
- * @returns {boolean} all items are string
73
- */
74
- function allItemsAreString(items) {
75
- return items && items.every(item => typeof item === 'string');
76
- }
77
- /**
78
- * Check if element is a heading
79
- *
80
- * @param {Element} element slotted element
81
- * @param {string[]} tagNames allowed tag names list
82
- * @returns {boolean} element is a heading
83
- */
84
- function isTagName(element, tagNames) {
85
- return tagNames.includes(element === null || element === void 0 ? void 0 : element.tagName.toLowerCase());
86
- }
87
-
88
- const errors$1 = {
89
- required: "This field is required.",
90
- date: {
91
- badInput: "The date format must be <span aria-hidden=\"true\">mm/dd/yyyy</span><span class=\"sr-only\">m m / d d / y y y y</span> and the date must be greater than {min}",
92
- min: "The date cannot be earlier than {min}",
93
- max: "The date cannot be later than {max}",
94
- minMax: "The date must be between {min} and {max}"
95
- },
96
- numeric: {
97
- min: "The value cannot be less than {min}",
98
- max: "The value cannot be greater than {max}",
99
- minMax: "The value must be between {min} et {max}"
100
- }
101
- };
102
- const nbCharLeft$1 = "{counter} characters left.";
103
- const input$1 = {
104
- select: {
105
- placeholder: "Select a value"
106
- }
107
- };
108
- const form$1 = {
109
- required: "Fields with a <strong class=\"is-asterisk\">*</strong> are required",
110
- allRequired: "All fields are required"
111
- };
112
- const message$1 = {
113
- closeButton: "Close message"
114
- };
115
- const modal$1 = {
116
- closeButton: "Close modal"
117
- };
118
- const pagination$1 = {
119
- label: "Pagination",
120
- page: "page",
121
- pages: "pages",
122
- nextPage: "Next page",
123
- previousPage: "Previous page",
124
- selectPage: "Select the page to display."
125
- };
126
- const panel$1 = {
127
- editLabel: "Edit section title."
128
- };
129
- const general$1 = {
130
- confirm: "Confirm",
131
- cancel: "Cancel",
132
- close: "Close",
133
- next: "next",
134
- previous: "previous"
135
- };
136
- const en = {
137
- errors: errors$1,
138
- nbCharLeft: nbCharLeft$1,
139
- input: input$1,
140
- form: form$1,
141
- message: message$1,
142
- modal: modal$1,
143
- pagination: pagination$1,
144
- panel: panel$1,
145
- general: general$1
146
- };
147
-
148
- const errors = {
149
- required: "Ce champ est obligatoire.",
150
- date: {
151
- badInput: "Le format de la date doit être du type <span aria-hidden=\"true\">jj/mm/aaaa</span><span class=\"sr-only\">j j / m m / a a a a</span> et la date supérieure au {min}",
152
- min: "La date ne peut pas être antérieure au {min}",
153
- max: "La date ne peut pas être postérieure au {max}",
154
- minMax: "La date doit être comprise entre le {min} et le {max}"
155
- },
156
- numeric: {
157
- min: "La valeur ne peut pas être inférieure à {min}",
158
- max: "La valeur ne peut pas être supérieure à {max}",
159
- minMax: "La valeur doit être comprise entre {min} et {max}"
160
- }
161
- };
162
- const nbCharLeft = "{counter} caractères disponibles.";
163
- const input = {
164
- select: {
165
- placeholder: "Sélectionnez une valeur"
166
- }
167
- };
168
- const form = {
169
- required: "Les champs marqués d'un <strong class=\"is-asterisk\">*</strong> sont obligatoires",
170
- allRequired: "Tous les champs sont obligatoires"
171
- };
172
- const message = {
173
- closeButton: "Fermer le message"
174
- };
175
- const modal = {
176
- closeButton: "Fermer la modale"
177
- };
178
- const pagination = {
179
- label: "Pagination",
180
- page: "page",
181
- pages: "pages",
182
- nextPage: "Page suivante",
183
- previousPage: "Page précédente",
184
- selectPage: "Sélectionner la page à afficher."
185
- };
186
- const panel = {
187
- editLabel: "Modifier le titre de la section."
188
- };
189
- const general = {
190
- confirm: "Valider",
191
- cancel: "Annuler",
192
- close: "Fermer",
193
- next: "suivant",
194
- previous: "précédent"
195
- };
196
- const fr = {
197
- errors: errors,
198
- nbCharLeft: nbCharLeft,
199
- input: input,
200
- form: form,
201
- message: message,
202
- modal: modal,
203
- pagination: pagination,
204
- panel: panel,
205
- general: general
206
- };
207
-
208
- const defaultLocale = 'en';
209
- const messages = { en, fr };
210
- /**
211
- * Get locale
212
- *
213
- * @param {HTMLElement} element element that needs to know the locale to use
214
- * @returns {string} locale
215
- */
216
- const getLocale = (element) => {
217
- var _a;
218
- return ((_a = element.closest('[lang]')) === null || _a === void 0 ? void 0 : _a.lang) || navigator.language || defaultLocale;
219
- };
220
- /**
221
- * Get Intl object
222
- * We load the defined locale but for now we only support the first subtag for messages
223
- *
224
- * @param {HTMLElement} element element we need to get the language
225
- * @returns {{ locale: string; messages: unknown }} messages object
226
- */
227
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
228
- const initLocales = (element) => {
229
- // Get local
230
- const locale = getLocale(element);
231
- // Only keep first subtag
232
- const localeSubtag = locale.split('-').shift();
233
- // Return
234
- return {
235
- locale,
236
- messages: messages[localeSubtag] || messages[defaultLocale],
237
- };
238
- };
239
-
240
- exports.ClassList = ClassList;
241
- exports.allItemsAreString = allItemsAreString;
242
- exports.createID = createID;
243
- exports.initLocales = initLocales;
244
- exports.isTagName = isTagName;
@@ -1,130 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const index = require('./index-94497267.js');
6
- const index$1 = require('./index-179621c8.js');
7
-
8
- const mgModalCss = ".mg-modal{display:flex;justify-content:center;align-items:center;position:fixed;top:0;right:0;bottom:0;left:0;z-index:1000;padding:2rem 0;background-color:hsla(var(--color-light), 85%)}.mg-modal__dialog{display:flex;flex-direction:column;align-self:center;row-gap:3rem;padding:1.5rem 2.5rem;width:60rem;height:fit-content;max-width:100%;max-height:100%;box-sizing:border-box;background-color:hsl(var(--color-light));box-shadow:var(--box-shadow);border-radius:var(--mg-modal-border-radius)}.mg-modal__header{margin-bottom:0.5rem}.mg-modal__title{margin:0;font-family:var(--font-family-heading);font-size:var(--mg-modal-title-font-size);font-weight:600}.mg-modal__close-button{float:right;height:var(--mg-modal-title-font-size);margin-top:calc((var(--default-size) - var(--mg-modal-title-font-size) * var(--line-height)) / 2 * -1);margin-right:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2 * -1)}.mg-modal__content{overflow-y:auto}.mg-modal__content::slotted(*){font-size:var(--mg-modal-content-font-size)}.mg-modal.mg-modal--hide{display:none}";
9
-
10
- const MgModal = class {
11
- constructor(hostRef) {
12
- index.registerInstance(this, hostRef);
13
- this.componentShow = index.createEvent(this, "component-show", 7);
14
- this.componentHide = index.createEvent(this, "component-hide", 7);
15
- /************
16
- * Internal *
17
- ************/
18
- // Classes
19
- this.classHide = 'mg-modal--hide';
20
- // IDs
21
- this.closeButtonId = '';
22
- this.titleId = '';
23
- /**
24
- * Identifier is used for the element ID (id is a reserved prop in Stencil.js)
25
- * If not set, it will be created.
26
- */
27
- this.identifier = index$1.createID('mg-modal');
28
- /**
29
- * Define if modal has a cross button
30
- */
31
- this.closeButton = false;
32
- /**
33
- * Define if modal is hidden
34
- */
35
- this.hide = false;
36
- /**
37
- * Define if component is using actions slot
38
- */
39
- this.hasActions = false;
40
- /**
41
- * Define if component is using content slot
42
- */
43
- this.hasContent = false;
44
- /**
45
- * Component classes
46
- */
47
- this.classList = new index$1.ClassList(['mg-modal']);
48
- /*************
49
- * Handlers *
50
- *************/
51
- /**
52
- * Handle close button
53
- *
54
- * @returns {void}
55
- */
56
- this.handleClose = () => {
57
- this.hide = true;
58
- };
59
- }
60
- validateModalTitle(newValue) {
61
- if (typeof newValue !== 'string' || newValue.trim() === '') {
62
- // TODO: throw new Error on next major (5.0.0)
63
- // throw new Error('<mg-modal> prop "modalTitle" is required.');
64
- console.error('<mg-modal> prop "modalTitle" is required.');
65
- }
66
- }
67
- validateHide(newValue) {
68
- if (newValue) {
69
- this.componentHide.emit();
70
- this.classList.add(this.classHide);
71
- document.body.style.overflow = this.bodyOverflow;
72
- }
73
- else {
74
- this.componentShow.emit();
75
- this.classList.delete(this.classHide);
76
- document.body.style.overflow = 'hidden';
77
- }
78
- }
79
- /**
80
- * Handle 'escape' key down
81
- *
82
- * @param {KeyboardEvent} event keydown event
83
- * @returns {void}
84
- */
85
- handleKeyDown(event) {
86
- // we can use 'Escape button" when this not a blocking modal, induced by closeButton value.
87
- if (this.closeButton && event.key === 'Escape') {
88
- this.hide = true;
89
- }
90
- }
91
- /*************
92
- * Lifecycle *
93
- *************/
94
- /**
95
- * Check if component props are well configured on init
96
- *
97
- * @returns {void}
98
- */
99
- componentWillLoad() {
100
- // Store body overflow
101
- this.bodyOverflow = document.body.style.overflow;
102
- // Get locales
103
- this.messages = index$1.initLocales(this.element).messages;
104
- // Validate
105
- this.hasActions = this.element.querySelector('[slot="actions"]') !== null;
106
- this.hasContent = this.element.querySelector('[slot="content"]') !== null;
107
- if (this.closeButton) {
108
- this.closeButtonId = `${this.identifier}-close-button`;
109
- }
110
- this.titleId = `${this.identifier}-title`;
111
- this.validateModalTitle(this.modalTitle);
112
- this.validateHide(this.hide);
113
- }
114
- /**
115
- * Render
116
- *
117
- * @returns {HTMLElement} HTML Element
118
- */
119
- render() {
120
- return (index.h("section", { role: "dialog", id: this.identifier, class: this.classList.join(), tabindex: "-1", "aria-labelledby": this.titleId, "aria-modal": "true", "aria-hidden": this.hide }, index.h("article", { class: "mg-modal__dialog" }, index.h("header", { class: "mg-modal__header" }, this.closeButton && (index.h("span", { class: "mg-modal__close-button" }, index.h("mg-button", { identifier: this.closeButtonId, "is-icon": true, variant: "flat", label: this.messages.modal.closeButton, onClick: this.handleClose }, index.h("mg-icon", { icon: "cross" })))), index.h("h1", { class: "mg-modal__title", id: this.titleId }, this.modalTitle)), this.hasContent && (index.h("article", { class: "mg-modal__content" }, index.h("slot", { name: "content" }))), this.hasActions && (index.h("footer", { class: "mg-modal__footer" }, index.h("slot", { name: "actions" }))))));
121
- }
122
- get element() { return index.getElement(this); }
123
- static get watchers() { return {
124
- "modalTitle": ["validateModalTitle"],
125
- "hide": ["validateHide"]
126
- }; }
127
- };
128
- MgModal.style = mgModalCss;
129
-
130
- exports.mg_modal = MgModal;
@@ -1,171 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const index = require('./index-94497267.js');
6
- const index$1 = require('./index-179621c8.js');
7
- const popper = require('./popper-11d5f714.js');
8
-
9
- const mgPopoverCss = "mg-popover.sc-mg-popover{display:contents}mg-popover.sc-mg-popover-s>*{display:inline-block}.mg-popover.sc-mg-popover{display:none;padding:1.5rem;z-index:9999;border-radius:0.5rem;background-color:hsl(var(--mg-popover-background-color));box-shadow:var(--box-shadow);color:hsl(var(--mg-popover-font-color))}.mg-popover[data-show].sc-mg-popover{display:block}.mg-popover.sc-mg-popover mg-button.sc-mg-popover{float:right;margin-right:calc(0rem - (var(--default-size) - var(--mg-icon-regular-size)) / 2);margin-top:calc(0rem - (var(--default-size) - var(--mg-popover-title-font-size) * var(--line-height)) / 2);margin-left:3rem}.mg-popover__arrow.sc-mg-popover,.mg-popover__arrow.sc-mg-popover::before{position:absolute;width:2rem;height:2rem;z-index:-1;background:inherit}.mg-popover__arrow.sc-mg-popover{visibility:hidden}.mg-popover__arrow.sc-mg-popover::before{visibility:visible;content:\"\";transform:rotate(45deg)}.mg-popover[data-popper-placement^=top].sc-mg-popover>.mg-popover__arrow.sc-mg-popover{bottom:-6px}.mg-popover[data-popper-placement^=bottom].sc-mg-popover>.mg-popover__arrow.sc-mg-popover{top:-6px}.mg-popover[data-popper-placement^=left].sc-mg-popover>.mg-popover__arrow.sc-mg-popover{right:-6px}.mg-popover[data-popper-placement^=right].sc-mg-popover>.mg-popover__arrow.sc-mg-popover{left:-6px}.mg-popover__title.sc-mg-popover-s>[slot=title],.mg-popover__title .sc-mg-popover-s>[slot=title]{margin:0 0 1rem;font-size:var(--mg-popover-title-font-size);font-weight:600}";
10
-
11
- const MgPopover = class {
12
- constructor(hostRef) {
13
- index.registerInstance(this, hostRef);
14
- this.displayChange = index.createEvent(this, "display-change", 7);
15
- this.closeButtonId = '';
16
- /**
17
- * Sets an `id` attribute.
18
- * Needed by the input for accessibility `aria-decribedby`.
19
- */
20
- this.identifier = index$1.createID('mg-popover');
21
- /**
22
- * Popover placement
23
- */
24
- this.placement = 'bottom';
25
- /**
26
- * Define if popover has a cross button
27
- */
28
- this.closeButton = false;
29
- /**
30
- * Display popover
31
- */
32
- this.display = false;
33
- /**
34
- * Disable popover
35
- */
36
- this.disabled = false;
37
- /**
38
- * Check if clicked outside of component
39
- *
40
- * @param {MouseEvent} event mouse event
41
- * @returns {void}
42
- */
43
- this.clickOutside = (event) => {
44
- var _a;
45
- if (!this.disabled && ((_a = event.target.closest(`#${this.identifier}`)) === null || _a === void 0 ? void 0 : _a.parentElement.nodeName) !== 'MG-POPOVER') {
46
- this.display = false;
47
- }
48
- };
49
- /**
50
- * Show popover
51
- *
52
- * @returns {void}
53
- */
54
- this.show = () => {
55
- // Make the popover visible
56
- this.popover.setAttribute('data-show', '');
57
- // Enable the event listeners
58
- this.popper.setOptions(options => (Object.assign(Object.assign({}, options), { modifiers: [...options.modifiers, { name: 'eventListeners', enabled: true }] })));
59
- // Update its position
60
- this.popper.update();
61
- // hide when click outside
62
- // setTimeout is used to prevent event to trigger after creation
63
- setTimeout(() => {
64
- document.addEventListener('click', this.clickOutside, false);
65
- }, 0);
66
- };
67
- /**
68
- * Hide popover
69
- *
70
- * @returns {void}
71
- */
72
- this.hide = () => {
73
- // Hide the popover
74
- this.popover.removeAttribute('data-show');
75
- // Disable the event listeners
76
- this.popper.setOptions(options => (Object.assign(Object.assign({}, options), { modifiers: [...options.modifiers, { name: 'eventListeners', enabled: false }] })));
77
- // Remove event listener
78
- document.removeEventListener('click', this.clickOutside, false);
79
- };
80
- /**
81
- * Handle action for close button
82
- *
83
- * @returns {void}
84
- */
85
- this.handleCloseButton = () => {
86
- this.display = false;
87
- };
88
- }
89
- handleDisplay(newValue) {
90
- if (newValue) {
91
- this.show();
92
- }
93
- else {
94
- this.hide();
95
- }
96
- this.displayChange.emit(newValue);
97
- }
98
- /*************
99
- * Lifecycle *
100
- *************/
101
- /**
102
- * Check if component props are well configured on init
103
- *
104
- * @returns {void} timeout
105
- */
106
- componentWillLoad() {
107
- // Get locales
108
- this.messages = index$1.initLocales(this.element).messages;
109
- }
110
- /**
111
- * Check if component props are well configured on init
112
- *
113
- * @returns {void}
114
- */
115
- componentDidLoad() {
116
- const headingTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
117
- const slotedTitleElement = this.element.querySelector('[slot="title"]');
118
- if (slotedTitleElement && !index$1.isTagName(slotedTitleElement, headingTags)) {
119
- throw new Error(`<mg-popover> Slotted title must be a heading: ${headingTags.join(', ')}`);
120
- }
121
- // Set close button id
122
- if (this.closeButton) {
123
- this.closeButtonId = `${this.identifier}-close-button`;
124
- }
125
- // Get popover content
126
- this.popover = this.element.querySelector(`#${this.identifier}`);
127
- //Get interactive element
128
- const interactiveElement = this.element.firstElementChild;
129
- // Add aria attributes
130
- interactiveElement.setAttribute('aria-controls', this.identifier);
131
- interactiveElement.setAttribute('aria-expanded', `${this.display}`);
132
- // Create popperjs popover
133
- this.popper = popper.createPopper(interactiveElement, this.popover, {
134
- placement: this.placement,
135
- modifiers: [
136
- {
137
- name: 'offset',
138
- options: {
139
- offset: [0, 10],
140
- },
141
- },
142
- ],
143
- });
144
- // Add events to toggle display
145
- interactiveElement.addEventListener('click', () => {
146
- if (!this.disabled)
147
- this.display = !this.display;
148
- });
149
- // Add events to hide popover
150
- this.element.addEventListener('keydown', e => {
151
- if (!this.disabled && e.code === 'Escape')
152
- this.display = false;
153
- });
154
- this.handleDisplay(this.display);
155
- }
156
- /**
157
- * Render
158
- *
159
- * @returns {HTMLElement} HTML Element
160
- */
161
- render() {
162
- return (index.h(index.Host, null, index.h("slot", null), index.h("div", { id: this.identifier, class: "mg-popover" }, !this.disabled && this.closeButton && (index.h("mg-button", { identifier: this.closeButtonId, "is-icon": true, variant: "flat", label: this.messages.general.close, onClick: this.handleCloseButton }, index.h("mg-icon", { icon: "cross" }))), index.h("div", { class: "mg-popover__title" }, index.h("slot", { name: "title" })), index.h("slot", { name: "content" }), index.h("div", { class: "mg-popover__arrow", "data-popper-arrow": true }))));
163
- }
164
- get element() { return index.getElement(this); }
165
- static get watchers() { return {
166
- "display": ["handleDisplay"]
167
- }; }
168
- };
169
- MgPopover.style = mgPopoverCss;
170
-
171
- exports.mg_popover = MgPopover;