@mgdis/mg-components 5.11.0 → 5.12.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 (49) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/mg-action-more_31.cjs.entry.js +294 -249
  3. package/dist/cjs/mg-components.cjs.js +1 -1
  4. package/dist/cjs/mg-item-more.cjs.entry.js +1 -1
  5. package/dist/cjs/{mg-menu.conf-05ec32a3.js → mg-menu.conf-79f0c761.js} +12 -2
  6. package/dist/collection/components/atoms/mg-icon/mg-icon.conf.js +0 -218
  7. package/dist/collection/components/atoms/mg-icon/mg-icon.css +0 -7
  8. package/dist/collection/components/atoms/mg-icon/mg-icon.js +6 -9
  9. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.css +34 -0
  10. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +159 -17
  11. package/dist/collection/components/molecules/mg-details/mg-details.css +20 -3
  12. package/dist/collection/components/molecules/mg-popover/mg-popover.js +4 -4
  13. package/dist/collection/locales/en/messages.json +6 -1
  14. package/dist/collection/locales/fr/messages.json +6 -1
  15. package/dist/collection/styles/a11y.scss +5 -1
  16. package/dist/collection/styles/typography.scss +7 -0
  17. package/dist/collection/variables.css +8 -0
  18. package/dist/components/index2.js +12 -2
  19. package/dist/components/mg-details.js +1 -1
  20. package/dist/components/mg-icon2.js +157 -227
  21. package/dist/components/mg-input-checkbox.js +170 -26
  22. package/dist/components/mg-pagination.js +1 -170
  23. package/dist/components/mg-pagination2.js +172 -0
  24. package/dist/components/mg-popover2.js +4 -4
  25. package/dist/esm/loader.js +1 -1
  26. package/dist/esm/mg-action-more_31.entry.js +294 -249
  27. package/dist/esm/mg-components.js +1 -1
  28. package/dist/esm/mg-item-more.entry.js +1 -1
  29. package/dist/esm/{mg-menu.conf-c8aa56ce.js → mg-menu.conf-850d4c6e.js} +12 -2
  30. package/dist/mg-components/locales/en/messages.json +6 -1
  31. package/dist/mg-components/locales/fr/messages.json +6 -1
  32. package/dist/mg-components/mg-components.css +1 -1
  33. package/dist/mg-components/mg-components.esm.js +1 -1
  34. package/dist/mg-components/p-60b7afd9.entry.js +1 -0
  35. package/dist/mg-components/{p-d3ed97d3.entry.js → p-67ba5d05.entry.js} +1 -1
  36. package/dist/mg-components/p-689503fc.js +1 -0
  37. package/dist/mg-components/styles/a11y.scss +5 -1
  38. package/dist/mg-components/styles/typography.scss +7 -0
  39. package/dist/mg-components/variables.css +8 -0
  40. package/dist/types/components/atoms/mg-icon/mg-icon.conf.d.ts +0 -4
  41. package/dist/types/components/atoms/mg-icon/mg-icon.d.ts +0 -5
  42. package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.conf.d.ts +4 -0
  43. package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +79 -2
  44. package/dist/types/components/molecules/mg-popover/mg-popover.d.ts +1 -1
  45. package/dist/types/components.d.ts +8 -0
  46. package/dist/types/locales/index.d.ts +10 -0
  47. package/package.json +7 -5
  48. package/dist/mg-components/p-51c2def3.entry.js +0 -1
  49. package/dist/mg-components/p-b14be68b.js +0 -1
@@ -2,10 +2,14 @@ import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/i
2
2
  import { M as MgInput } from './MgInput.js';
3
3
  import { C as ClassList } from './components.utils.js';
4
4
  import { i as initLocales } from './index2.js';
5
- import { d as defineCustomElement$7 } from './mg-button2.js';
6
- import { d as defineCustomElement$6 } from './mg-card2.js';
7
- import { d as defineCustomElement$5 } from './mg-icon2.js';
8
- import { d as defineCustomElement$4 } from './mg-input-title2.js';
5
+ import { d as defineCustomElement$b } from './mg-button2.js';
6
+ import { d as defineCustomElement$a } from './mg-card2.js';
7
+ import { d as defineCustomElement$9 } from './mg-character-left2.js';
8
+ import { d as defineCustomElement$8 } from './mg-icon2.js';
9
+ import { d as defineCustomElement$7 } from './mg-input-select2.js';
10
+ import { d as defineCustomElement$6 } from './mg-input-text2.js';
11
+ import { d as defineCustomElement$5 } from './mg-input-title2.js';
12
+ import { d as defineCustomElement$4 } from './mg-pagination2.js';
9
13
  import { d as defineCustomElement$3 } from './mg-popover2.js';
