@mgdis/mg-components 6.3.0 → 6.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/dist/cjs/{index-a5b2cd1b.js → index-1a5a1081.js} +331 -162
  2. package/dist/cjs/index-1a5a1081.js.map +1 -0
  3. package/dist/cjs/{index-cc11af95.js → index-ede3b3dc.js} +3 -3
  4. package/dist/cjs/{index-cc11af95.js.map → index-ede3b3dc.js.map} +1 -1
  5. package/dist/cjs/{index.es-ac7c22e3.js → index.es-a112f649.js} +40 -40
  6. package/dist/cjs/index.es-a112f649.js.map +1 -0
  7. package/dist/cjs/loader.cjs.js +2 -2
  8. package/dist/cjs/mg-action-more_36.cjs.entry.js +3411 -2633
  9. package/dist/cjs/mg-action-more_36.cjs.entry.js.map +1 -1
  10. package/dist/cjs/mg-alert.cjs.entry.js +15 -12
  11. package/dist/cjs/mg-alert.cjs.entry.js.map +1 -1
  12. package/dist/cjs/mg-components.cjs.js +3 -3
  13. package/dist/cjs/mg-components.cjs.js.map +1 -1
  14. package/dist/cjs/mg-loader.cjs.entry.js +5 -7
  15. package/dist/cjs/mg-loader.cjs.entry.js.map +1 -1
  16. package/dist/cjs/mg-progress.cjs.entry.js +26 -11
  17. package/dist/cjs/mg-progress.cjs.entry.js.map +1 -1
  18. package/dist/collection/collection-manifest.json +2 -2
  19. package/dist/collection/components/atoms/internals/mg-character-left/mg-character-left.js +10 -3
  20. package/dist/collection/components/atoms/internals/mg-character-left/mg-character-left.js.map +1 -1
  21. package/dist/collection/components/atoms/internals/mg-input-title/mg-input-title.js +15 -4
  22. package/dist/collection/components/atoms/internals/mg-input-title/mg-input-title.js.map +1 -1
  23. package/dist/collection/components/atoms/mg-badge/mg-badge.js +15 -4
  24. package/dist/collection/components/atoms/mg-badge/mg-badge.js.map +1 -1
  25. package/dist/collection/components/atoms/mg-button/mg-button.js +50 -11
  26. package/dist/collection/components/atoms/mg-button/mg-button.js.map +1 -1
  27. package/dist/collection/components/atoms/mg-card/mg-card.js +1 -1
  28. package/dist/collection/components/atoms/mg-divider/mg-divider.js +9 -1
  29. package/dist/collection/components/atoms/mg-divider/mg-divider.js.map +1 -1
  30. package/dist/collection/components/atoms/mg-icon/mg-icon.js +22 -6
  31. package/dist/collection/components/atoms/mg-icon/mg-icon.js.map +1 -1
  32. package/dist/collection/components/atoms/mg-tag/mg-tag.js +14 -4
  33. package/dist/collection/components/atoms/mg-tag/mg-tag.js.map +1 -1
  34. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip-content/mg-tooltip-content.js +3 -4
  35. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip-content/mg-tooltip-content.js.map +1 -1
  36. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.conf.js +1 -0
  37. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.conf.js.map +1 -1
  38. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +95 -43
  39. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js.map +1 -1
  40. package/dist/collection/components/molecules/inputs/mg-input/mg-input.js +50 -13
  41. package/dist/collection/components/molecules/inputs/mg-input/mg-input.js.map +1 -1
  42. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox-paginated/mg-input-checkbox-paginated.js +29 -11
  43. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox-paginated/mg-input-checkbox-paginated.js.map +1 -1
  44. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +106 -33
  45. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js.map +1 -1
  46. package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +99 -36
  47. package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js.map +1 -1
  48. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +130 -35
  49. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js.map +1 -1
  50. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +87 -25
  51. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js.map +1 -1
  52. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +86 -26
  53. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js.map +1 -1
  54. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +92 -30
  55. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js.map +1 -1
  56. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +108 -31
  57. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js.map +1 -1
  58. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +109 -29
  59. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js.map +1 -1
  60. package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +67 -21
  61. package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js.map +1 -1
  62. package/dist/collection/components/molecules/internals/mg-item-more/mg-item-more.js +16 -70
  63. package/dist/collection/components/molecules/internals/mg-item-more/mg-item-more.js.map +1 -1
  64. package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js +101 -89
  65. package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js.map +1 -1
  66. package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js +202 -157
  67. package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js.map +1 -1
  68. package/dist/collection/components/molecules/mg-action-more/mg-action-more.js +19 -8
  69. package/dist/collection/components/molecules/mg-action-more/mg-action-more.js.map +1 -1
  70. package/dist/collection/components/molecules/mg-alert/mg-alert.js +15 -6
  71. package/dist/collection/components/molecules/mg-alert/mg-alert.js.map +1 -1
  72. package/dist/collection/components/molecules/mg-details/mg-details.js +22 -5
  73. package/dist/collection/components/molecules/mg-details/mg-details.js.map +1 -1
  74. package/dist/collection/components/molecules/mg-form/mg-form.js +48 -16
  75. package/dist/collection/components/molecules/mg-form/mg-form.js.map +1 -1
  76. package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js +13 -3
  77. package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js.map +1 -1
  78. package/dist/collection/components/molecules/mg-loader/mg-loader.js +5 -5
  79. package/dist/collection/components/molecules/mg-loader/mg-loader.js.map +1 -1
  80. package/dist/collection/components/molecules/mg-message/mg-message.js +22 -6
  81. package/dist/collection/components/molecules/mg-message/mg-message.js.map +1 -1
  82. package/dist/collection/components/molecules/mg-modal/mg-modal.js +37 -9
  83. package/dist/collection/components/molecules/mg-modal/mg-modal.js.map +1 -1
  84. package/dist/collection/components/molecules/mg-pagination/mg-pagination.js +28 -9
  85. package/dist/collection/components/molecules/mg-pagination/mg-pagination.js.map +1 -1
  86. package/dist/collection/components/molecules/mg-panel/mg-panel.js +48 -13
  87. package/dist/collection/components/molecules/mg-panel/mg-panel.js.map +1 -1
  88. package/dist/collection/components/molecules/mg-popover/mg-popover-content/mg-popover-content.js +10 -2
  89. package/dist/collection/components/molecules/mg-popover/mg-popover-content/mg-popover-content.js.map +1 -1
  90. package/dist/collection/components/molecules/mg-popover/mg-popover.conf.js +2 -0
  91. package/dist/collection/components/molecules/mg-popover/mg-popover.conf.js.map +1 -0
  92. package/dist/collection/components/molecules/mg-popover/mg-popover.js +133 -52
  93. package/dist/collection/components/molecules/mg-popover/mg-popover.js.map +1 -1
  94. package/dist/collection/components/molecules/mg-progress/mg-progress.js +26 -1
  95. package/dist/collection/components/molecules/mg-progress/mg-progress.js.map +1 -1
  96. package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js +3 -2
  97. package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js.map +1 -1
  98. package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +28 -8
  99. package/dist/collection/components/molecules/mg-tabs/mg-tabs.js.map +1 -1
  100. package/dist/collection/utils/behaviors.utils.js +44 -107
  101. package/dist/collection/utils/behaviors.utils.js.map +1 -1
  102. package/dist/collection/utils/floating-ui.utils.js +33 -0
  103. package/dist/collection/utils/floating-ui.utils.js.map +1 -0
  104. package/dist/components/floating-ui.utils.js +2099 -0
  105. package/dist/components/floating-ui.utils.js.map +1 -0
  106. package/dist/components/index.es.js +37 -37
  107. package/dist/components/index.es.js.map +1 -1
  108. package/dist/components/index2.js +2 -2
  109. package/dist/components/mg-action-more.js +15 -12
  110. package/dist/components/mg-action-more.js.map +1 -1
  111. package/dist/components/mg-alert.js +13 -10
  112. package/dist/components/mg-alert.js.map +1 -1
  113. package/dist/components/mg-badge2.js +12 -9
  114. package/dist/components/mg-badge2.js.map +1 -1
  115. package/dist/components/mg-button2.js +36 -15
  116. package/dist/components/mg-button2.js.map +1 -1
  117. package/dist/components/mg-card2.js +2 -2
  118. package/dist/components/mg-card2.js.map +1 -1
  119. package/dist/components/mg-character-left2.js +8 -7
  120. package/dist/components/mg-character-left2.js.map +1 -1
  121. package/dist/components/mg-details.js +14 -5
  122. package/dist/components/mg-details.js.map +1 -1
  123. package/dist/components/mg-divider2.js +7 -1
  124. package/dist/components/mg-divider2.js.map +1 -1
  125. package/dist/components/mg-form.js +35 -21
  126. package/dist/components/mg-form.js.map +1 -1
  127. package/dist/components/mg-icon2.js +17 -11
  128. package/dist/components/mg-icon2.js.map +1 -1
  129. package/dist/components/mg-illustrated-message.js +12 -6
  130. package/dist/components/mg-illustrated-message.js.map +1 -1
  131. package/dist/components/mg-input-checkbox-paginated2.js +14 -10
  132. package/dist/components/mg-input-checkbox-paginated2.js.map +1 -1
  133. package/dist/components/mg-input-checkbox.js +69 -36
  134. package/dist/components/mg-input-checkbox.js.map +1 -1
  135. package/dist/components/mg-input-date.js +75 -44
  136. package/dist/components/mg-input-date.js.map +1 -1
  137. package/dist/components/mg-input-numeric.js +88 -43
  138. package/dist/components/mg-input-numeric.js.map +1 -1
  139. package/dist/components/mg-input-password.js +54 -26
  140. package/dist/components/mg-input-password.js.map +1 -1
  141. package/dist/components/mg-input-radio.js +58 -30
  142. package/dist/components/mg-input-radio.js.map +1 -1
  143. package/dist/components/mg-input-select2.js +58 -34
  144. package/dist/components/mg-input-select2.js.map +1 -1
  145. package/dist/components/mg-input-text2.js +67 -36
  146. package/dist/components/mg-input-text2.js.map +1 -1
  147. package/dist/components/mg-input-textarea.js +69 -33
  148. package/dist/components/mg-input-textarea.js.map +1 -1
  149. package/dist/components/mg-input-title2.js +10 -7
  150. package/dist/components/mg-input-title2.js.map +1 -1
  151. package/dist/components/mg-input-toggle.js +42 -24
  152. package/dist/components/mg-input-toggle.js.map +1 -1
  153. package/dist/components/mg-input2.js +35 -18
  154. package/dist/components/mg-input2.js.map +1 -1
  155. package/dist/components/mg-item-more2.js +146 -270
  156. package/dist/components/mg-item-more2.js.map +1 -1
  157. package/dist/components/mg-loader.js +3 -5
  158. package/dist/components/mg-loader.js.map +1 -1
  159. package/dist/components/mg-menu-item2.js +200 -148
  160. package/dist/components/mg-menu-item2.js.map +1 -1
  161. package/dist/components/mg-message2.js +22 -10
  162. package/dist/components/mg-message2.js.map +1 -1
  163. package/dist/components/mg-modal.js +33 -15
  164. package/dist/components/mg-modal.js.map +1 -1
  165. package/dist/components/mg-pagination2.js +21 -14
  166. package/dist/components/mg-pagination2.js.map +1 -1
  167. package/dist/components/mg-panel.js +37 -20
  168. package/dist/components/mg-panel.js.map +1 -1
  169. package/dist/components/mg-popover-content2.js +11 -5
  170. package/dist/components/mg-popover-content2.js.map +1 -1
  171. package/dist/components/mg-popover2.js +119 -52
  172. package/dist/components/mg-popover2.js.map +1 -1
  173. package/dist/components/mg-progress.js +25 -10
  174. package/dist/components/mg-progress.js.map +1 -1
  175. package/dist/components/mg-skip-links.js +0 -1
  176. package/dist/components/mg-skip-links.js.map +1 -1
  177. package/dist/components/mg-tabs.js +26 -16
  178. package/dist/components/mg-tabs.js.map +1 -1
  179. package/dist/components/mg-tag.js +11 -7
  180. package/dist/components/mg-tag.js.map +1 -1
  181. package/dist/components/mg-tooltip-content2.js +2 -3
  182. package/dist/components/mg-tooltip-content2.js.map +1 -1
  183. package/dist/components/mg-tooltip2.js +86 -45
  184. package/dist/components/mg-tooltip2.js.map +1 -1
  185. package/dist/esm/{index-eb0e1053.js → index-5059254f.js} +331 -162
  186. package/dist/esm/index-5059254f.js.map +1 -0
  187. package/dist/esm/{index-f3d3fb70.js → index-a7c3b5c5.js} +3 -3
  188. package/dist/esm/{index-f3d3fb70.js.map → index-a7c3b5c5.js.map} +1 -1
  189. package/dist/esm/{index.es-940821a9.js → index.es-5e0101ac.js} +38 -38
  190. package/dist/esm/index.es-5e0101ac.js.map +1 -0
  191. package/dist/esm/loader.js +3 -3
  192. package/dist/esm/mg-action-more_36.entry.js +3411 -2633
  193. package/dist/esm/mg-action-more_36.entry.js.map +1 -1
  194. package/dist/esm/mg-alert.entry.js +15 -12
  195. package/dist/esm/mg-alert.entry.js.map +1 -1
  196. package/dist/esm/mg-components.js +4 -4
  197. package/dist/esm/mg-components.js.map +1 -1
  198. package/dist/esm/mg-loader.entry.js +5 -7
  199. package/dist/esm/mg-loader.entry.js.map +1 -1
  200. package/dist/esm/mg-progress.entry.js +26 -11
  201. package/dist/esm/mg-progress.entry.js.map +1 -1
  202. package/dist/mg-components/mg-components.esm.js +1 -1
  203. package/dist/mg-components/mg-components.esm.js.map +1 -1
  204. package/dist/mg-components/p-1a162791.entry.js +2 -0
  205. package/dist/mg-components/{p-d0086664.entry.js.map → p-1a162791.entry.js.map} +1 -1
  206. package/dist/mg-components/p-2403e01d.entry.js +2 -0
  207. package/dist/mg-components/p-2403e01d.entry.js.map +1 -0
  208. package/dist/mg-components/p-6c831a83.entry.js +2 -0
  209. package/dist/mg-components/p-6c831a83.entry.js.map +1 -0
  210. package/dist/mg-components/p-ad64ab4a.entry.js +2 -0
  211. package/dist/mg-components/p-ad64ab4a.entry.js.map +1 -0
  212. package/dist/mg-components/{p-ee51ec5e.js → p-b6c1a6ce.js} +2 -2
  213. package/dist/mg-components/p-b6c1a6ce.js.map +1 -0
  214. package/dist/mg-components/{p-a49e2b74.js → p-d9731ebc.js} +2 -2
  215. package/dist/mg-components/p-e39791fa.js +3 -0
  216. package/dist/mg-components/p-e39791fa.js.map +1 -0
  217. package/dist/types/components/atoms/mg-tooltip/mg-tooltip.conf.d.ts +6 -0
  218. package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +7 -6
  219. package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +6 -0
  220. package/dist/types/components/molecules/internals/mg-item-more/mg-item-more.d.ts +1 -15
  221. package/dist/types/components/molecules/menu/mg-menu/mg-menu.d.ts +14 -30
  222. package/dist/types/components/molecules/menu/mg-menu-item/mg-menu-item.d.ts +54 -39
  223. package/dist/types/components/molecules/mg-details/mg-details.d.ts +4 -0
  224. package/dist/types/components/molecules/mg-popover/mg-popover.conf.d.ts +6 -0
  225. package/dist/types/components/molecules/mg-popover/mg-popover.d.ts +13 -8
  226. package/dist/types/components.d.ts +8 -11
  227. package/dist/types/utils/behaviors.utils.d.ts +15 -44
  228. package/dist/types/utils/floating-ui.utils.d.ts +19 -0
  229. package/ide/intellij/web-types.json +3 -7
  230. package/ide/vscode/html-custom-data.json +2 -2
  231. package/package.json +24 -24
  232. package/dist/cjs/index-a5b2cd1b.js.map +0 -1
  233. package/dist/cjs/index.es-ac7c22e3.js.map +0 -1
  234. package/dist/components/popper.js +0 -1794
  235. package/dist/components/popper.js.map +0 -1
  236. package/dist/esm/index-eb0e1053.js.map +0 -1
  237. package/dist/esm/index.es-940821a9.js.map +0 -1
  238. package/dist/mg-components/p-15b6849a.js +0 -3
  239. package/dist/mg-components/p-15b6849a.js.map +0 -1
  240. package/dist/mg-components/p-3aecf564.entry.js +0 -2
  241. package/dist/mg-components/p-3aecf564.entry.js.map +0 -1
  242. package/dist/mg-components/p-6f3d70b2.entry.js +0 -2
  243. package/dist/mg-components/p-6f3d70b2.entry.js.map +0 -1
  244. package/dist/mg-components/p-a17ea0af.entry.js +0 -2
  245. package/dist/mg-components/p-a17ea0af.entry.js.map +0 -1
  246. package/dist/mg-components/p-d0086664.entry.js +0 -2
  247. package/dist/mg-components/p-ee51ec5e.js.map +0 -1
  248. /package/dist/mg-components/{p-a49e2b74.js.map → p-d9731ebc.js.map} +0 -0
