@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,20 +0,0 @@
1
- /**
2
- * List of all possibles placements
3
- */
4
- export const placements = [
5
- 'auto',
6
- 'auto-start',
7
- 'auto-end',
8
- 'top',
9
- 'top-start',
10
- 'top-end',
11
- 'bottom',
12
- 'bottom-start',
13
- 'bottom-end',
14
- 'right',
15
- 'right-start',
16
- 'right-end',
17
- 'left',
18
- 'left-start',
19
- 'left-end',
20
- ];
@@ -1,212 +0,0 @@
1
- :root {
2
- /*
3
- Fonts
4
- */
5
-
6
- --font-size: 1.3rem;
7
- --line-height: 1.4;
8
-
9
- /* Open Sans is used for the body (mostly all texts) */
10
- --font-family: 'Open Sans', sans-serif;
11
-
12
- /* Headings (h1 to h6) font can be customized */
13
- --font-family-heading: var(--font-family);
14
-
15
- /* Font colors */
16
- --color-font-light: var(--color-light);
17
- --color-font-dark: var(--color-dark);
18
- /*
19
- Colors
20
- https://jira.mgdis.fr/browse/PDA9-690
21
- */
22
-
23
- /* Neutral */
24
- /* #fefefe; */
25
- /* rgb(254, 254, 254); */
26
- --color-neutral-h: 0;
27
- --color-neutral-s: 0%;
28
- --color-neutral-l: 99.6%;
29
- --color-neutral: var(--color-neutral-h), var(--color-neutral-s), var(--color-neutral-l);
30
-
31
- /* Warning */
32
- /* #ffc33e */
33
- /* rgb(255, 195, 62); */
34
- --color-warning-h: 41;
35
- --color-warning-s: 100%;
36
- --color-warning-l: 62.2%;
37
- --color-warning: var(--color-warning-h), var(--color-warning-s), var(--color-warning-l);
38
-
39
- /* Success */
40
- /* #32d59c */
41
- /* rgb(50, 213, 156); */
42
- --color-success-h: 159;
43
- --color-success-s: 66%;
44
- --color-success-l: 51.6%;
45
- --color-success: var(--color-success-h), var(--color-success-s), var(--color-success-l);
46
-
47
- /* Info */
48
- /* #005e9c; */
49
- /* rgb(0, 94, 156); */
50
- --color-info-h: 204;
51
- --color-info-s: 100%;
52
- --color-info-l: 30.6%;
53
- --color-info: var(--color-info-h), var(--color-info-s), var(--color-info-l);
54
-
55
- /* Danger */
56
- /* #db1f29; */
57
- /* rgb(219, 31, 41); */
58
- --color-danger-h: 357;
59
- --color-danger-s: 75%;
60
- --color-danger-l: 49%;
61
- --color-danger: var(--color-danger-h), var(--color-danger-s), var(--color-danger-l);
62
-
63
- /* Dark */
64
- /* #15282e; */
65
- /* rgb(21, 40, 46); */
66
- --color-dark-h: 194;
67
- --color-dark-s: 37.3%;
68
- --color-dark-l: 13.1%;
69
- --color-dark: var(--color-dark-h), var(--color-dark-s), var(--color-dark-l);
70
-
71
- /* Light */
72
- /* white; (#ffffff) */
73
- /* rgb(255, 255, 255); */
74
- --color-light-h: 0;
75
- --color-light-s: 0%;
76
- --color-light-l: 100%;
77
- --color-light: var(--color-light-h), var(--color-light-s), var(--color-light-l);
78
-
79
- /* Primary */
80
- --color-primary-h: hsl(var(--color-dark-h));
81
- --color-primary-s: hsl(var(--color-dark-s));
82
- --color-primary-l: hsl(var(--color-dark-l));
83
- --color-primary: hsl(var(--color-dark));
84
-
85
- /* Secondary */
86
- --color-secondary-h: hsl(var(--color-neutral-h));
87
- --color-secondary-s: hsl(var(--color-neutral-s));
88
- --color-secondary-l: hsl(var(--color-neutral-l));
89
- --color-secondary: hsl(var(--color-neutral));
90
-
91
- /* Shadow */
92
- --box-shadow: 0 0.3rem 0.8rem 0 rgba(0, 0, 0, 0.1);
93
-
94
- /*
95
- Global
96
- */
97
- --default-size: 3.5rem;
98
-
99
- /*
100
- <mg-icon>
101
- */
102
- --mg-icon-small-size: 1.2rem;
103
- --mg-icon-regular-size: 1.6rem;
104
- --mg-icon-large-size: 2.4rem;
105
- --mg-icon-extra-large-size: 3.6rem;
106
-
107
- /*
108
- <mg-button>
109
- */
110
-
111
- --mg-button-border-radius: 0.3rem;
112
- --mg-button-icon-border-radius: var(--default-size);
113
- --mg-button-disabled-opacity: 0.6;
114
- --mg-button-gradient: 1; /* Can only be 1 or 0 to enable disable gradient */
115
- --mg-button-border-variation: 1; /* Can only be 1 or 0 to enable disable border variation */
116
-
117
- /* Primary */
118
- --mg-button-primary-color-h: var(--color-dark-h);
119
- --mg-button-primary-color-s: var(--color-dark-s);
120
- --mg-button-primary-color-l: var(--color-dark-l);
121
- --mg-button-primary-font-color: var(--color-neutral);
122
-
123
- /* Secondary */
124
- --mg-button-secondary-color-h: var(--color-neutral-h);
125
- --mg-button-secondary-color-s: var(--color-neutral-s);
126
- --mg-button-secondary-color-l: var(--color-neutral-l);
127
- --mg-button-secondary-font-color: var(--color-dark);
128
-
129
- /*
130
- <mg-tag>
131
- */
132
- --mg-tag-height: 2.3rem;
133
- --mg-tag-border-radius: 0.5rem;
134
- --mg-tag-font-size: 1.2rem;
135
-
136
- /*
137
- <mg-badge>
138
- */
139
- --mg-badge-size: 1.6rem;
140
- --mg-badge-font-size: 1.1rem;
141
-
142
- /*
143
- <mg-tooltip>
144
- */
145
- --mg-tooltip-border-radius: 0.5rem;
146
- --mg-tooltip-background-color: var(--color-dark);
147
- --mg-tooltip-font-color: var(--color-font-light);
148
-
149
- /*
150
- <mg-popover>
151
- */
152
- --mg-popover-background-color: var(--color-light);
153
- --mg-popover-font-color: var(--color-font-dark);
154
- --mg-popover-title-font-size: 1.4rem;
155
-
156
- /*
157
- <mg-message>
158
- */
159
- --mg-message-border-radius: 0.3rem;
160
-
161
- /*
162
- <mg-modal>
163
- */
164
- --mg-modal-border-radius: 0.5rem;
165
- --mg-modal-title-font-size: 1.8rem;
166
- --mg-modal-content-font-size: 1.2rem;
167
-
168
- /*
169
- <mg-panel>
170
- */
171
-
172
- --mg-panel-border-radius: 0.5rem;
173
- --mg-panel-background: var(--color-info-h) var(--color-info-s) calc(var(--color-info-l) + 68%);
174
- --mg-panel-content-padding: 1.5rem;
175
-
176
- /*
177
- Layout
178
- */
179
- --mg-grid-spacing: 1rem;
180
-
181
- /*
182
- Forms
183
- */
184
-
185
- /*
186
- <mg-input-...>
187
- */
188
- --mg-inputs-border-width: 0.1rem;
189
- --mg-inputs-border-radius: 0.3rem;
190
- --mg-inputs-color: #b5c2c9;
191
- --mg-inputs-spacer: 1rem;
192
-
193
- /* Error message background */
194
- --mg-inputs-error-bg-color: var(--color-danger-h), calc(var(--color-danger-s) + 5%), calc(var(--color-danger-l) + 49%);
195
-
196
- /* Input focus shadow */
197
- /* #b5c2c9 */
198
- /* rgb(0, 221, 255); */
199
- /* hsl(188, 100%, 50%); */
200
- --mg-inputs-color-shadow-focus-hsl: 188, 100%, 50%;
201
-
202
- /*
203
- <mg-input-toggle>
204
- */
205
- --mg-input-toggle-border-radius-ratio: 2;
206
-
207
- /*
208
- <mg-input-checkbox>
209
- <mg-input-radio>
210
- */
211
- --mg-input-check-size: 1.3rem;
212
- }
@@ -1,238 +0,0 @@
1
- /**
2
- * Create random ID
3
- *
4
- * @param {string} prefix add prefix to created ID
5
- * @param {number} length ID length
6
- * @returns {string} ID
7
- */
8
- function createID(prefix = '', length = 10) {
9
- let ID = '';
10
- const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
11
- const charsLength = chars.length;
12
- for (let i = 0; i < length; i++) {
13
- ID += chars.charAt(Math.floor(Math.random() * charsLength));
14
- }
15
- return (prefix !== '' ? `${prefix}-` : '') + ID;
16
- }
17
- /**
18
- * Class to manage component classlist
19
- * Set() are not working when imported in project
20
- */
21
- class ClassList {
22
- constructor(classlist = []) {
23
- /**
24
- * Add class
25
- *
26
- * @param {string} className class name to add
27
- * @returns {void}
28
- */
29
- this.add = (className) => {
30
- if (!this.has(className)) {
31
- this.classes.push(className);
32
- }
33
- };
34
- /**
35
- * Delete class
36
- *
37
- * @param {string} className class name to delete
38
- * @returns {void}
39
- */
40
- this.delete = (className) => {
41
- const index = this.classes.indexOf(className);
42
- if (index > -1) {
43
- this.classes.splice(index, 1);
44
- }
45
- };
46
- /**
47
- * Check if class exist in list
48
- *
49
- * @param {string} className class name to check
50
- * @returns {boolean} class name is in the list
51
- */
52
- this.has = (className) => {
53
- return this.classes.includes(className);
54
- };
55
- /**
56
- * Join classes seperated by spaces
57
- *
58
- * @returns {string} joined values
59
- */
60
- this.join = () => {
61
- return this.classes.join(' ');
62
- };
63
- this.classes = classlist;
64
- }
65
- }
66
- /**
67
- * Check if all items are string
68
- *
69
- * @param {string[]} items items to check
70
- * @returns {boolean} all items are string
71
- */
72
- function allItemsAreString(items) {
73
- return items && items.every(item => typeof item === 'string');
74
- }
75
- /**
76
- * Check if element is a heading
77
- *
78
- * @param {Element} element slotted element
79
- * @param {string[]} tagNames allowed tag names list
80
- * @returns {boolean} element is a heading
81
- */
82
- function isTagName(element, tagNames) {
83
- return tagNames.includes(element === null || element === void 0 ? void 0 : element.tagName.toLowerCase());
84
- }
85
-
86
- const errors$1 = {
87
- required: "This field is required.",
88
- date: {
89
- 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}",
90
- min: "The date cannot be earlier than {min}",
91
- max: "The date cannot be later than {max}",
92
- minMax: "The date must be between {min} and {max}"
93
- },
94
- numeric: {
95
- min: "The value cannot be less than {min}",
96
- max: "The value cannot be greater than {max}",
97
- minMax: "The value must be between {min} et {max}"
98
- }
99
- };
100
- const nbCharLeft$1 = "{counter} characters left.";
101
- const input$1 = {
102
- select: {
103
- placeholder: "Select a value"
104
- }
105
- };
106
- const form$1 = {
107
- required: "Fields with a <strong class=\"is-asterisk\">*</strong> are required",
108
- allRequired: "All fields are required"
109
- };
110
- const message$1 = {
111
- closeButton: "Close message"
112
- };
113
- const modal$1 = {
114
- closeButton: "Close modal"
115
- };
116
- const pagination$1 = {
117
- label: "Pagination",
118
- page: "page",
119
- pages: "pages",
120
- nextPage: "Next page",
121
- previousPage: "Previous page",
122
- selectPage: "Select the page to display."
123
- };
124
- const panel$1 = {
125
- editLabel: "Edit section title."
126
- };
127
- const general$1 = {
128
- confirm: "Confirm",
129
- cancel: "Cancel",
130
- close: "Close",
131
- next: "next",
132
- previous: "previous"
133
- };
134
- const en = {
135
- errors: errors$1,
136
- nbCharLeft: nbCharLeft$1,
137
- input: input$1,
138
- form: form$1,
139
- message: message$1,
140
- modal: modal$1,
141
- pagination: pagination$1,
142
- panel: panel$1,
143
- general: general$1
144
- };
145
-
146
- const errors = {
147
- required: "Ce champ est obligatoire.",
148
- date: {
149
- 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}",
150
- min: "La date ne peut pas être antérieure au {min}",
151
- max: "La date ne peut pas être postérieure au {max}",
152
- minMax: "La date doit être comprise entre le {min} et le {max}"
153
- },
154
- numeric: {
155
- min: "La valeur ne peut pas être inférieure à {min}",
156
- max: "La valeur ne peut pas être supérieure à {max}",
157
- minMax: "La valeur doit être comprise entre {min} et {max}"
158
- }
159
- };
160
- const nbCharLeft = "{counter} caractères disponibles.";
161
- const input = {
162
- select: {
163
- placeholder: "Sélectionnez une valeur"
164
- }
165
- };
166
- const form = {
167
- required: "Les champs marqués d'un <strong class=\"is-asterisk\">*</strong> sont obligatoires",
168
- allRequired: "Tous les champs sont obligatoires"
169
- };
170
- const message = {
171
- closeButton: "Fermer le message"
172
- };
173
- const modal = {
174
- closeButton: "Fermer la modale"
175
- };
176
- const pagination = {
177
- label: "Pagination",
178
- page: "page",
179
- pages: "pages",
180
- nextPage: "Page suivante",
181
- previousPage: "Page précédente",
182
- selectPage: "Sélectionner la page à afficher."
183
- };
184
- const panel = {
185
- editLabel: "Modifier le titre de la section."
186
- };
187
- const general = {
188
- confirm: "Valider",
189
- cancel: "Annuler",
190
- close: "Fermer",
191
- next: "suivant",
192
- previous: "précédent"
193
- };
194
- const fr = {
195
- errors: errors,
196
- nbCharLeft: nbCharLeft,
197
- input: input,
198
- form: form,
199
- message: message,
200
- modal: modal,
201
- pagination: pagination,
202
- panel: panel,
203
- general: general
204
- };
205
-
206
- const defaultLocale = 'en';
207
- const messages = { en, fr };
208
- /**
209
- * Get locale
210
- *
211
- * @param {HTMLElement} element element that needs to know the locale to use
212
- * @returns {string} locale
213
- */
214
- const getLocale = (element) => {
215
- var _a;
216
- return ((_a = element.closest('[lang]')) === null || _a === void 0 ? void 0 : _a.lang) || navigator.language || defaultLocale;
217
- };
218
- /**
219
- * Get Intl object
220
- * We load the defined locale but for now we only support the first subtag for messages
221
- *
222
- * @param {HTMLElement} element element we need to get the language
223
- * @returns {{ locale: string; messages: unknown }} messages object
224
- */
225
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
226
- const initLocales = (element) => {
227
- // Get local
228
- const locale = getLocale(element);
229
- // Only keep first subtag
230
- const localeSubtag = locale.split('-').shift();
231
- // Return
232
- return {
233
- locale,
234
- messages: messages[localeSubtag] || messages[defaultLocale],
235
- };
236
- };
237
-
238
- export { ClassList as C, isTagName as a, allItemsAreString as b, createID as c, initLocales as i };
@@ -1,126 +0,0 @@
1
- import { r as registerInstance, c as createEvent, h, g as getElement } from './index-aad0184c.js';
2
- import { c as createID, C as ClassList, i as initLocales } from './index-7efedd97.js';
3
-
4
- 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}";
5
-
6
- const MgModal = class {
7
- constructor(hostRef) {
8
- registerInstance(this, hostRef);
9
- this.componentShow = createEvent(this, "component-show", 7);
10
- this.componentHide = createEvent(this, "component-hide", 7);
11
- /************
12
- * Internal *
13
- ************/
14
- // Classes
15
- this.classHide = 'mg-modal--hide';
16
- // IDs
17
- this.closeButtonId = '';
18
- this.titleId = '';
19
- /**
20
- * Identifier is used for the element ID (id is a reserved prop in Stencil.js)
21
- * If not set, it will be created.
22
- */
23
- this.identifier = createID('mg-modal');
24
- /**
25
- * Define if modal has a cross button
26
- */
27
- this.closeButton = false;
28
- /**
29
- * Define if modal is hidden
30
- */
31
- this.hide = false;
32
- /**
33
- * Define if component is using actions slot
34
- */
35
- this.hasActions = false;
36
- /**
37
- * Define if component is using content slot
38
- */
39
- this.hasContent = false;
40
- /**
41
- * Component classes
42
- */
43
- this.classList = new ClassList(['mg-modal']);
44
- /*************
45
- * Handlers *
46
- *************/
47
- /**
48
- * Handle close button
49
- *
50
- * @returns {void}
51
- */
52
- this.handleClose = () => {
53
- this.hide = true;
54
- };
55
- }
56
- validateModalTitle(newValue) {
57
- if (typeof newValue !== 'string' || newValue.trim() === '') {
58
- // TODO: throw new Error on next major (5.0.0)
59
- // throw new Error('<mg-modal> prop "modalTitle" is required.');
60
- console.error('<mg-modal> prop "modalTitle" is required.');
61
- }
62
- }
63
- validateHide(newValue) {
64
- if (newValue) {
65
- this.componentHide.emit();
66
- this.classList.add(this.classHide);
67
- document.body.style.overflow = this.bodyOverflow;
68
- }
69
- else {
70
- this.componentShow.emit();
71
- this.classList.delete(this.classHide);
72
- document.body.style.overflow = 'hidden';
73
- }
74
- }
75
- /**
76
- * Handle 'escape' key down
77
- *
78
- * @param {KeyboardEvent} event keydown event
79
- * @returns {void}
80
- */
81
- handleKeyDown(event) {
82
- // we can use 'Escape button" when this not a blocking modal, induced by closeButton value.
83
- if (this.closeButton && event.key === 'Escape') {
84
- this.hide = true;
85
- }
86
- }
87
- /*************
88
- * Lifecycle *
89
- *************/
90
- /**
91
- * Check if component props are well configured on init
92
- *
93
- * @returns {void}
94
- */
95
- componentWillLoad() {
96
- // Store body overflow
97
- this.bodyOverflow = document.body.style.overflow;
98
- // Get locales
99
- this.messages = initLocales(this.element).messages;
100
- // Validate
101
- this.hasActions = this.element.querySelector('[slot="actions"]') !== null;
102
- this.hasContent = this.element.querySelector('[slot="content"]') !== null;
103
- if (this.closeButton) {
104
- this.closeButtonId = `${this.identifier}-close-button`;
105
- }
106
- this.titleId = `${this.identifier}-title`;
107
- this.validateModalTitle(this.modalTitle);
108
- this.validateHide(this.hide);
109
- }
110
- /**
111
- * Render
112
- *
113
- * @returns {HTMLElement} HTML Element
114
- */
115
- render() {
116
- return (h("section", { role: "dialog", id: this.identifier, class: this.classList.join(), tabindex: "-1", "aria-labelledby": this.titleId, "aria-modal": "true", "aria-hidden": this.hide }, h("article", { class: "mg-modal__dialog" }, h("header", { class: "mg-modal__header" }, this.closeButton && (h("span", { class: "mg-modal__close-button" }, h("mg-button", { identifier: this.closeButtonId, "is-icon": true, variant: "flat", label: this.messages.modal.closeButton, onClick: this.handleClose }, h("mg-icon", { icon: "cross" })))), h("h1", { class: "mg-modal__title", id: this.titleId }, this.modalTitle)), this.hasContent && (h("article", { class: "mg-modal__content" }, h("slot", { name: "content" }))), this.hasActions && (h("footer", { class: "mg-modal__footer" }, h("slot", { name: "actions" }))))));
117
- }
118
- get element() { return getElement(this); }
119
- static get watchers() { return {
120
- "modalTitle": ["validateModalTitle"],
121
- "hide": ["validateHide"]
122
- }; }
123
- };
124
- MgModal.style = mgModalCss;
125
-
126
- export { MgModal as mg_modal };