10
14
  import { d as defineCustomElement$2 } from './mg-tooltip2.js';
11
15
 
@@ -14,7 +18,7 @@ import { d as defineCustomElement$2 } from './mg-tooltip2.js';
14
18
  */
15
19
  const checkboxTypes = ['checkbox', 'multi'];
16
20
 
17
- const mgInputCheckboxCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__input .mg-input__box:disabled,.mg-input__input-group--disabled label,.mg-input.mg-input--toggle-disabled .mg-input__input .mg-input__button-toggle,.mg-input.mg-input--checkbox-multi-disabled .mg-input__input strong{opacity:var(--mg-disabled-opacity)}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}fieldset.mg-input{border:0;margin-left:0;margin-right:0;padding:0}fieldset.mg-input input[type=radio],fieldset.mg-input input[type=checkbox]{flex-shrink:0;width:var(--mg-input-check-size);height:var(--mg-input-check-size);margin-top:calc((var(--font-size) * var(--line-height) - var(--mg-input-check-size)) / 2);margin-right:0.6rem;margin-bottom:0;margin-left:0}fieldset.mg-input.mg-input--label-on-top .mg-input__input-group-container{margin-top:0.7rem}.mg-input__input-container mg-tooltip{margin-left:3rem}.mg-input__input-group-container{margin:0;padding:0;list-style:none;display:flex;flex-wrap:wrap;column-gap:2.3rem;row-gap:1rem;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2)}.mg-input__input-group-container--vertical{flex-direction:column}.mg-input__input-group{display:flex;align-items:top}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}@media (prefers-reduced-motion){.mg-a11y-animation{animation:none !important;transition:none !important}}.mg-input.mg-input--checkbox-multi .mg-input__input-checkbox-multi{display:flex;flex-wrap:wrap;gap:calc(var(--mg-inputs-spacer) * 1.2)}.mg-input.mg-input--checkbox-multi .mg-input__input-checkbox-multi-inputs{margin:0}.mg-input.mg-input--checkbox-multi:not(.mg-input--label-on-top) mg-tooltip{margin-left:var(--mg-inputs-spacer)}.mg-input.mg-input--checkbox-multi mg-popover{--mg-popover-min-width:7rem}";
21
+ const mgInputCheckboxCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__input .mg-input__box:disabled,.mg-input__input-group--disabled label,.mg-input.mg-input--toggle-disabled .mg-input__input .mg-input__button-toggle,.mg-input.mg-input--checkbox-multi-disabled .mg-input__input strong{opacity:var(--mg-disabled-opacity)}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}fieldset.mg-input{border:0;margin-left:0;margin-right:0;padding:0}fieldset.mg-input input[type=radio],fieldset.mg-input input[type=checkbox]{flex-shrink:0;width:var(--mg-input-check-size);height:var(--mg-input-check-size);margin-top:calc((var(--font-size) * var(--line-height) - var(--mg-input-check-size)) / 2);margin-right:0.6rem;margin-bottom:0;margin-left:0}fieldset.mg-input.mg-input--label-on-top .mg-input__input-group-container{margin-top:0.7rem}.mg-input__input-container mg-tooltip{margin-left:3rem}.mg-input__input-group-container{margin:0;padding:0;list-style:none;display:flex;flex-wrap:wrap;column-gap:2.3rem;row-gap:1rem;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2)}.mg-input__input-group-container--vertical{flex-direction:column}.mg-input__input-group{display:flex;align-items:top}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}@media (prefers-reduced-motion){.mg-a11y-animation{animation:none !important;transition:none !important}}.mg-input.mg-input--checkbox-multi .mg-input__input-checkbox-multi{display:flex;flex-wrap:wrap;gap:calc(var(--mg-inputs-spacer) * 1.2)}.mg-input.mg-input--checkbox-multi .mg-input__input-checkbox-multi--with-values.mg-input__input-checkbox-multi{gap:0.4rem}.mg-input.mg-input--checkbox-multi .mg-input__input-checkbox-multi-values-container{display:flex;flex-wrap:wrap;gap:0.4rem;margin:0;padding:0;list-style:none}.mg-input.mg-input--checkbox-multi .mg-input__input-checkbox-multi-value{display:inline-flex;justify-content:center;align-items:center;box-sizing:border-box;min-height:var(--default-size);min-width:var(--default-size);padding:calc((var(--default-size) - 0.2rem - var(--font-size) * var(--line-height)) / 2) 1.1rem;background-color:var(--mg-color-dark-5-hsl);border-radius:0.3rem;font-size:var(--font-size)}.mg-input.mg-input--checkbox-multi .mg-input__input-checkbox-multi-no-result{text-align:center}.mg-input.mg-input--checkbox-multi .mg-input__input-checkbox-multi-inputs{margin:0}.mg-input.mg-input--checkbox-multi:not(.mg-input--label-on-top) mg-tooltip{margin-left:var(--mg-inputs-spacer)}.mg-input.mg-input--checkbox-multi mg-popover{--mg-popover-min-width:7rem}.mg-input.mg-input--checkbox-multi mg-popover [slot=content]{display:flex;flex-direction:column;gap:calc(0.4rem * 2)}.mg-input.mg-input--checkbox-multi mg-input-text{--mg-inputs-margin-bottom:0}";
18
22
 