@@ -1,5 +1,5 @@
1
1
  import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
2
- import { m as me, H as He, z as ze, f as ft, c as ct, X as Xe, Y as Ye } from './index.es.js';
2
+ import { K as Ke, m as me, q as qe, W as We, u as ut, f as ft, V as Ve } from './index.es.js';
3
3
  import { d as defineCustomElement$5, b as classReadonly, e as classDisabled } from './mg-input2.js';
4
4
  import { i as initLocales } from './index2.js';
5
5
  import { d as defineCustomElement$6 } from './mg-icon2.js';
@@ -19,12 +19,46 @@ const MgInputDate$1 = /*@__PURE__*/ proxyCustomElement(class MgInputDate extends
19
19
  this.inputValid = createEvent(this, "input-valid", 7);
20
20
  // hasDisplayedError (triggered by blur event)
21
21
  this.hasDisplayedError = false;
22
+ /**
23
+ * Input name
24
+ * If not set the value equals the identifier
25
+ */
26
+ this.name = this.identifier;
27
+ /**
28
+ * Define if label is visible
29
+ */
30
+ this.labelHide = false;
31
+ /**
32
+ * Define if input is required
33
+ */
34
+ this.required = false;
35
+ /**
36
+ * Define if input is readonly
37
+ */
38
+ this.readonly = false;
39
+ /**
40
+ * Define input maximum date
41
+ * format: yyyy-mm-dd
42
+ */
43
+ this.max = '9999-12-31';
44
+ /**
45
+ * Define if input is disabled
46
+ */
47
+ this.disabled = false;
48
+ /**
49
+ * Define tooltip position
50
+ */
51
+ this.tooltipPosition = 'input';
52
+ /**
53
+ * Component classes
54
+ */
55
+ this.classCollection = new Ke(['mg-c-input--date']);
22
56
  /**
23
57
  * Method to validate date pattern string
24
58
  * @param value - value to test
25
59
  * @returns truthy when value match the pattern
26
60
  */
27
- this.isValidPattern = (value) => me(value) && He.test(value);
61
+ this.isValidPattern = (value) => me(value) && qe.test(value);
28
62
  /**
29
63
  * Format help text to display
30
64
  * @param helpText - help text format
@@ -35,7 +69,7 @@ const MgInputDate$1 = /*@__PURE__*/ proxyCustomElement(class MgInputDate extends
35
69
  let text = me(helpText) ? helpText : this.messages.input.date.helpText;
36
70
  if (text.includes(defaultHelpTextVariable))
37
71
  text = text.replace(defaultHelpTextVariable, this.formatHelpText(this.messages.input.date.helpText));
38
- return text.replace('{pattern}', this.renderPattern()).replace('{date}', ze(ft(new Date('2023-12-24')), this.systemLocale));
72
+ return text.replace('{pattern}', this.renderPattern()).replace('{date}', We(ut(new Date('2023-12-24')), this.systemLocale));
39
73
  };
40
74
  /**
41
75
  * Handle input event
@@ -66,7 +100,7 @@ const MgInputDate$1 = /*@__PURE__*/ proxyCustomElement(class MgInputDate extends
66
100
  // when we reset the field we need to test a blank value.
67
101
  if (['Delete', 'Backspace'].includes(event.key)) {
68
102
  event.preventDefault();
69
- this.value = '';
103
+ this.value = null;
70
104
  this.checkValidity();
71
105
  if (this.hasDisplayedError) {
72
106
  this.setErrorMessage();
@@ -77,7 +111,7 @@ const MgInputDate$1 = /*@__PURE__*/ proxyCustomElement(class MgInputDate extends
77
111
  * Check if input is valid
78
112
  */
79
113
  this.checkValidity = () => {
80
- this.setValidity(this.readonly || this.disabled || (this.input.checkValidity() && (['', undefined].includes(this.value) || this.isValidPattern(this.value))));
114
+ this.setValidity(this.readonly || this.disabled || (this.input.checkValidity() && (this.value === null || this.isValidPattern(this.value))));
81
115
  };
82
116
  /**
83
117
  * get input error code
@@ -86,14 +120,14 @@ const MgInputDate$1 = /*@__PURE__*/ proxyCustomElement(class MgInputDate extends
86
120
  this.getInputError = () => {
87
121
  var _a;
88
122
  let inputError = null;
123
+ // bad input or pattern
124
+ if (this.input.validity.badInput || (this.value && !this.isValidPattern(this.value))) {
125
+ inputError = 'badInput';
126
+ }
89
127
  // required
90
- if (this.input.validity.valueMissing) {
128
+ else if (this.input.validity.valueMissing) {
91
129
  inputError = 'required';
92
130
  }
93
- // pattern
94
- else if (this.value && !this.isValidPattern(this.value)) {
95
- inputError = 'badInput';
96
- }
97
131
  // min & max
98
132
  else if ((this.input.validity.rangeUnderflow || this.input.validity.rangeOverflow) && ((_a = this.min) === null || _a === void 0 ? void 0 : _a.length) > 0 && this.max !== '9999-12-31') {
99
133
  inputError = 'minMax';
@@ -127,8 +161,8 @@ const MgInputDate$1 = /*@__PURE__*/ proxyCustomElement(class MgInputDate extends
127
161
  // min, max & minMax
128
162
  else if (['min', 'max', 'minMax'].includes(inputError)) {
129
163
  this.errorMessage = this.messages.errors.date[inputError]
130
- .replace('{min}', ze(this.min, this.systemLocale))
131
- .replace('{max}', ze(this.max, this.systemLocale));
164
+ .replace('{min}', We(this.min, this.systemLocale))
165
+ .replace('{max}', We(this.max, this.systemLocale));
132
166
  }
133
167
  // wrong date format
134
168
  // element.validity.badInput is default error message
@@ -142,40 +176,26 @@ const MgInputDate$1 = /*@__PURE__*/ proxyCustomElement(class MgInputDate extends
142
176
  * @returns translated html pattern
143
177
  */
144
178
  this.renderPattern = () => {
145
- let patternLocal = ct(this.systemLocale);
179
+ let patternLocal = ft(this.systemLocale);
146
180
  for (const key in this.messages.input.date.pattern) {
147
181
  patternLocal = patternLocal.replace(key, this.messages.input.date.pattern[key]);
148
182
  }
149
183
  return `<span aria-hidden="true">${patternLocal}</span><span class="mg-u-visually-hidden">${[...patternLocal].join(' ')}</span>`;
150
184
  };
151
- this.value = undefined;
152
- this.identifier = undefined;
153
- this.name = this.identifier;
154
- this.label = undefined;
155
- this.labelOnTop = undefined;
156
- this.labelHide = false;
157
- this.required = false;
158
- this.readonly = false;
159
- this.min = undefined;
160
- this.max = '9999-12-31';
161
- this.disabled = false;
162
- this.tooltip = undefined;
163
- this.tooltipPosition = 'input';
164
- this.helpText = undefined;
165
- this.valid = undefined;
166
- this.invalid = undefined;
167
- this.classCollection = new Xe(['mg-c-input--date']);
168
- this.errorMessage = undefined;
169
185
  }
170
186
  validateValue(newValue) {
171
187
  // When the input is not fully completed or has been cleared, the value becomes an empty string.
172
- if (newValue === '')
173
- newValue = null;
174
- // check value validity
175
- if (newValue && !me(newValue)) {
176
- throw new Error(`<mg-input-date> props 'value' must be a valid string. Passed value: ${Ye(newValue)}.`);
188
+ if (['', undefined].includes(newValue)) {
189
+ // need to force value update to `null` to prevent extra render
190
+ // - `''` is not a valide value
191
+ // - `undefined` is not allowed in CustomEvent['detail']
192
+ this.value = null;
177
193
  }
178
- else if ([null, undefined].includes(newValue) || this.isValidPattern(newValue)) {
194
+ else if (newValue && !me(newValue)) {
195
+ // check value validity
196
+ throw new Error(`<mg-input-date> props 'value' must be a valid string. Passed value: ${Ve(newValue)}.`);
197
+ }
198
+ else if (newValue === null || this.isValidPattern(newValue)) {
179
199
  this.valueChange.emit(newValue);
180
200
  }
181
201
  else {
@@ -190,7 +210,7 @@ const MgInputDate$1 = /*@__PURE__*/ proxyCustomElement(class MgInputDate extends
190
210
  }
191
211
  validateMinMax(newValue) {
192
212
  if (newValue && !this.isValidPattern(newValue)) {
193
- throw new Error(`<mg-input-date> props 'min/max' doesn't match pattern: 'yyyy-mm-dd'. Passed value: ${Ye(newValue)}.`);
213
+ throw new Error(`<mg-input-date> props 'min/max' doesn't match pattern: 'yyyy-mm-dd'. Passed value: ${Ve(newValue)}.`);
194
214
  }
195
215
  }
196
216
  handleValidityChange(newValue, _oldValue, prop) {
@@ -212,10 +232,21 @@ const MgInputDate$1 = /*@__PURE__*/ proxyCustomElement(class MgInputDate extends
212
232
  /**
213
233
  * Display input error if it exists.
214
234
  */
215
- async displayError() {
216
- this.checkValidity();
217
- this.setErrorMessage();
218
- this.hasDisplayedError = this.invalid;
235
+ displayError() {
236
+ // Use `Promise` as requested for stencil method
237
+ // Use `requestAnimationFrame` to ensure:
238
+ // - DOM is fully updated before validation
239
+ // - Async operations are completed
240
+ // - No timing issues with Stencil's render cycle
241
+ // - Keep everything in sync both inside and outside the component
242
+ return new Promise(resolve => {
243
+ requestAnimationFrame(() => {
244
+ this.checkValidity();
245
+ this.setErrorMessage();
246
+ this.hasDisplayedError = this.invalid;
247
+ resolve();
248
+ });
249
+ });
219
250
  }
220
251
  /**
221
252
  * Set an error and display a custom error message.
@@ -243,7 +274,7 @@ const MgInputDate$1 = /*@__PURE__*/ proxyCustomElement(class MgInputDate extends
243
274
  */
244
275
  async reset() {
245
276
  if (!this.readonly) {
246
- this.value = '';
277
+ this.value = null;
247
278
  this.checkValidity();
248
279
  this.invalid = false;
249
280
  this.errorMessage = undefined;
@@ -295,7 +326,7 @@ const MgInputDate$1 = /*@__PURE__*/ proxyCustomElement(class MgInputDate extends
295
326
  * @returns HTML Element
296
327
  */
297
328
  render() {
298
- return (h("mg-input", { key: '33ffeaf0b7b07cc65081891709a73a44c9454092', label: this.label, identifier: this.identifier, class: this.classCollection.join(), ariaDescribedbyIDs: [], labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, tooltip: this.tooltip, tooltipPosition: this.readonly && ['', undefined].includes(this.value) ? 'label' : this.tooltipPosition, helpText: this.formatHelpText(this.helpText), errorMessage: this.errorMessage }, this.readonly ? (this.value && h("b", { class: "mg-c-input__readonly-value" }, ze(this.value, this.locale))) : (h("input", { type: "date", class: "mg-c-input__box", min: this.min, max: this.max, value: this.value, id: this.identifier, name: this.name, disabled: this.disabled, required: this.required, "aria-invalid": (this.invalid === true).toString(), onInput: this.handleInput, onBlur: this.handleBlur, onKeyDown: this.handleKeyDown, ref: (el) => {
329
+ return (h("mg-input", { key: '09d07883b178cd1196c2be110c8fcfdde8fef01d', label: this.label, identifier: this.identifier, class: this.classCollection.join(), ariaDescribedbyIDs: [], labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, tooltip: this.tooltip, tooltipPosition: this.readonly && this.value === null ? 'label' : this.tooltipPosition, helpText: this.formatHelpText(this.helpText), errorMessage: this.errorMessage }, this.readonly ? (this.value && h("b", { class: "mg-c-input__readonly-value" }, We(this.value, this.locale))) : (h("input", { type: "date", class: "mg-c-input__box", min: this.min, max: this.max, value: this.value, id: this.identifier, name: this.name, disabled: this.disabled, required: this.required, "aria-invalid": (this.invalid === true).toString(), onInput: this.handleInput, onBlur: this.handleBlur, onKeyDown: this.handleKeyDown, ref: (el) => {
299
330
  if (el !== null)
300
331
  this.input = el;
301
332
  } }))));
@@ -1 +1 @@
1
- {"file":"mg-input-date.js","mappings":";;;;;;;;;AAAA,MAAM,cAAc,GAAG,ymFAAymF,CAAC;AACjoF,0BAAe,cAAc;;MCUhBA,aAAW;;;;;;;;QAcd,sBAAiB,GAAG,KAAK,CAAC;;;;;;QAyN1B,mBAAc,GAAG,CAAC,KAAa,KAAcC,EAAa,CAAC,KAAK,CAAC,IAAIC,EAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;;;;;;QAO5F,mBAAc,GAAG,CAAC,QAAgB;YACxC,MAAM,uBAAuB,GAAG,mBAAmB,CAAC;YACpD,IAAI,IAAI,GAAGD,EAAa,CAAC,QAAQ,CAAC,GAAG,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;YAClF,IAAI,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAAC;gBAAE,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YAEjJ,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAEE,EAAU,CAACC,EAAY,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;SAC/I,CAAC;;;;QAiBM,gBAAW,GAAG;YACpB,IAAI,CAAC,aAAa,EAAE,CAAC;YACrB,IAAI,IAAI,CAAC,i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Q,IACZ,IAAI,CAAC,KAAK,IAAI,SAAG,KAAK,EAAC,4BAA4B,IAAEE,EAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAK,KAE7F,aACE,IAAI,EAAC,MAAM,EACX,KAAK,EAAC,iBAAiB,EACvB,GAAG,EAAE,IAAI,CAAC,GAAG,EACb,GAAG,EAAE,IAAI,CAAC,GAAG,EACb,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,EAAE,EAAE,IAAI,CAAC,UAAU,EACnB,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ,kBACT,CAAC,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE,QAAQ,EAAE,EAChD,OAAO,EAAE,IAAI,CAAC,WAAW,EACzB,MAAM,EAAE,IAAI,CAAC,UAAU,EACvB,SAAS,EAAE,IAAI,CAAC,aAAa,EAC7B,GAAG,EAAE,CAAC,EAAoB;gBACxB,IAAI,EAAE,KAAK,IAAI;oBAAE,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;aAClC,GACD,CACH,CACQ,EACX;KACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["MgInputDate","isValidString","dateRegExp","localeDate","dateToString","getLocaleDatePattern","ClassList","toString"],"sources":["../styles/dist/components/mg-input-date.css?tag=mg-input-date&encapsulation=shadow","src/components/molecules/inputs/mg-input-date/mg-input-date.tsx"],"sourcesContent":[".mg-c-input__readonly-value{min-height:var(--mg-b-font-size);align-self:flex-start;margin-top:calc((var(--mg-b-size-min-height) - var(--mg-b-font-size)*var(--mg-b-line-height))/2);word-break:break-word}.mg-c-input__box{height:var(--mg-b-size-min-height);box-sizing:border-box;padding:calc((var(--mg-b-size-min-height) - var(--mg-b-font-size)*var(--mg-b-line-height))/2) var(--mg-b-size-8);border-width:var(--mg-c-input-border-width);border-style:solid;border-color:var(--mg-c-input-color-border);border-radius:var(--mg-c-input-border-radius);background-color:var(--mg-b-color-light);color:var(--mg-b-color-dark);font-family:inherit;font-size:var(--mg-b-font-size);text-align:var(--mg-c-input-text-align, left)}.mg-c-input__box::placeholder{color:var(--mg-c-input-placeholder-color-text);font-style:italic}.mg-c-input__box:focus{box-shadow:0 0 var(--mg-b-size-4) var(--mg-c-input-color-box-shadow-focus)}.mg-c-input__box:disabled{opacity:var(--mg-b-opacity-element-disabled)}.mg-c-input.mg-c-input--has-error .mg-c-input__box{border-color:var(--mg-b-color-danger)}.mg-c-input.mg-c-input--is-input-group-append{--mg-c-button-border-radius-top-left: 0;--mg-c-button-border-radius-bottom-left: 0}.mg-c-input.mg-c-input--is-input-group-append .mg-c-input__box{margin-right:calc(-1*var(--mg-b-size-border));border-bottom-right-radius:0;border-top-right-radius:0}.mg-c-input.mg-c-input--is-input-group-append .mg-c-input__box:focus-visible{outline-offset:-0.2rem;outline-style:solid;outline-width:.2rem}.mg-c-input.mg-c-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-c-button-border-radius-top-right: 0;--mg-c-button-border-radius-bottom-right: 0}.mg-c-input.mg-c-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-c-button-border-right-width: 0}.mg-c-input.mg-c-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-c-button-border-radius-top-right: var(--mg-c-input-border-radius);--mg-c-button-border-radius-bottom-right: var(--mg-c-input-border-radius)}.mg-c-input.mg-c-input--is-append-input-slot-content:not(.mg-c-input--readonly) ::slotted([slot=append-input]){align-self:start;padding-top:calc((var(--mg-b-size-min-height) - var(--mg-b-size-16))/2)}.mg-u-visually-hidden{position:absolute !important;overflow:hidden !important;width:.1rem !important;height:.1rem !important;padding:0 !important;border:0 !important;margin:-0.1rem !important;clip:rect(0.1rem, 0.1rem, 0.1rem, 0.1rem) !important;clip-path:inset(50%) !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}@media(prefers-reduced-motion){*{animation:none !important;transition:none !important}}/*# sourceMappingURL=mg-input-date.css.map */\n","import { Component, Element, Event, EventEmitter, h, Prop, State, Watch, Method } from '@stencil/core';\nimport { ClassList, isValidString, localeDate, dateRegExp, dateToString, getLocaleDatePattern, toString } from '@mgdis/stencil-helpers';\nimport { type InputDateError } from './mg-input-date.conf';\nimport { type EventType, classReadonly, type TooltipPosition, classDisabled } from '../mg-input/mg-input.conf';\nimport { initLocales } from '../../../../locales';\n\n@Component({\n tag: 'mg-input-date',\n styleUrl: '../../../../../node_modules/@mgdis/styles/dist/components/mg-input-date.css',\n shadow: true,\n})\nexport class MgInputDate {\n /************\n * Internal *\n ************/\n\n // HTML selector\n private input: HTMLInputElement;\n\n // Locales\n private messages;\n private locale: string;\n private systemLocale: string;\n\n // hasDisplayedError (triggered by blur event)\n private hasDisplayedError = false;\n private handlerInProgress: EventType;\n\n /**************\n * Decorators *\n **************/\n\n /**\n * Get component DOM element\n */\n @Element() element: HTMLMgInputDateElement;\n\n /**\n * Component value\n */\n @Prop({ mutable: true, reflect: true }) value: string;\n @Watch('value')\n validateValue(newValue: MgInputDate['value']): void {\n // When the input is not fully completed or has been cleared, the value becomes an empty string.\n if (newValue === '') newValue = null;\n\n // check value validity\n if (newValue && !isValidString(newValue)) {\n throw new Error(`<mg-input-date> props 'value' must be a valid string. Passed value: ${toString(newValue)}.`);\n } else if ([null, undefined].includes(newValue) || this.isValidPattern(newValue)) {\n this.valueChange.emit(newValue);\n } else {\n console.error(\"<mg-input-date> props 'value' doesn't match pattern: 'yyyy-mm-dd'.\");\n }\n }\n\n /**\n * Identifier is used for the element ID (id is a reserved prop in Stencil.js)\n */\n @Prop() identifier!: string;\n\n /**\n * Input name\n * If not set the value equals the identifier\n */\n @Prop() name: string = this.identifier;\n\n /**\n * Input label\n */\n @Prop() label!: string;\n\n /**\n * Define if label is displayed on top\n */\n @Prop() labelOnTop?: boolean;\n\n /**\n * Define if label is visible\n */\n @Prop() labelHide = false;\n\n /**\n * Define if input is required\n */\n @Prop() required = false;\n\n /**\n * Define if input is readonly\n */\n @Prop() readonly = false;\n @Watch('readonly')\n watchReadonly(newValue: MgInputDate['readonly']): void {\n if (newValue) this.classCollection.add(classReadonly);\n else this.classCollection.delete(classReadonly);\n }\n\n /**\n * Define input minimum date\n * format: yyyy-mm-dd\n */\n @Prop() min?: string;\n\n /**\n * Define input maximum date\n * format: yyyy-mm-dd\n */\n @Prop() max?: string = '9999-12-31';\n @Watch('min')\n @Watch('max')\n validateMinMax(newValue: string): void {\n if (newValue && !this.isValidPattern(newValue)) {\n throw new Error(`<mg-input-date> props 'min/max' doesn't match pattern: 'yyyy-mm-dd'. Passed value: ${toString(newValue)}.`);\n }\n }\n\n /**\n * Define if input is disabled\n */\n @Prop() disabled = false;\n @Watch('required')\n @Watch('readonly')\n @Watch('disabled')\n @Watch('min')\n @Watch('max')\n handleValidityChange(newValue: boolean, _oldValue: boolean, prop: string): void {\n if (this.input !== undefined) {\n this.input[prop] = newValue;\n this.checkValidity();\n if (this.hasDisplayedError) {\n this.setErrorMessage();\n this.hasDisplayedError = false;\n }\n }\n }\n\n @Watch('disabled')\n watchDisabled(newValue: MgInputDate['disabled']): void {\n if (newValue) this.classCollection.add(classDisabled);\n else this.classCollection.delete(classDisabled);\n }\n\n /**\n * Add a tooltip message next to the input\n */\n @Prop() tooltip?: string;\n\n /**\n * Define tooltip position\n */\n @Prop() tooltipPosition: TooltipPosition = 'input';\n\n /**\n * Add a help text under the input, usually expected data format and example\n * Available string variables:\n * - `{pattern}`: render innerHTML pattern based on system\n * - `{date}`: render innerText date with a pattern base format.\n * - `{defaultHelpText}`: render default `helpText` usefull to concat helpText local with your custom text.\n * ex: `Input use {pattern} pattern` as `helpText` prop value will be render as `Input use mm/dd/yyyy pattern`\n */\n @Prop() helpText?: string;\n\n /**\n * Define input valid state\n */\n @Prop({ mutable: true }) valid: boolean;\n\n /**\n * Define input invalid state\n */\n @Prop({ mutable: true }) invalid: boolean;\n\n /**\n * Component classes\n */\n @State() classCollection: ClassList = new ClassList(['mg-c-input--date']);\n\n /**\n * Error message to display\n */\n @State() errorMessage: string;\n\n /**\n * Emited event when value change\n */\n @Event({ eventName: 'value-change' }) valueChange: EventEmitter<HTMLMgInputDateElement['value']>;\n\n /**\n * Emited event when checking validity\n */\n @Event({ eventName: 'input-valid' }) inputValid: EventEmitter<HTMLMgInputDateElement['valid']>;\n\n /**\n * Display input error if it exists.\n */\n @Method()\n async displayError(): Promise<void> {\n this.checkValidity();\n this.setErrorMessage();\n this.hasDisplayedError = this.invalid;\n }\n\n /**\n * Set an error and display a custom error message.\n * This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.\n * It must be paired with an error message to display for the given context.\n * When used to set validity to `false`, you should use this method again to reset the validity to `true`.\n * @param valid - value indicating the validity\n * @param errorMessage - the error message to display\n */\n @Method()\n async setError(valid: MgInputDate['valid'], errorMessage: string): Promise<void> {\n if (typeof valid !== 'boolean') {\n throw new Error('<mg-input-date> method \"setError()\" param \"valid\" must be a boolean.');\n } else if (!isValidString(errorMessage)) {\n throw new Error('<mg-input-date> method \"setError()\" param \"errorMessage\" must be a string.');\n } else {\n this.setValidity(valid);\n this.setErrorMessage(valid ? undefined : errorMessage);\n this.hasDisplayedError = this.invalid;\n }\n }\n\n /**\n * Reset value, validity and error state\n */\n @Method()\n async reset(): Promise<void> {\n if (!this.readonly) {\n this.value = '';\n this.checkValidity();\n this.invalid = false;\n this.errorMessage = undefined;\n this.hasDisplayedError = false;\n }\n }\n\n /**\n * Method to validate date pattern string\n * @param value - value to test\n * @returns truthy when value match the pattern\n */\n private isValidPattern = (value: string): boolean => isValidString(value) && dateRegExp.test(value);\n\n /**\n * Format help text to display\n * @param helpText - help text format\n * @returns formated pattern help text. Ex: Format attendu : jj/mm/aaaa (ex : 20/12/2020)\n */\n private formatHelpText = (helpText: string): string => {\n const defaultHelpTextVariable = '{defaultHelpText}';\n let text = isValidString(helpText) ? helpText : this.messages.input.date.helpText;\n if (text.includes(defaultHelpTextVariable)) text = text.replace(defaultHelpTextVariable, this.formatHelpText(this.messages.input.date.helpText));\n\n return text.replace('{pattern}', this.renderPattern()).replace('{date}', localeDate(dateToString(new Date('2023-12-24')), this.systemLocale));\n };\n\n /**\n * Method to set validity values\n * @param newValue - valid new value\n */\n private setValidity(newValue: MgInputDate['valid']) {\n const oldValidValue = this.valid;\n this.valid = newValue;\n this.invalid = !this.valid;\n // We need to send valid event even if it is the same value\n if (this.handlerInProgress === undefined || (this.handlerInProgress === 'blur' && this.valid !== oldValidValue)) this.inputValid.emit(this.valid);\n }\n\n /**\n * Handle input event\n */\n private handleInput = (): void => {\n this.checkValidity();\n if (this.hasDisplayedError) {\n this.setErrorMessage();\n }\n this.value = this.input.value;\n };\n\n /**\n * Handle blur event\n */\n private handleBlur = (): void => {\n this.handlerInProgress = 'blur';\n this.displayError().finally(() => {\n // reset guard\n this.handlerInProgress = undefined;\n });\n };\n\n /**\n * Handle keydown event\n * @param event - input keydown event\n */\n private handleKeyDown = (event: KeyboardEvent): void => {\n // bypass the native \"Delete\" action wich trigger an \"input\" event with \"checkValidty() => false\" with a falsy badInput = true,\n // when we reset the field we need to test a blank value.\n if (['Delete', 'Backspace'].includes(event.key)) {\n event.preventDefault();\n this.value = '';\n this.checkValidity();\n if (this.hasDisplayedError) {\n this.setErrorMessage();\n }\n }\n };\n\n /**\n * Check if input is valid\n */\n private checkValidity = (): void => {\n this.setValidity(this.readonly || this.disabled || (this.input.checkValidity() && (['', undefined].includes(this.value) || this.isValidPattern(this.value))));\n };\n\n /**\n * get input error code\n * @returns error code\n */\n private getInputError = (): null | InputDateError => {\n let inputError: InputDateError = null;\n\n // required\n if (this.input.validity.valueMissing) {\n inputError = 'required';\n }\n // pattern\n else if (this.value && !this.isValidPattern(this.value)) {\n inputError = 'badInput';\n }\n // min & max\n else if ((this.input.validity.rangeUnderflow || this.input.validity.rangeOverflow) && this.min?.length > 0 && this.max !== '9999-12-31') {\n inputError = 'minMax';\n }\n // min\n else if (this.input.validity.rangeUnderflow) {\n inputError = 'min';\n }\n // max\n else if (this.input.validity.rangeOverflow) {\n inputError = 'max';\n }\n\n return inputError;\n };\n\n /**\n * Check input errors\n * @param errorMessage - errorMessage override\n */\n private setErrorMessage = (errorMessage?: string): void => {\n // Set error message\n this.errorMessage = undefined;\n if (!this.valid) {\n const inputError = this.getInputError();\n if (errorMessage !== undefined) {\n this.errorMessage = errorMessage;\n }\n // required\n else if (inputError === 'required') {\n this.errorMessage = this.messages.errors[inputError];\n }\n // min, max & minMax\n else if (['min', 'max', 'minMax'].includes(inputError)) {\n this.errorMessage = this.messages.errors.date[inputError]\n .replace('{min}', localeDate(this.min, this.systemLocale))\n .replace('{max}', localeDate(this.max, this.systemLocale));\n }\n // wrong date format\n // element.validity.badInput is default error message\n else {\n this.errorMessage = this.messages.errors.date.badInput.replace('{pattern}', this.renderPattern());\n }\n }\n };\n\n /*************\n * Lifecycle *\n *************/\n\n /**\n * Check if component props are well configured on init\n * @returns timeout\n */\n componentWillLoad(): ReturnType<typeof setTimeout> {\n // Get locales\n const locales = initLocales(this.element);\n this.locale = locales.locale;\n this.messages = locales.messages;\n\n // as a native input use the OS locale to define the date pattern\n // we need to get this locale to define the displayed pattern\n this.systemLocale = Intl.DateTimeFormat().resolvedOptions().locale;\n\n // Validate\n this.validateValue(this.value);\n this.validateMinMax(this.min);\n this.validateMinMax(this.max);\n this.watchReadonly(this.readonly);\n this.watchDisabled(this.disabled);\n // Check validity when component is ready\n // return a promise to process action only in the FIRST render().\n // https://stenciljs.com/docs/component-lifecycle#componentwillload\n return setTimeout(() => {\n this.checkValidity();\n }, 0);\n }\n\n /**\n * Render pattern\n * @returns translated html pattern\n */\n private renderPattern = (): string => {\n let patternLocal = getLocaleDatePattern(this.systemLocale);\n for (const key in this.messages.input.date.pattern) {\n patternLocal = patternLocal.replace(key, this.messages.input.date.pattern[key]);\n }\n\n return `<span aria-hidden=\"true\">${patternLocal}</span><span class=\"mg-u-visually-hidden\">${[...patternLocal].join(' ')}</span>`;\n };\n\n /**\n * Render\n * @returns HTML Element\n */\n render(): HTMLElement {\n return (\n <mg-input\n label={this.label}\n identifier={this.identifier}\n class={this.classCollection.join()}\n ariaDescribedbyIDs={[]}\n labelOnTop={this.labelOnTop}\n labelHide={this.labelHide}\n required={this.required}\n tooltip={this.tooltip}\n tooltipPosition={this.readonly && ['', undefined].includes(this.value) ? 'label' : this.tooltipPosition}\n helpText={this.formatHelpText(this.helpText)}\n errorMessage={this.errorMessage}\n >\n {this.readonly ? (\n this.value && <b class=\"mg-c-input__readonly-value\">{localeDate(this.value, this.locale)}</b>\n ) : (\n <input\n type=\"date\"\n class=\"mg-c-input__box\"\n min={this.min}\n max={this.max}\n value={this.value}\n id={this.identifier}\n name={this.name}\n disabled={this.disabled}\n required={this.required}\n aria-invalid={(this.invalid === true).toString()}\n onInput={this.handleInput}\n onBlur={this.handleBlur}\n onKeyDown={this.handleKeyDown}\n ref={(el: HTMLInputElement) => {\n if (el !== null) this.input = el;\n }}\n />\n )}\n </mg-input>\n );\n }\n}\n"],"version":3}
1
+ {"file":"mg-input-date.js","mappings":";;;;;;;;;AAAA,MAAM,cAAc,GAAG,ymFAAymF,CAAC;AACjoF,0BAAe,cAAc;;MCUhBA,aAAW;IALxB;;;;;;;QAmBU,sBAAiB,GAAG,KAAK,CAAC;;;;;QA2C1B,SAAI,GAAW,IAAI,CAAC,UAAU,CAAC;;;;QAe/B,cAAS,GAAG,KAAK,CAAC;;;;QAKlB,aAAQ,GAAG,KAAK,CAAC;;;;QAKjB,aAAQ,GAAG,KAAK,CAAC;;;;;QAiBjB,QAAG,GAAY,YAAY,CAAC;;;;QAY5B,aAAQ,GAAG,KAAK,CAAC;;;;QA+BjB,oBAAe,GAAoB,OAAO,CAAC;;;;QAyB1C,oBAAe,GAAc,IAAIC,EAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC;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C,QAAQ,kBACT,CAAC,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE,QAAQ,EAAE,EAChD,OAAO,EAAE,IAAI,CAAC,WAAW,EACzB,MAAM,EAAE,IAAI,CAAC,UAAU,EACvB,SAAS,EAAE,IAAI,CAAC,aAAa,EAC7B,GAAG,EAAE,CAAC,EAAoB;gBACxB,IAAI,EAAE,KAAK,IAAI;oBAAE,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;aAClC,GACD,CACH,CACQ,EACX;KACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["MgInputDate","ClassList","isValidString","dateRegExp","localeDate","dateToString","getLocaleDatePattern","toString"],"sources":["../styles/dist/components/mg-input-date.css?tag=mg-input-date&encapsulation=shadow","src/components/molecules/inputs/mg-input-date/mg-input-date.tsx"],"sourcesContent":[".mg-c-input__readonly-value{min-height:var(--mg-b-font-size);align-self:flex-start;margin-top:calc((var(--mg-b-size-min-height) - var(--mg-b-font-size)*var(--mg-b-line-height))/2);word-break:break-word}.mg-c-input__box{height:var(--mg-b-size-min-height);box-sizing:border-box;padding:calc((var(--mg-b-size-min-height) - var(--mg-b-font-size)*var(--mg-b-line-height))/2) var(--mg-b-size-8);border-width:var(--mg-c-input-border-width);border-style:solid;border-color:var(--mg-c-input-color-border);border-radius:var(--mg-c-input-border-radius);background-color:var(--mg-b-color-light);color:var(--mg-b-color-dark);font-family:inherit;font-size:var(--mg-b-font-size);text-align:var(--mg-c-input-text-align, left)}.mg-c-input__box::placeholder{color:var(--mg-c-input-placeholder-color-text);font-style:italic}.mg-c-input__box:focus{box-shadow:0 0 var(--mg-b-size-4) var(--mg-c-input-color-box-shadow-focus)}.mg-c-input__box:disabled{opacity:var(--mg-b-opacity-element-disabled)}.mg-c-input.mg-c-input--has-error .mg-c-input__box{border-color:var(--mg-b-color-danger)}.mg-c-input.mg-c-input--is-input-group-append{--mg-c-button-border-radius-top-left: 0;--mg-c-button-border-radius-bottom-left: 0}.mg-c-input.mg-c-input--is-input-group-append .mg-c-input__box{margin-right:calc(-1*var(--mg-b-size-border));border-bottom-right-radius:0;border-top-right-radius:0}.mg-c-input.mg-c-input--is-input-group-append .mg-c-input__box:focus-visible{outline-offset:-0.2rem;outline-style:solid;outline-width:.2rem}.mg-c-input.mg-c-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-c-button-border-radius-top-right: 0;--mg-c-button-border-radius-bottom-right: 0}.mg-c-input.mg-c-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-c-button-border-right-width: 0}.mg-c-input.mg-c-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-c-button-border-radius-top-right: var(--mg-c-input-border-radius);--mg-c-button-border-radius-bottom-right: var(--mg-c-input-border-radius)}.mg-c-input.mg-c-input--is-append-input-slot-content:not(.mg-c-input--readonly) ::slotted([slot=append-input]){align-self:start;padding-top:calc((var(--mg-b-size-min-height) - var(--mg-b-size-16))/2)}.mg-u-visually-hidden{position:absolute !important;overflow:hidden !important;width:.1rem !important;height:.1rem !important;padding:0 !important;border:0 !important;margin:-0.1rem !important;clip:rect(0.1rem, 0.1rem, 0.1rem, 0.1rem) !important;clip-path:inset(50%) !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}@media(prefers-reduced-motion){*{animation:none !important;transition:none !important}}/*# sourceMappingURL=mg-input-date.css.map */\n","import { Component, Element, Event, EventEmitter, h, Prop, State, Watch, Method } from '@stencil/core';\nimport { ClassList, isValidString, localeDate, dateRegExp, dateToString, getLocaleDatePattern, toString } from '@mgdis/stencil-helpers';\nimport { type InputDateError } from './mg-input-date.conf';\nimport { type EventType, classReadonly, type TooltipPosition, classDisabled } from '../mg-input/mg-input.conf';\nimport { initLocales } from '../../../../locales';\n\n@Component({\n tag: 'mg-input-date',\n styleUrl: '../../../../../node_modules/@mgdis/styles/dist/components/mg-input-date.css',\n shadow: true,\n})\nexport class MgInputDate {\n /************\n * Internal *\n ************/\n\n // HTML selector\n private input: HTMLInputElement;\n\n // Locales\n private messages;\n private locale: string;\n private systemLocale: string;\n\n // hasDisplayedError (triggered by blur event)\n private hasDisplayedError = false;\n private handlerInProgress: EventType;\n\n /**************\n * Decorators *\n **************/\n\n /**\n * Get component DOM element\n */\n @Element() element: HTMLMgInputDateElement;\n\n /**\n * Component value\n */\n @Prop({ mutable: true, reflect: true }) value: string;\n @Watch('value')\n validateValue(newValue: MgInputDate['value']): void {\n // When the input is not fully completed or has been cleared, the value becomes an empty string.\n if (['', undefined].includes(newValue)) {\n // need to force value update to `null` to prevent extra render\n // - `''` is not a valide value\n // - `undefined` is not allowed in CustomEvent['detail']\n this.value = null;\n } else if (newValue && !isValidString(newValue)) {\n // check value validity\n throw new Error(`<mg-input-date> props 'value' must be a valid string. Passed value: ${toString(newValue)}.`);\n } else if (newValue === null || this.isValidPattern(newValue)) {\n this.valueChange.emit(newValue);\n } else {\n console.error(\"<mg-input-date> props 'value' doesn't match pattern: 'yyyy-mm-dd'.\");\n }\n }\n\n /**\n * Identifier is used for the element ID (id is a reserved prop in Stencil.js)\n */\n @Prop() identifier!: string;\n\n /**\n * Input name\n * If not set the value equals the identifier\n */\n @Prop() name: string = this.identifier;\n\n /**\n * Input label\n */\n @Prop() label!: string;\n\n /**\n * Define if label is displayed on top\n */\n @Prop() labelOnTop?: boolean;\n\n /**\n * Define if label is visible\n */\n @Prop() labelHide = false;\n\n /**\n * Define if input is required\n */\n @Prop() required = false;\n\n /**\n * Define if input is readonly\n */\n @Prop() readonly = false;\n @Watch('readonly')\n watchReadonly(newValue: MgInputDate['readonly']): void {\n if (newValue) this.classCollection.add(classReadonly);\n else this.classCollection.delete(classReadonly);\n }\n\n /**\n * Define input minimum date\n * format: yyyy-mm-dd\n */\n @Prop() min?: string;\n\n /**\n * Define input maximum date\n * format: yyyy-mm-dd\n */\n @Prop() max?: string = '9999-12-31';\n @Watch('min')\n @Watch('max')\n validateMinMax(newValue: string): void {\n if (newValue && !this.isValidPattern(newValue)) {\n throw new Error(`<mg-input-date> props 'min/max' doesn't match pattern: 'yyyy-mm-dd'. Passed value: ${toString(newValue)}.`);\n }\n }\n\n /**\n * Define if input is disabled\n */\n @Prop() disabled = false;\n @Watch('required')\n @Watch('readonly')\n @Watch('disabled')\n @Watch('min')\n @Watch('max')\n handleValidityChange(newValue: boolean, _oldValue: boolean, prop: string): void {\n if (this.input !== undefined) {\n this.input[prop] = newValue;\n this.checkValidity();\n if (this.hasDisplayedError) {\n this.setErrorMessage();\n this.hasDisplayedError = false;\n }\n }\n }\n\n @Watch('disabled')\n watchDisabled(newValue: MgInputDate['disabled']): void {\n if (newValue) this.classCollection.add(classDisabled);\n else this.classCollection.delete(classDisabled);\n }\n\n /**\n * Add a tooltip message next to the input\n */\n @Prop() tooltip?: string;\n\n /**\n * Define tooltip position\n */\n @Prop() tooltipPosition: TooltipPosition = 'input';\n\n /**\n * Add a help text under the input, usually expected data format and example\n * Available string variables:\n * - `{pattern}`: render innerHTML pattern based on system\n * - `{date}`: render innerText date with a pattern base format.\n * - `{defaultHelpText}`: render default `helpText` usefull to concat helpText local with your custom text.\n * ex: `Input use {pattern} pattern` as `helpText` prop value will be render as `Input use mm/dd/yyyy pattern`\n */\n @Prop() helpText?: string;\n\n /**\n * Define input valid state\n */\n @Prop({ mutable: true }) valid: boolean;\n\n /**\n * Define input invalid state\n */\n @Prop({ mutable: true }) invalid: boolean;\n\n /**\n * Component classes\n */\n @State() classCollection: ClassList = new ClassList(['mg-c-input--date']);\n\n /**\n * Error message to display\n */\n @State() errorMessage: string;\n\n /**\n * Emited event when value change\n */\n @Event({ eventName: 'value-change' }) valueChange: EventEmitter<HTMLMgInputDateElement['value']>;\n\n /**\n * Emited event when checking validity\n */\n @Event({ eventName: 'input-valid' }) inputValid: EventEmitter<HTMLMgInputDateElement['valid']>;\n\n /**\n * Display input error if it exists.\n */\n @Method()\n displayError(): Promise<void> {\n // Use `Promise` as requested for stencil method\n // Use `requestAnimationFrame` to ensure:\n // - DOM is fully updated before validation\n // - Async operations are completed\n // - No timing issues with Stencil's render cycle\n // - Keep everything in sync both inside and outside the component\n return new Promise(resolve => {\n requestAnimationFrame(() => {\n this.checkValidity();\n this.setErrorMessage();\n this.hasDisplayedError = this.invalid;\n resolve()\n })\n })\n }\n\n /**\n * Set an error and display a custom error message.\n * This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.\n * It must be paired with an error message to display for the given context.\n * When used to set validity to `false`, you should use this method again to reset the validity to `true`.\n * @param valid - value indicating the validity\n * @param errorMessage - the error message to display\n */\n @Method()\n async setError(valid: MgInputDate['valid'], errorMessage: string): Promise<void> {\n if (typeof valid !== 'boolean') {\n throw new Error('<mg-input-date> method \"setError()\" param \"valid\" must be a boolean.');\n } else if (!isValidString(errorMessage)) {\n throw new Error('<mg-input-date> method \"setError()\" param \"errorMessage\" must be a string.');\n } else {\n this.setValidity(valid);\n this.setErrorMessage(valid ? undefined : errorMessage);\n this.hasDisplayedError = this.invalid;\n }\n }\n\n /**\n * Reset value, validity and error state\n */\n @Method()\n async reset(): Promise<void> {\n if (!this.readonly) {\n this.value = null;\n this.checkValidity();\n this.invalid = false;\n this.errorMessage = undefined;\n this.hasDisplayedError = false;\n }\n }\n\n /**\n * Method to validate date pattern string\n * @param value - value to test\n * @returns truthy when value match the pattern\n */\n private isValidPattern = (value: string): boolean => isValidString(value) && dateRegExp.test(value);\n\n /**\n * Format help text to display\n * @param helpText - help text format\n * @returns formated pattern help text. Ex: Format attendu : jj/mm/aaaa (ex : 20/12/2020)\n */\n private formatHelpText = (helpText: string): string => {\n const defaultHelpTextVariable = '{defaultHelpText}';\n let text = isValidString(helpText) ? helpText : this.messages.input.date.helpText;\n if (text.includes(defaultHelpTextVariable)) text = text.replace(defaultHelpTextVariable, this.formatHelpText(this.messages.input.date.helpText));\n\n return text.replace('{pattern}', this.renderPattern()).replace('{date}', localeDate(dateToString(new Date('2023-12-24')), this.systemLocale));\n };\n\n /**\n * Method to set validity values\n * @param newValue - valid new value\n */\n private setValidity(newValue: MgInputDate['valid']) {\n const oldValidValue = this.valid;\n this.valid = newValue;\n this.invalid = !this.valid;\n // We need to send valid event even if it is the same value\n if (this.handlerInProgress === undefined || (this.handlerInProgress === 'blur' && this.valid !== oldValidValue)) this.inputValid.emit(this.valid);\n }\n\n /**\n * Handle input event\n */\n private handleInput = (): void => {\n this.checkValidity();\n if (this.hasDisplayedError) {\n this.setErrorMessage();\n }\n this.value = this.input.value;\n };\n\n /**\n * Handle blur event\n */\n private handleBlur = (): void => {\n this.handlerInProgress = 'blur';\n this.displayError().finally(() => {\n // reset guard\n this.handlerInProgress = undefined;\n });\n };\n\n /**\n * Handle keydown event\n * @param event - input keydown event\n */\n private handleKeyDown = (event: KeyboardEvent): void => {\n // bypass the native \"Delete\" action wich trigger an \"input\" event with \"checkValidty() => false\" with a falsy badInput = true,\n // when we reset the field we need to test a blank value.\n if (['Delete', 'Backspace'].includes(event.key)) {\n event.preventDefault();\n this.value = null;\n this.checkValidity();\n if (this.hasDisplayedError) {\n this.setErrorMessage();\n }\n }\n };\n\n /**\n * Check if input is valid\n */\n private checkValidity = (): void => {\n this.setValidity(this.readonly || this.disabled || (this.input.checkValidity() && (this.value === null || this.isValidPattern(this.value))));\n };\n\n /**\n * get input error code\n * @returns error code\n */\n private getInputError = (): null | InputDateError => {\n let inputError: InputDateError = null;\n\n // bad input or pattern\n if (this.input.validity.badInput || (this.value && !this.isValidPattern(this.value))) {\n inputError = 'badInput';\n }\n // required\n else if (this.input.validity.valueMissing) {\n inputError = 'required';\n }\n // min & max\n else if ((this.input.validity.rangeUnderflow || this.input.validity.rangeOverflow) && this.min?.length > 0 && this.max !== '9999-12-31') {\n inputError = 'minMax';\n }\n // min\n else if (this.input.validity.rangeUnderflow) {\n inputError = 'min';\n }\n // max\n else if (this.input.validity.rangeOverflow) {\n inputError = 'max';\n }\n\n return inputError;\n };\n\n /**\n * Check input errors\n * @param errorMessage - errorMessage override\n */\n private setErrorMessage = (errorMessage?: string): void => {\n // Set error message\n this.errorMessage = undefined;\n if (!this.valid) {\n const inputError = this.getInputError();\n if (errorMessage !== undefined) {\n this.errorMessage = errorMessage;\n }\n // required\n else if (inputError === 'required') {\n this.errorMessage = this.messages.errors[inputError];\n }\n // min, max & minMax\n else if (['min', 'max', 'minMax'].includes(inputError)) {\n this.errorMessage = this.messages.errors.date[inputError]\n .replace('{min}', localeDate(this.min, this.systemLocale))\n .replace('{max}', localeDate(this.max, this.systemLocale));\n }\n // wrong date format\n // element.validity.badInput is default error message\n else {\n this.errorMessage = this.messages.errors.date.badInput.replace('{pattern}', this.renderPattern());\n }\n }\n };\n\n /*************\n * Lifecycle *\n *************/\n\n /**\n * Check if component props are well configured on init\n * @returns timeout\n */\n componentWillLoad(): ReturnType<typeof setTimeout> {\n // Get locales\n const locales = initLocales(this.element);\n this.locale = locales.locale;\n this.messages = locales.messages;\n\n // as a native input use the OS locale to define the date pattern\n // we need to get this locale to define the displayed pattern\n this.systemLocale = Intl.DateTimeFormat().resolvedOptions().locale;\n\n // Validate\n this.validateValue(this.value);\n this.validateMinMax(this.min);\n this.validateMinMax(this.max);\n this.watchReadonly(this.readonly);\n this.watchDisabled(this.disabled);\n // Check validity when component is ready\n // return a promise to process action only in the FIRST render().\n // https://stenciljs.com/docs/component-lifecycle#componentwillload\n return setTimeout(() => {\n this.checkValidity();\n }, 0);\n }\n\n /**\n * Render pattern\n * @returns translated html pattern\n */\n private renderPattern = (): string => {\n let patternLocal = getLocaleDatePattern(this.systemLocale);\n for (const key in this.messages.input.date.pattern) {\n patternLocal = patternLocal.replace(key, this.messages.input.date.pattern[key]);\n }\n\n return `<span aria-hidden=\"true\">${patternLocal}</span><span class=\"mg-u-visually-hidden\">${[...patternLocal].join(' ')}</span>`;\n };\n\n /**\n * Render\n * @returns HTML Element\n */\n render(): HTMLElement {\n return (\n <mg-input\n label={this.label}\n identifier={this.identifier}\n class={this.classCollection.join()}\n ariaDescribedbyIDs={[]}\n labelOnTop={this.labelOnTop}\n labelHide={this.labelHide}\n required={this.required}\n tooltip={this.tooltip}\n tooltipPosition={this.readonly && this.value === null ? 'label' : this.tooltipPosition}\n helpText={this.formatHelpText(this.helpText)}\n errorMessage={this.errorMessage}\n >\n {this.readonly ? (\n this.value && <b class=\"mg-c-input__readonly-value\">{localeDate(this.value, this.locale)}</b>\n ) : (\n <input\n type=\"date\"\n class=\"mg-c-input__box\"\n min={this.min}\n max={this.max}\n value={this.value}\n id={this.identifier}\n name={this.name}\n disabled={this.disabled}\n required={this.required}\n aria-invalid={(this.invalid === true).toString()}\n onInput={this.handleInput}\n onBlur={this.handleBlur}\n onKeyDown={this.handleKeyDown}\n ref={(el: HTMLInputElement) => {\n if (el !== null) this.input = el;\n }}\n />\n )}\n </mg-input>\n );\n }\n}\n"],"version":3}
@@ -1,5 +1,5 @@
1
1
  import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
2
- import { p as pt, d as dt, u as ut, $ as $t, X as Xe, Y as Ye, m as me } from './index.es.js';
2
+ import { K as Ke, $ as $t, g as gt, p as pt, d as dt, V as Ve, m as me } from './index.es.js';
3
3
  import { d as defineCustomElement$5, b as classReadonly, e as classDisabled, w as widths } from './mg-input2.js';
4
4
  import { i as initLocales } from './index2.js';
5
5
  import { d as defineCustomElement$6 } from './mg-icon2.js';
@@ -25,6 +25,62 @@ const MgInputNumeric$1 = /*@__PURE__*/ proxyCustomElement(class MgInputNumeric e
25
25
  this.inputValid = createEvent(this, "input-valid", 7);
26
26
  // hasDisplayedError (triggered by blur event)
27
27
  this.hasDisplayedError = false;
28
+ /**
29
+ * Input name
30
+ * If not set the value equals the identifier
31
+ */
32
+ this.name = this.identifier;
33
+ /**
34
+ * Define if label is visible
35
+ */
36
+ this.labelHide = false;
37
+ /**
38
+ * Define if input is required
39
+ */
40
+ this.required = false;
41
+ /**
42
+ * Define if input is readonly
43
+ */
44
+ this.readonly = false;
45
+ /**
46
+ * Define if input is disabled
47
+ */
48
+ this.disabled = false;
49
+ /**
50
+ * Define tooltip position
51
+ */
52
+ this.tooltipPosition = 'input';
53
+ /**
54
+ * Define numeric type
55
+ */
56
+ this.type = 'decimal';
57
+ /**
58
+ * Set local formatting.
59
+ * Numbers are formatted based on the locale.
60
+ */
61
+ this.format = 'number';
62
+ /**
63
+ * Define currency
64
+ */
65
+ this.currency = 'EUR';
66
+ /**
67
+ * Define unit display format ('short', 'long', 'narrow')
68
+ */
69
+ this.unitDisplay = 'short';
70
+ /**
71
+ * Override integer length
72
+ * integer is the number before the decimal point
73
+ */
74
+ this.integerLength = 13;
75
+ /**
76
+ * Override decimal length
77
+ * decimal is the number after the decimal point
78
+ */
79
+ this.decimalLength = 2;
80
+ /**
81
+ * Component classes
82
+ */
83
+ this.classCollection = new Ke(['mg-c-input--numeric']);
28
84
  /**
29
85
  * Handle input event
30
86
  */
@@ -62,6 +118,12 @@ const MgInputNumeric$1 = /*@__PURE__*/ proxyCustomElement(class MgInputNumeric e
62
118
  this.checkValidity = () => {
63
119
  this.setValidity(this.readonly || this.disabled || this.getInputError() === null);
64
120
  };
121
+ /**
122
+ * Format min/max value for error message
123
+ * @param value - value to format
124
+ * @returns formatted value according to locale
125
+ */
126
+ this.formatErrorValue = (value) => $t(value, this.locale, !Number.isInteger(value) && this.type === 'decimal' ? this.decimalLength : 0);
65
127
  /**
66
128
  * Set input error message
67
129
  * @param errorMessage - errorMessage override
@@ -78,8 +140,8 @@ const MgInputNumeric$1 = /*@__PURE__*/ proxyCustomElement(class MgInputNumeric e
78
140
  this.errorMessage = this.messages.errors[inputError];
79
141
  }
80
142
  else {
81
- const formattedMin = this.formatValue(this.min);
82
- const formattedMax = this.formatValue(this.max);
143
+ const formattedMin = this.formatErrorValue(this.min);
144
+ const formattedMax = this.formatErrorValue(this.max);
83
145
  this.errorMessage = this.messages.errors.numeric[inputError].replace('{min}', formattedMin).replace('{max}', formattedMax);
84
146
  }
85
147
  }
@@ -120,11 +182,11 @@ const MgInputNumeric$1 = /*@__PURE__*/ proxyCustomElement(class MgInputNumeric e
120
182
  case 'number':
121
183
  return $t(value, this.locale, this.type === 'decimal' ? this.decimalLength : undefined);
122
184
  case 'currency':
123
- return ut(value, this.locale, this.currency);
185
+ return dt(value, this.locale, this.currency);
124
186
  case 'percent':
125
- return dt(value / 100, this.locale, this.type === 'decimal' ? this.decimalLength : undefined);
187
+ return pt(value / 100, this.locale, this.type === 'decimal' ? this.decimalLength : undefined);
126
188
  case 'unit':
127
- return pt(value, this.locale, this.unit, this.unitDisplay, this.type === 'decimal' ? this.decimalLength : undefined);
189
+ return gt(value, this.locale, this.unit, this.unitDisplay, this.type === 'decimal' ? this.decimalLength : undefined);
128
190
  case 'none':
129
191
  return value.toString();
130
192
  }
@@ -151,34 +213,6 @@ const MgInputNumeric$1 = /*@__PURE__*/ proxyCustomElement(class MgInputNumeric e
151
213
  this.renderReadonly = () => {
152
214
  return this.slotContent !== undefined ? (h("span", { class: "mg-c-input__readonly-value" }, h("b", null, this.readonlyValue), this.slotContent)) : (h("b", { class: "mg-c-input__readonly-value" }, this.readonlyValue));
153
215
  };
154
- this.value = undefined;
155
- this.identifier = undefined;
156
- this.name = this.identifier;
157
- this.label = undefined;
158
- this.labelOnTop = undefined;
159
- this.labelHide = false;
160
- this.placeholder = undefined;
161
- this.required = false;
162
- this.readonly = false;
163
- this.max = undefined;
164
- this.min = undefined;
165
- this.disabled = false;
166
- this.mgWidth = undefined;
167
- this.tooltip = undefined;
168
- this.tooltipPosition = 'input';
169
- this.helpText = undefined;
170
- this.type = 'decimal';
171
- this.format = 'number';
172
- this.currency = 'EUR';
173
- this.unit = undefined;
174
- this.unitDisplay = 'short';
175
- this.integerLength = 13;
176
- this.decimalLength = 2;
177
- this.valid = undefined;
178
- this.invalid = undefined;
179
- this.classCollection = new Xe(['mg-c-input--numeric']);
180
- this.errorMessage = undefined;
181
- this.hasFocus = undefined;
182
216
  }
183
217
  validateValue(newValue) {
184
218
  // has input value is always render as string we get a stringified value or a '' for nullish value, so we test string type
@@ -231,31 +265,42 @@ const MgInputNumeric$1 = /*@__PURE__*/ proxyCustomElement(class MgInputNumeric e
231
265
  }
232
266
  validateType(newValue) {
233
267
  if (!types.includes(newValue)) {
234
- throw new Error(`<mg-input-numeric> prop "type" must be one of: ${types.join(', ')}. Passed value: ${Ye(newValue)}.`);
268
+ throw new Error(`<mg-input-numeric> prop "type" must be one of: ${types.join(', ')}. Passed value: ${Ve(newValue)}.`);
235
269
  }
236
270
  }
237
271
  watchFormat(newValue) {
238
272
  if (!formats.includes(newValue)) {
239
- throw new Error(`<mg-input-numeric> prop "format" must be one of: ${formats.join(', ')}. Passed value: ${Ye(newValue)}.`);
273
+ throw new Error(`<mg-input-numeric> prop "format" must be one of: ${formats.join(', ')}. Passed value: ${Ve(newValue)}.`);
240
274
  }
241
275
  }
242
276
  validateIntegerLength(newValue) {
243
277
  if (newValue < 1) {
244
- throw new Error(`<mg-input-numeric> prop "integer-length" must be a positive number. Passed value: ${Ye(newValue)}.`);
278
+ throw new Error(`<mg-input-numeric> prop "integer-length" must be a positive number. Passed value: ${Ve(newValue)}.`);
245
279
  }
246
280
  }
247
281
  validateDecimalLength(newValue) {
248
282
  if (newValue < 1) {
249
- throw new Error(`<mg-input-numeric> prop "decimal-length" must be a positive number, consider using prop "type" to "integer" instead. Passed value: ${Ye(newValue)}.`);
283
+ throw new Error(`<mg-input-numeric> prop "decimal-length" must be a positive number, consider using prop "type" to "integer" instead. Passed value: ${Ve(newValue)}.`);
250
284
  }
251
285
  }
252
286
  /**
253
287
  * Display input error if it exists.
254
288
  */
255
- async displayError() {
256
- this.checkValidity();
257
- this.setErrorMessage();
258
- this.hasDisplayedError = this.invalid;
289
+ displayError() {
290
+ // Use `Promise` as requested for stencil method
291
+ // Use `requestAnimationFrame` to ensure:
292
+ // - DOM is fully updated before validation
293
+ // - Async operations are completed
294
+ // - No timing issues with Stencil's render cycle
295
+ // - Keep everything in sync both inside and outside the component
296
+ return new Promise(resolve => {
297
+ requestAnimationFrame(() => {
298
+ this.checkValidity();
299
+ this.setErrorMessage();
300
+ this.hasDisplayedError = this.invalid;
301
+ resolve();
302
+ });
303
+ });
259
304
  }
260
305
  /**
261
306
  * Set an error and display a custom error message.
@@ -375,7 +420,7 @@ const MgInputNumeric$1 = /*@__PURE__*/ proxyCustomElement(class MgInputNumeric e
375
420
  * @returns HTML Element
376
421
  */
377
422
  render() {
378
- return (h("mg-input", { key: '6d34c2b7e9762cdefc5de3814ff4afd95fa4a6a6', label: this.label, identifier: this.identifier, class: this.classCollection.join(), ariaDescribedbyIDs: [], labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, tooltip: this.tooltip, tooltipPosition: this.readonly && this.value === undefined ? 'label' : this.tooltipPosition, helpText: this.helpText, errorMessage: this.errorMessage }, this.readonly
423
+ return (h("mg-input", { key: 'b3f1b0e8a78d2f61146f052db1636d98e89271d1', label: this.label, identifier: this.identifier, class: this.classCollection.join(), ariaDescribedbyIDs: [], labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, tooltip: this.tooltip, tooltipPosition: this.readonly && this.value === undefined ? 'label' : this.tooltipPosition, helpText: this.helpText, errorMessage: this.errorMessage }, this.readonly
379
424
  ? this.readonlyValue && this.renderReadonly()
380
425
  : [
381
426
  h("input", { key: "input", type: "text", class: "mg-c-input__box mg-c-input__box--width", value: this.displayValue(), id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, disabled: this.disabled, required: this.required, "aria-invalid": (this.invalid === true).toString(), onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: (el) => {