19
23
  /**
20
24
  * type CheckboxItem validation function
@@ -39,6 +43,9 @@ const MgInputCheckbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
39
43
  this.hasDisplayedError = false;
40
44
  // style
41
45
  this.baseClassName = 'mg-input--checkbox';
46
+ this.multiStart = 5;
47
+ this.searchStart = 10;
48
+ this.searchOffset = 10;
42
49
  /**
43
50
  * Handle input event
44
51
  * @param event - input event
@@ -60,12 +67,12 @@ const MgInputCheckbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
60
67
  this.handleKeydown = (event) => {
61
68
  var _a;
62
69
  // track "Tab" key event when popover display (is "multi" type selected)
63
- if (event.key === 'Tab' && ((_a = this.popover) === null || _a === void 0 ? void 0 : _a.display)) {
70
+ if (event.key === 'Tab' && ((_a = this.mgPopover) === null || _a === void 0 ? void 0 : _a.display)) {
64
71
  const enableInputs = this.checkboxItems.filter(input => !input.disabled).map(({ id }) => id);
65
72
  const originInputIndex = enableInputs.findIndex(id => id === event.target.id);
66
73
  // close popover when tab trigger focus outside its DOM
67
74
  if ((originInputIndex + 1 >= enableInputs.length && !event.shiftKey) || (originInputIndex === 0 && event.shiftKey))
68
- this.popover.display = false;
75
+ this.mgPopover.display = false;
69
76
  }
70
77
  };
71
78
  /**
@@ -76,6 +83,27 @@ const MgInputCheckbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
76
83
  this.checkValidity();
77
84
  this.setErrorMessage();
78
85
  };
86
+ /**
87
+ * Handle input search value-change event
88
+ * @param event - input value-change event
89
+ */
90
+ this.handleSearchChange = (event) => {
91
+ this.searchValue = event.detail;
92
+ };
93
+ /**
94
+ * Handle mg-pagination current page change event
95
+ * @param event - pagination current page change event
96
+ */
97
+ this.handleCurrentPageChange = (event) => {
98
+ this.currentSearchPage = Number(event.detail);
99
+ };
100
+ this.handleMgPopoverDisplayChange = (event) => {
101
+ // reset search value
102
+ if (!event.detail) {
103
+ this.searchValue = '';
104
+ this.setCurrentSearchPage();
105
+ }
106
+ };
79
107
  /**
80
108
  * get invalid element
81
109
  * @returns element
@@ -119,6 +147,17 @@ const MgInputCheckbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
119
147
  * @returns MgPopover identifier
120
148
  */
121
149
  this.getMgPopoverIdentifier = () => `${this.identifier}-input-mg-popover`;
150
+ /**
151
+ * Manage items to display depending on the search state
152
+ * @returns items to display
153
+ */
154
+ this.getDisplayItems = () => (this.searchValue.length > 0 ? this.searchResults : this.checkboxItems);
155
+ /**
156
+ * Method to get pagination total-page
157
+ * @param checkboxes - checkboxes to paginate
158
+ * @returns total page number for pagination
159
+ */
160
+ this.getPaginationTotalPages = (checkboxes) => Math.ceil(checkboxes.length / this.searchOffset);
122
161
  this.value = undefined;
123
162
  this.type = checkboxTypes[0];
124
163
  this.identifier = undefined;
@@ -129,6 +168,7 @@ const MgInputCheckbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
129
168
  this.inputVerticalList = false;
130
169
  this.required = false;
131
170
  this.readonly = false;
171
+ this.displaySelectedValues = undefined;
132
172
  this.disabled = false;
133
173
  this.tooltip = undefined;
134
174
  this.helpText = undefined;
@@ -137,6 +177,10 @@ const MgInputCheckbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
137
177
  this.classCollection = new ClassList([this.baseClassName]);
138
178
  this.errorMessage = undefined;
139
179
  this.checkboxItems = [];
180
+ this.displaySearchInput = undefined;
181
+ this.currentSearchPage = 0;
182
+ this.searchValue = '';
183
+ this.searchResults = [];
140
184
  }
141
185
  validateValue(newValue) {
142
186
  if (isCheckboxItems(newValue)) {
@@ -158,12 +202,18 @@ const MgInputCheckbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
158
202
  }
159
203
  else {
160
204
  const className = `${this.baseClassName}-multi`;
161
- if (newValue === 'multi')
205
+ if (newValue === 'multi') {
162
206
  this.classCollection.add(className);
207
+ this.element.dataset.mgPopoverGuard = this.getMgPopoverIdentifier();
208
+ }
163
209
  else
164
210
  this.classCollection.delete(className);
165
211
  }
166
212
  }
213
+ validateDisplaySelectedValues(newValue) {
214
+ if (newValue !== undefined && this.type !== 'multi')
215
+ throw new Error('<mg-input-checkbox> prop "displaySelectedValues" can only be used with prop type "multi".');
216
+ }
167
217
  handleValidityChange(newValue, _oldValue, prop) {
168
218
  this.inputs.forEach(input => {
169
219
  input[prop] = newValue;
@@ -181,6 +231,17 @@ const MgInputCheckbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
181
231
  else
182
232
  this.classCollection.delete(className);
183
233
  }
234
+ validateCheckboxItems(newValue) {
235
+ if (newValue.length > this.multiStart)
236
+ this.type = 'multi';
237
+ if (newValue.length > this.searchStart)
238
+ this.displaySearchInput = this.type === 'multi';
239
+ }
240
+ validateSearchValue(newValue) {
241
+ this.searchResults = this.checkboxItems.filter(item => item.title.toLocaleLowerCase().includes(newValue.trim().toLocaleLowerCase()));
242
+ // after each query we reset pagination
243
+ this.setCurrentSearchPage();
244
+ }
184
245
  /**
185
246
  * Public method to display errors
186
247
  */
@@ -189,6 +250,31 @@ const MgInputCheckbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
189
250
  this.setErrorMessage();
190
251
  this.hasDisplayedError = this.invalid;
191
252
  }
253
+ /**
254
+ * Reset current-search-page prop
255
+ */
256
+ setCurrentSearchPage() {
257
+ this.currentSearchPage = this.getDisplayItems().length > 0 ? 1 : 0;
258
+ }
259
+ /**
260
+ * Method to get a array range
261
+ * @param from - array start index
262
+ * @param to - array end index
263
+ * @returns array's range
264
+ */
265
+ getArrayRange(array, from, to) {
266
+ return array.slice(from, to);
267
+ }
268
+ /**
269
+ * Get from and to index
270
+ * @returns [from,to] index
271
+ */
272
+ getFromToIndexes() {
273
+ const isFirstPage = this.currentSearchPage === 1;
274
+ const checkboxItemsFromIndex = isFirstPage ? 0 : (this.currentSearchPage - 1) * this.searchOffset;
275
+ const checkboxItemsToIndex = isFirstPage ? this.searchOffset : this.currentSearchPage * this.searchOffset;
276
+ return [checkboxItemsFromIndex, checkboxItemsToIndex];
277
+ }
192
278
  /*************
193
279
  * Lifecycle *
194
280
  *************/
@@ -199,12 +285,12 @@ const MgInputCheckbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
199
285
  componentWillLoad() {
200
286
  // Get locales
201
287
  this.messages = initLocales(this.element).messages;
202
- if (this.type === 'multi')
203
- this.element.dataset.mgPopoverGuard = this.getMgPopoverIdentifier();
204
288
  // Validate
289
+ this.validateType(this.type);
205
290
  this.validateValue(this.value);
206
291
  this.validateDisabled(this.disabled);
207
- this.validateType(this.type);
292
+ this.validateDisplaySelectedValues(this.displaySelectedValues);
293
+ this.setCurrentSearchPage();
208
294
  // Check validity when component is ready
209
295
  // return a promise to process action only in the FIRST render().
210
296
  // https://stenciljs.com/docs/component-lifecycle#componentwillload
@@ -212,30 +298,60 @@ const MgInputCheckbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
212
298
  this.checkValidity();
213
299
  }, 0);
214
300
  }
301
+ /**
302
+ * Render checkbox multi display values
303
+ * @param selectedValuesNb - selected values length
304
+ * @returns display selected values
305
+ */
306
+ renderCheckboxMultiDisplaySelectedValues(selectedValuesNb) {
307
+ if (this.displaySelectedValues) {
308
+ return (selectedValuesNb > 0 && (h("ul", { role: "list", class: "mg-input__input-checkbox-multi-values-container" }, this.checkboxItems
309
+ .filter(({ value }) => value)
310
+ .map(({ title }) => (h("li", { class: "mg-input__input-checkbox-multi-value", key: title }, title))))));
311
+ }
312
+ else {
313
+ return h("strong", null, this.messages.input.checkbox[selectedValuesNb > 1 ? 'selectedValues' : 'selectedValue'].replace('{nb}', selectedValuesNb));
314
+ }
315
+ }
316
+ /**
317
+ * Render paginated checkboxes
318
+ * @param checkboxes - checkboxes to render
319
+ * @returns paginated checkboxes
320
+ */
321
+ renderPaginatedCheckboxes(checkboxes) {
322
+ const [checkboxItemsFromIndex, checkboxItemsToIndex] = this.getFromToIndexes();
323
+ return [
324
+ this.renderCheckboxes(this.getArrayRange(checkboxes, checkboxItemsFromIndex, checkboxItemsToIndex)),
325
+ h("mg-pagination", { key: "search-pagination", totalPages: this.getPaginationTotalPages(checkboxes), currentPage: this.currentSearchPage, "onCurrent-page-change": this.handleCurrentPageChange, hideNavigationLabels: true, identifier: `${this.identifier}-pagination` }),
326
+ ];
327
+ }
215
328
  /**
216
329
  * render checkbox multi element
217
330
  * @returns html element
218
331
  */
219
332
  renderCheckboxMulti() {
220
333
  const selectedValuesNb = this.checkboxItems.filter(({ value }) => value).length;
221
- return (h("div", { class: "mg-input__input-container mg-input__input-checkbox-multi" }, h("strong", null, this.messages.input.checkbox[selectedValuesNb > 1 ? 'selectedValues' : 'selectedValue'].replace('{nb}', selectedValuesNb)), h("mg-popover", { arrowHide: true, identifier: this.getMgPopoverIdentifier(), ref: el => {
334
+ const checkboxes = this.getDisplayItems();
335
+ return (h("div", { class: { 'mg-input__input-container': true, 'mg-input__input-checkbox-multi': true, 'mg-input__input-checkbox-multi--with-values': this.displaySelectedValues } }, this.renderCheckboxMultiDisplaySelectedValues(selectedValuesNb), h("mg-popover", { arrowHide: true, identifier: this.getMgPopoverIdentifier(), "onDisplay-change": this.handleMgPopoverDisplayChange, ref: el => {
222
336
  if (Boolean(el))
223
- this.popover = el;
224
- } }, h("mg-button", { variant: "secondary" }, h("mg-icon", { icon: "list" }), this.renderButtonText(selectedValuesNb)), h("div", { slot: "content" }, this.renderCheckboxes()))));
337
+ this.mgPopover = el;
338
+ } }, h("mg-button", { variant: "secondary" }, h("mg-icon", { icon: "list" }), this.renderButtonText(selectedValuesNb)), h("div", { slot: "content" }, this.displaySearchInput && [
339
+ h("mg-input-text", { key: "input-search", identifier: `${this.identifier}-input-search`, icon: "magnifying-glass", type: "search", placeholder: this.messages.input.checkbox.label, label: this.messages.input.checkbox.label, mgWidth: "full", value: this.searchValue, labelHide: true, displayCharacterLeft: false, name: "q", "onValue-change": this.handleSearchChange, "aria-controls": "search-results items-list" }),
340
+ h("p", { key: "search-results", role: "status", class: "sr-only", id: "search-results" }, `${checkboxes.length} ${this.messages.input.checkbox[checkboxes.length > 0 ? 'results' : 'result']}`),
341
+ ], this.displaySearchInput && this.getPaginationTotalPages(checkboxes) > 1 ? this.renderPaginatedCheckboxes(checkboxes) : this.renderCheckboxes(checkboxes), this.displaySearchInput && checkboxes.length === 0 && h("p", { class: "mg-input__input-checkbox-multi-no-result" }, this.messages.input.checkbox.noResult)))));
225
342
  }
226
343
  /**
227
344
  * Render checkbox element
345
+ * @param checkboxes - checkboxes to render
228
346
  * @returns HTML Element
229
347
  */
230
- renderCheckboxes() {
348
+ renderCheckboxes(checkboxes) {
231
349
  return (h("ul", { class: {
232
350
  'mg-input__input-group-container': true,
233
351
  'mg-input__input-group-container--vertical': this.inputVerticalList || (this.type === 'multi' && !this.readonly),
234
352
  'mg-input__input-checkbox-multi-inputs': this.type === 'multi' && !this.readonly,
235
- }, role: "list" }, this.checkboxItems
236
- .filter(item => {
237
- return !this.readonly || item.value;
238
- })
353
+ }, role: "list", "aria-describedby": this.displaySearchInput ? 'search-results' : false, "aria-label": this.displaySearchInput ? this.messages.input.checkbox.searchResults : false, "aria-live": this.displaySearchInput ? 'polite' : false, id: "items-list", key: "checkboxes" }, checkboxes
354
+ .filter(item => !this.readonly || item.value)
239
355
  .map((input, index) => (h("li", { key: input.id, class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } }, h("input", { type: "checkbox", id: input.id, name: this.identifier, value: input.value && input.value.toString(), checked: Boolean(input.value), disabled: this.readonly || this.disabled || input.disabled, required: this.required, indeterminate: input.value === null, onInput: this.handleInput, onBlur: this.handleBlur, onKeyDown: this.handleKeydown, ref: el => {
240
356
  if (el !== null)
241
357
  this.inputs[index] = el;
@@ -246,20 +362,23 @@ const MgInputCheckbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
246
362
  * @returns HTML Element
247
363
  */
248
364
  render() {
249
- return (h(MgInput, { identifier: this.identifier, classCollection: this.classCollection, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: !this.readonly ? this.required : undefined, readonly: undefined, mgWidth: undefined, disabled: this.disabled, value: this.value && this.value.toString(), readonlyValue: undefined, tooltip: !this.readonly ? this.tooltip : undefined, helpText: !this.readonly ? this.helpText : undefined, errorMessage: !this.readonly ? this.errorMessage : undefined, isFieldset: true }, this.type === 'checkbox' || this.readonly ? this.renderCheckboxes() : this.renderCheckboxMulti()));
365
+ return (h(MgInput, { identifier: this.identifier, classCollection: this.classCollection, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: !this.readonly ? this.required : undefined, readonly: undefined, mgWidth: undefined, disabled: this.disabled, value: this.value && this.value.toString(), readonlyValue: undefined, tooltip: !this.readonly ? this.tooltip : undefined, helpText: !this.readonly ? this.helpText : undefined, errorMessage: !this.readonly ? this.errorMessage : undefined, isFieldset: true }, this.type === 'checkbox' || this.readonly ? this.renderCheckboxes(this.checkboxItems) : this.renderCheckboxMulti()));
250
366
  }
251
367
  get element() { return this; }
252
368
  static get watchers() { return {
253
369
  "value": ["validateValue"],
254
370
  "type": ["validateType"],
371
+ "displaySelectedValues": ["validateDisplaySelectedValues"],
255
372
  "required": ["handleValidityChange"],
256
373
  "readonly": ["handleValidityChange"],
257
- "disabled": ["handleValidityChange", "validateDisabled"]
374
+ "disabled": ["handleValidityChange", "validateDisabled"],
375
+ "checkboxItems": ["validateCheckboxItems"],
376
+ "searchValue": ["validateSearchValue"]
258
377
  }; }
259
378
  static get style() { return mgInputCheckboxCss; }
260
379
  }, [1, "mg-input-checkbox", {
261
380
  "value": [1040],
262
- "type": [1],
381
+ "type": [1025],
263
382
  "identifier": [1],
264
383
  "name": [1],
265
384
  "label": [1],
@@ -268,6 +387,7 @@ const MgInputCheckbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
268
387
  "inputVerticalList": [4, "input-vertical-list"],
269
388
  "required": [4],
270
389
  "readonly": [4],
390
+ "displaySelectedValues": [4, "display-selected-values"],
271
391
  "disabled": [4],
272
392
  "tooltip": [1],
273
393
  "helpText": [1, "help-text"],
@@ -276,13 +396,17 @@ const MgInputCheckbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
276
396
  "classCollection": [32],
277
397
  "errorMessage": [32],
278
398
  "checkboxItems": [32],
399
+ "displaySearchInput": [32],
400
+ "currentSearchPage": [32],
401
+ "searchValue": [32],
402
+ "searchResults": [32],
279
403
  "displayError": [64]
280
404
  }]);
281
405
  function defineCustomElement$1() {
282
406
  if (typeof customElements === "undefined") {
283
407
  return;
284
408
  }
285
- const components = ["mg-input-checkbox", "mg-button", "mg-card", "mg-icon", "mg-input-title", "mg-popover", "mg-tooltip"];
409
+ const components = ["mg-input-checkbox", "mg-button", "mg-card", "mg-character-left", "mg-icon", "mg-input-select", "mg-input-text", "mg-input-title", "mg-pagination", "mg-popover", "mg-tooltip"];
286
410
  components.forEach(tagName => { switch (tagName) {
287
411
  case "mg-input-checkbox":
288
412
  if (!customElements.get(tagName)) {
@@ -291,20 +415,40 @@ function defineCustomElement$1() {
291
415
  break;
292
416
  case "mg-button":
293
417
  if (!customElements.get(tagName)) {
294
- defineCustomElement$7();
418
+ defineCustomElement$b();
295
419
  }
296
420
  break;
297
421
  case "mg-card":
298
422
  if (!customElements.get(tagName)) {
299
- defineCustomElement$6();
423
+ defineCustomElement$a();
424
+ }
425
+ break;
426
+ case "mg-character-left":
427
+ if (!customElements.get(tagName)) {
428
+ defineCustomElement$9();
300
429
  }
301
430
  break;
302
431
  case "mg-icon":
303
432
  if (!customElements.get(tagName)) {
304
- defineCustomElement$5();
433
+ defineCustomElement$8();
434
+ }
435
+ break;
436
+ case "mg-input-select":
437
+ if (!customElements.get(tagName)) {
438
+ defineCustomElement$7();
439
+ }
440
+ break;
441
+ case "mg-input-text":
442
+ if (!customElements.get(tagName)) {
443
+ defineCustomElement$6();
305
444
  }
306
445
  break;
307
446
  case "mg-input-title":
447
+ if (!customElements.get(tagName)) {
448
+ defineCustomElement$5();
449
+ }
450
+ break;
451
+ case "mg-pagination":
308
452
  if (!customElements.get(tagName)) {
309
453
  defineCustomElement$4();
310
454
  }
@@ -1,173 +1,4 @@
1
- import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
2
- import { c as createID } from './components.utils.js';
3
- import { i as initLocales } from './index2.js';
4
- import { d as defineCustomElement$6 } from './mg-button2.js';
5
- import { d as defineCustomElement$5 } from './mg-icon2.js';
6
- import { d as defineCustomElement$4 } from './mg-input-select2.js';
7
- import { d as defineCustomElement$3 } from './mg-input-title2.js';
8
- import { d as defineCustomElement$2 } from './mg-tooltip2.js';
9
-
10
- var NavigationAction;
11
- (function (NavigationAction) {
12
- NavigationAction["NEXT"] = "next";
13
- NavigationAction["PREVIOUS"] = "previous";
14
- })(NavigationAction || (NavigationAction = {}));
15
-
16
- const mgPaginationCss = ".sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}@media (prefers-reduced-motion){.mg-a11y-animation{animation:none !important;transition:none !important}}.mg-pagination{display:flex;align-items:center;flex-direction:row}.mg-pagination mg-input-select{margin-right:0.5rem}.mg-pagination mg-button{display:flex}.mg-pagination mg-button:first-of-type{margin-right:1rem}.mg-pagination mg-button:last-of-type{margin-left:1rem}";
17
-
18
- /**
19
- * Range generator
20
- *
21
- * ```
22
- * start by get the range length, add "+ 1" to include last value, ex: Math.ceil((3 + 1 - 1) / 1) => 3
23
- * then with Array(Math.ceil...) we get the final array with empty values, ex: Array(Math.ceil(2 + 1 - 1) / 1)) => [empty, empty, empty]
24
- * then with Array(Math.ceil...).keys() we get the Array Iterator from empty values
25
- * then with Array.from(Array(...)) we get the complete array with "index" values instead of "empty" values
26
- * ex: Array.from(Array(Math.ceil((2 + 1 - 1) / 1) || 1).keys()) => [0, 1, 2]
27
- * finaly we map values from "start" range and apply the "step" coefficiant,
28
- * ex: Array.from(Array(Math.ceil((2 + 1 - 1) / 1) || 1).keys()).map(x => 1 + x * 1) => [1, 2, 3]
29
- * ```
30
- *
31
- * range(1, 1) = [1]
32
- * range(1, 5) = [1, 2, 3, 4, 5]
33
- * range(10, 20, 2) = [10, 12, 14, 16, 18, 20]
34
- * @param start - start range
35
- * @param end - start end
36
- * @param step - step size
37
- * @returns range numbers
38
- */
39
- const range = (start, end, step = 1) => Array.from(Array(Math.ceil((end + 1 - start) / step)).keys()).map(x => start + x * step);
40
- const MgPagination$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
41
- constructor() {
42
- super();
43
- this.__registerHost();
44
- this.__attachShadow();
45
- this.currentPageChange = createEvent(this, "current-page-change", 7);
46
- /**
47
- * Change current page from target
48
- * @param target - target page
49
- */
50
- this.goToPage = (target) => {
51
- this.currentPage = target;
52
- };
53
- /************
54
- * Handlers *
55
- ************/
56
- /**
57
- * select handler
58
- * @param event - value change event
59
- */
60
- this.handleSelect = (event) => {
61
- const to = Number(event.target.value);
62
- this.goToPage(to > 0 ? to : 1);
63
- };
64
- /**
65
- * Go to 'previous/next' page button handler
66
- * @param action - navigation action
67
- * @param disabled - button disable state
68
- */
69
- this.handleGoToPage = (action, disabled) => {
70
- !disabled && this.goToPage(action === NavigationAction.NEXT ? this.currentPage + 1 : this.currentPage - 1);
71
- };
72
- this.identifier = createID('mg-pagination');
73
- this.label = undefined;
74
- this.hideNavigationLabels = undefined;
75
- this.totalPages = 1;
76
- this.currentPage = 1;
77
- }
78
- validateTotalPages(newValue) {
79
- if (newValue < 1) {
80
- throw new Error('<mg-pagination> prop "totalPages" must be greater than 0');
81
- }
82
- }
83
- validateCurrentPage(newValue) {
84
- if (newValue < 1) {
85
- throw new Error('<mg-pagination> prop "currentPage" must be greater than 0');
86
- }
87
- else if (newValue > this.totalPages) {
88
- throw new Error('<mg-pagination> prop "currentPage" can not be greater than total page');
89
- }
90
- this.currentPageChange.emit(newValue);
91
- }
92
- /*************
93
- * Lifecycle *
94
- *************/
95
- /**
96
- * Check if props are well configured on init
97
- */
98
- componentWillLoad() {
99
- // Get locales
100
- this.messages = initLocales(this.element).messages;
101
- // Validate
102
- this.validateTotalPages(this.totalPages);
103
- this.validateCurrentPage(this.currentPage);
104
- // Set default label
105
- if (this.label === undefined || this.label === '') {
106
- this.label = this.messages.pagination.label;
107
- }
108
- }
109
- /**
110
- * Render
111
- * @returns HTML Element
112
- */
113
- render() {
114
- const navigationActionButton = (disabled, action) => (h("mg-button", { identifier: `${this.identifier}-button-${action}`, label: this.messages.pagination[`${action}Page`],
115
- // eslint-disable-next-line react/jsx-no-bind
116
- onClick: () => this.handleGoToPage(action, disabled), disabled: disabled, variant: "flat", isIcon: this.hideNavigationLabels }, action === NavigationAction.PREVIOUS && h("mg-icon", { icon: "chevron-left" }), !this.hideNavigationLabels && this.messages.general[action], action === NavigationAction.NEXT && h("mg-icon", { icon: "chevron-right" })));
117
- return (h("nav", { "aria-label": this.label, id: this.identifier, class: "mg-pagination" }, navigationActionButton(this.currentPage <= 1, NavigationAction.PREVIOUS), h("mg-input-select", { identifier: `${this.identifier}-select`, items: range(1, this.totalPages).map(page => page.toString()), label: this.messages.pagination.selectPage, "label-hide": true, "on-value-change": this.handleSelect, value: this.currentPage.toString(), "placeholder-hide": true }), h("span", { class: "sr-only" }, this.messages.pagination.page, " ", this.currentPage), h("span", null, "/ ", this.totalPages, " ", this.totalPages > 1 ? this.messages.pagination.pages : this.messages.pagination.page), navigationActionButton(this.currentPage >= this.totalPages, NavigationAction.NEXT)));
118
- }
119
- get element() { return this; }
120
- static get watchers() { return {
121
- "totalPages": ["validateTotalPages"],
122
- "currentPage": ["validateCurrentPage"]
123
- }; }
124
- static get style() { return mgPaginationCss; }
125
- }, [1, "mg-pagination", {
126
- "identifier": [1],
127
- "label": [1025],
128
- "hideNavigationLabels": [4, "hide-navigation-labels"],
129
- "totalPages": [2, "total-pages"],
130
- "currentPage": [1538, "current-page"]
131
- }]);
132
- function defineCustomElement$1() {
133
- if (typeof customElements === "undefined") {
134
- return;
135
- }
136
- const components = ["mg-pagination", "mg-button", "mg-icon", "mg-input-select", "mg-input-title", "mg-tooltip"];
137
- components.forEach(tagName => { switch (tagName) {
138
- case "mg-pagination":
139
- if (!customElements.get(tagName)) {
140
- customElements.define(tagName, MgPagination$1);
141
- }
142
- break;
143
- case "mg-button":
144
- if (!customElements.get(tagName)) {
145
- defineCustomElement$6();
146
- }
147
- break;
148
- case "mg-icon":
149
- if (!customElements.get(tagName)) {
150
- defineCustomElement$5();
151
- }
152
- break;
153
- case "mg-input-select":
154
- if (!customElements.get(tagName)) {
155
- defineCustomElement$4();
156
- }
157
- break;
158
- case "mg-input-title":
159
- if (!customElements.get(tagName)) {
160
- defineCustomElement$3();
161
- }
162
- break;
163
- case "mg-tooltip":
164
- if (!customElements.get(tagName)) {
165
- defineCustomElement$2();
166
- }
167
- break;
168
- } });
169
- }
170
- defineCustomElement$1();
1
+ import { M as MgPagination$1, d as defineCustomElement$1 } from './mg-pagination2.js';
171
2
 
172
3
  const MgPagination = MgPagination$1;
173
4
  const defineCustomElement = defineCustomElement$1;