@mgdis/mg-components 3.1.0 → 4.0.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 (241) hide show
  1. package/dist/cjs/{index-85a4a0b6.js → index-88560a66.js} +123 -48
  2. package/dist/cjs/index-a39c5567.js +233 -0
  3. package/dist/cjs/loader.cjs.js +3 -17
  4. package/dist/cjs/mg-badge_21.cjs.entry.js +3538 -0
  5. package/dist/cjs/mg-components.cjs.js +3 -7
  6. package/dist/cjs/mg-modal.cjs.entry.js +117 -0
  7. package/dist/cjs/mg-popover.cjs.entry.js +170 -0
  8. package/dist/cjs/popper-71bf3058.js +1790 -0
  9. package/dist/collection/collection-manifest.json +4 -1
  10. package/dist/collection/components/atoms/mg-badge/{mg-badge.stories.js → doc/mg-badge.stories.js} +4 -1
  11. package/dist/collection/components/atoms/mg-badge/mg-badge.conf.js +1 -1
  12. package/dist/collection/components/atoms/mg-badge/mg-badge.css +0 -2
  13. package/dist/collection/components/atoms/mg-badge/mg-badge.js +26 -10
  14. package/dist/collection/components/atoms/mg-button/{mg-button.stories.js → doc/mg-button.stories.js} +7 -2
  15. package/dist/collection/components/atoms/mg-button/mg-button.conf.js +1 -1
  16. package/dist/collection/components/atoms/mg-button/mg-button.css +46 -49
  17. package/dist/collection/components/atoms/mg-button/mg-button.js +78 -4
  18. package/dist/collection/components/atoms/mg-character-left/{mg-character-left.stories.js → doc/mg-character-left.stories.js} +8 -0
  19. package/dist/collection/components/atoms/mg-character-left/mg-character-left.js +20 -46
  20. package/dist/collection/components/atoms/mg-icon/{mg-icon.stories.js → doc/mg-icon.stories.js} +1 -1
  21. package/dist/collection/components/atoms/mg-icon/mg-icon.conf.js +104 -9
  22. package/dist/collection/components/atoms/mg-icon/mg-icon.css +9 -7
  23. package/dist/collection/components/atoms/mg-icon/mg-icon.js +33 -7
  24. package/dist/collection/components/atoms/mg-input-title/{mg-input-title.stories.js → doc/mg-input-title.stories.js} +0 -0
  25. package/dist/collection/components/atoms/mg-input-title/mg-input-title.css +4 -4
  26. package/dist/collection/components/atoms/mg-input-title/mg-input-title.js +14 -3
  27. package/dist/collection/components/atoms/mg-tag/{mg-tag.stories.js → doc/mg-tag.stories.js} +4 -1
  28. package/dist/collection/components/atoms/mg-tag/mg-tag.js +28 -6
  29. package/dist/collection/components/atoms/mg-tooltip/{mg-tooltip.stories.js → doc/mg-tooltip.stories.js} +14 -1
  30. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.conf.js +20 -0
  31. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +16 -2
  32. package/dist/collection/components/molecules/inputs/MgInput.conf.js +1 -7
  33. package/dist/collection/components/molecules/inputs/MgInput.js +25 -29
  34. package/dist/collection/components/molecules/inputs/mg-input-checkbox/{mg-input-checkbox.stories.js → doc/mg-input-checkbox.stories.js} +6 -1
  35. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.css +25 -11
  36. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +102 -52
  37. package/dist/collection/components/molecules/inputs/mg-input-date/{mg-input-date.stories.js → doc/mg-input-date.stories.js} +6 -1
  38. package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.css +37 -9
  39. package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +136 -66
  40. package/dist/collection/components/molecules/inputs/mg-input-numeric/{mg-input-numeric.stories.js → doc/mg-input-numeric.stories.js} +15 -3
  41. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.css +38 -10
  42. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +180 -80
  43. package/dist/collection/components/molecules/inputs/mg-input-password/{mg-input-password.stories.js → doc/mg-input-password.stories.js} +16 -2
  44. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.css +37 -9
  45. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +108 -47
  46. package/dist/collection/components/molecules/inputs/mg-input-radio/{mg-input-radio.stories.js → doc/mg-input-radio.stories.js} +6 -1
  47. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.css +25 -11
  48. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +113 -42
  49. package/dist/collection/components/molecules/inputs/mg-input-select/{mg-input-select.stories.js → doc/mg-input-select.stories.js} +22 -2
  50. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.css +39 -10
  51. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +145 -71
  52. package/dist/collection/components/molecules/inputs/mg-input-text/{mg-input-text.stories.js → doc/mg-input-text.stories.js} +17 -8
  53. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.css +69 -19
  54. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +184 -83
  55. package/dist/collection/components/molecules/inputs/mg-input-textarea/{mg-input-textarea.stories.js → doc/mg-input-textarea.stories.js} +16 -5
  56. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.css +69 -13
  57. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +163 -70
  58. package/dist/collection/components/molecules/inputs/mg-input-toggle/{mg-input-toggle.stories.js → doc/mg-input-toggle.stories.js} +6 -1
  59. package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.css +22 -10
  60. package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +68 -33
  61. package/dist/collection/components/molecules/mg-form/doc/mg-form.stories.js +58 -0
  62. package/dist/collection/components/molecules/mg-form/mg-form.css +19 -0
  63. package/dist/collection/components/molecules/mg-form/mg-form.js +271 -0
  64. package/dist/collection/components/molecules/mg-message/{mg-message.stories.js → doc/mg-message.stories.js} +6 -2
  65. package/dist/collection/components/molecules/mg-message/mg-message.css +1 -1
  66. package/dist/collection/components/molecules/mg-message/mg-message.js +26 -11
  67. package/dist/collection/components/molecules/mg-modal/doc/mg-modal.stories.js +51 -0
  68. package/dist/collection/components/molecules/mg-modal/mg-modal.css +52 -0
  69. package/dist/collection/components/molecules/mg-modal/mg-modal.js +240 -0
  70. package/dist/collection/components/molecules/mg-pagination/{mg-pagination.stories.js → doc/mg-pagination.stories.js} +1 -0
  71. package/dist/collection/components/molecules/mg-pagination/mg-pagination.js +47 -28
  72. package/dist/collection/components/molecules/mg-panel/doc/mg-panel.stories.js +39 -0
  73. package/dist/collection/components/molecules/mg-panel/mg-panel.css +53 -0
  74. package/dist/collection/components/molecules/mg-panel/mg-panel.js +356 -0
  75. package/dist/collection/components/molecules/mg-popover/{mg-popover.stories.js → doc/mg-popover.stories.js} +10 -0
  76. package/dist/collection/components/molecules/mg-popover/mg-popover.conf.js +20 -0
  77. package/dist/collection/components/molecules/mg-popover/mg-popover.css +2 -2
  78. package/dist/collection/components/molecules/mg-popover/mg-popover.js +37 -12
  79. package/dist/collection/components/molecules/mg-tabs/{mg-tabs.stories.js → doc/mg-tabs.stories.js} +20 -4
  80. package/dist/collection/components/molecules/mg-tabs/mg-tabs.conf.js +11 -1
  81. package/dist/collection/components/molecules/mg-tabs/mg-tabs.css +17 -3
  82. package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +139 -26
  83. package/dist/collection/locales/index.js +33 -4
  84. package/dist/collection/stories/helpers.stories.js +33 -0
  85. package/dist/collection/utils/components.utils.js +16 -9
  86. package/dist/collection/utils/locale.utils.js +13 -7
  87. package/dist/collection/utils/test.utils.js +27 -15
  88. package/dist/collection/variables.css +39 -5
  89. package/dist/collection/variables.scss +39 -5
  90. package/dist/components/MgInput.js +26 -37
  91. package/dist/components/components.utils.js +16 -9
  92. package/dist/components/index.d.ts +24 -6
  93. package/dist/components/index.js +23 -0
  94. package/dist/components/index2.js +116 -17
  95. package/dist/components/locale.utils.js +13 -8
  96. package/dist/components/mg-badge2.js +25 -9
  97. package/dist/components/mg-button2.js +29 -5
  98. package/dist/components/mg-character-left2.js +14 -26
  99. package/dist/components/mg-form.d.ts +11 -0
  100. package/dist/components/mg-form.js +148 -0
  101. package/dist/components/mg-icon2.js +138 -17
  102. package/dist/components/mg-input-checkbox.js +66 -53
  103. package/dist/components/mg-input-date.js +100 -69
  104. package/dist/components/mg-input-numeric.js +125 -81
  105. package/dist/components/mg-input-password.js +69 -48
  106. package/dist/components/mg-input-radio.js +74 -46
  107. package/dist/components/mg-input-select2.js +103 -71
  108. package/dist/components/mg-input-text.js +1 -237
  109. package/dist/components/mg-input-text2.js +300 -0
  110. package/dist/components/mg-input-textarea.js +100 -46
  111. package/dist/components/mg-input-title2.js +13 -4
  112. package/dist/components/mg-input-toggle.js +39 -31
  113. package/dist/components/mg-message.js +25 -10
  114. package/dist/components/mg-modal.d.ts +11 -0
  115. package/dist/components/mg-modal.js +153 -0
  116. package/dist/components/mg-pagination.js +45 -31
  117. package/dist/components/mg-panel.d.ts +11 -0
  118. package/dist/components/mg-panel.js +244 -0
  119. package/dist/components/mg-popover.js +31 -11
  120. package/dist/components/mg-tabs.js +113 -23
  121. package/dist/components/mg-tag.js +27 -5
  122. package/dist/components/mg-tooltip2.js +10 -1
  123. package/dist/components/popper.js +6 -2
  124. package/dist/esm/{index-e3e84606.js → index-bca81100.js} +124 -46
  125. package/dist/esm/index-e51ae032.js +228 -0
  126. package/dist/esm/loader.js +3 -17
  127. package/dist/esm/mg-badge_21.entry.js +3514 -0
  128. package/dist/esm/mg-components.js +3 -7
  129. package/dist/esm/mg-modal.entry.js +113 -0
  130. package/dist/esm/mg-popover.entry.js +166 -0
  131. package/dist/esm/polyfills/css-shim.js +1 -1
  132. package/dist/esm/popper-93ecb064.js +1788 -0
  133. package/dist/index.js +1 -1
  134. package/dist/mg-components/mg-components.css +1 -1
  135. package/dist/mg-components/mg-components.esm.js +1 -1
  136. package/dist/mg-components/p-003a1344.entry.js +1 -0
  137. package/dist/mg-components/p-462d648a.entry.js +1 -0
  138. package/dist/mg-components/p-4c66f794.js +1 -0
  139. package/dist/mg-components/p-5126ab10.entry.js +1 -0
  140. package/dist/mg-components/p-780bd52d.js +1 -0
  141. package/dist/mg-components/p-b14a3443.js +2 -0
  142. package/dist/mg-components/variables.css +39 -5
  143. package/dist/mg-components/variables.scss +39 -5
  144. package/dist/types/components/atoms/mg-badge/{mg-badge.stories.d.ts → doc/mg-badge.stories.d.ts} +5 -0
  145. package/dist/types/components/atoms/mg-badge/mg-badge.d.ts +16 -5
  146. package/dist/types/components/atoms/mg-button/{mg-button.stories.d.ts → doc/mg-button.stories.d.ts} +5 -0
  147. package/dist/types/components/atoms/mg-button/mg-button.d.ts +23 -3
  148. package/dist/types/components/atoms/mg-character-left/{mg-character-left.stories.d.ts → doc/mg-character-left.stories.d.ts} +9 -0
  149. package/dist/types/components/atoms/mg-character-left/mg-character-left.d.ts +16 -13
  150. package/dist/types/components/atoms/mg-icon/{mg-icon.stories.d.ts → doc/mg-icon.stories.d.ts} +0 -0
  151. package/dist/types/components/atoms/mg-icon/mg-icon.conf.d.ts +1 -1
  152. package/dist/types/components/atoms/mg-icon/mg-icon.d.ts +14 -4
  153. package/dist/types/components/atoms/mg-input-title/{mg-input-title.stories.d.ts → doc/mg-input-title.stories.d.ts} +0 -0
  154. package/dist/types/components/atoms/mg-input-title/mg-input-title.d.ts +11 -1
  155. package/dist/types/components/atoms/mg-tag/{mg-tag.stories.d.ts → doc/mg-tag.stories.d.ts} +5 -0
  156. package/dist/types/components/atoms/mg-tag/mg-tag.d.ts +18 -4
  157. package/dist/types/components/atoms/mg-tooltip/doc/mg-tooltip.stories.d.ts +29 -0
  158. package/dist/types/components/atoms/mg-tooltip/mg-tooltip.conf.d.ts +8 -0
  159. package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +13 -3
  160. package/dist/types/components/molecules/inputs/MgInput.conf.d.ts +6 -4
  161. package/dist/types/components/molecules/inputs/MgInput.d.ts +7 -8
  162. package/dist/types/components/molecules/inputs/mg-input-checkbox/{mg-input-checkbox.stories.d.ts → doc/mg-input-checkbox.stories.d.ts} +5 -0
  163. package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +36 -13
  164. package/dist/types/components/molecules/inputs/mg-input-date/{mg-input-date.stories.d.ts → doc/mg-input-date.stories.d.ts} +5 -0
  165. package/dist/types/components/molecules/inputs/mg-input-date/mg-input-date.d.ts +46 -15
  166. package/dist/types/components/molecules/inputs/mg-input-numeric/{mg-input-numeric.stories.d.ts → doc/mg-input-numeric.stories.d.ts} +11 -0
  167. package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +61 -16
  168. package/dist/types/components/molecules/inputs/mg-input-password/doc/mg-input-password.stories.d.ts +22 -0
  169. package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.d.ts +35 -11
  170. package/dist/types/components/molecules/inputs/mg-input-radio/{mg-input-radio.stories.d.ts → doc/mg-input-radio.stories.d.ts} +5 -0
  171. package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.conf.d.ts +1 -1
  172. package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.d.ts +42 -9
  173. package/dist/types/components/molecules/inputs/mg-input-select/doc/mg-input-select.stories.d.ts +34 -0
  174. package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.conf.d.ts +1 -1
  175. package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.d.ts +37 -9
  176. package/dist/types/components/molecules/inputs/mg-input-text/{mg-input-text.stories.d.ts → doc/mg-input-text.stories.d.ts} +13 -0
  177. package/dist/types/components/molecules/inputs/mg-input-text/mg-input-text.d.ts +52 -16
  178. package/dist/types/components/molecules/inputs/mg-input-textarea/doc/mg-input-textarea.stories.d.ts +19 -0
  179. package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.d.ts +45 -17
  180. package/dist/types/components/molecules/inputs/mg-input-toggle/{mg-input-toggle.stories.d.ts → doc/mg-input-toggle.stories.d.ts} +5 -0
  181. package/dist/types/components/molecules/inputs/mg-input-toggle/mg-input-toggle.conf.d.ts +1 -1
  182. package/dist/types/components/molecules/inputs/mg-input-toggle/mg-input-toggle.d.ts +29 -12
  183. package/dist/types/components/molecules/{mg-popover/mg-popover.stories.d.ts → mg-form/doc/mg-form.stories.d.ts} +3 -4
  184. package/dist/types/components/molecules/mg-form/mg-form.d.ts +83 -0
  185. package/dist/types/components/molecules/mg-message/{mg-message.stories.d.ts → doc/mg-message.stories.d.ts} +10 -0
  186. package/dist/types/components/molecules/mg-message/mg-message.d.ts +13 -4
  187. package/dist/types/components/molecules/mg-modal/doc/mg-modal.stories.d.ts +13 -0
  188. package/dist/types/components/molecules/mg-modal/mg-modal.d.ts +85 -0
  189. package/dist/types/components/molecules/mg-pagination/{mg-pagination.stories.d.ts → doc/mg-pagination.stories.d.ts} +5 -0
  190. package/dist/types/components/molecules/mg-pagination/mg-pagination.d.ts +31 -7
  191. package/dist/types/components/molecules/mg-panel/doc/mg-panel.stories.d.ts +11 -0
  192. package/dist/types/components/molecules/mg-panel/mg-panel.d.ts +139 -0
  193. package/dist/types/components/molecules/mg-popover/doc/mg-popover.stories.d.ts +25 -0
  194. package/dist/types/components/molecules/mg-popover/mg-popover.conf.d.ts +8 -0
  195. package/dist/types/components/molecules/mg-popover/mg-popover.d.ts +27 -4
  196. package/dist/types/components/molecules/mg-tabs/doc/mg-tabs.stories.d.ts +20 -0
  197. package/dist/types/components/molecules/mg-tabs/mg-tabs.conf.d.ts +11 -0
  198. package/dist/types/components/molecules/mg-tabs/mg-tabs.d.ts +70 -6
  199. package/dist/types/components.d.ts +528 -211
  200. package/dist/types/locales/index.d.ts +108 -38
  201. package/dist/types/stories/{buttons.stories.d.ts → helpers.stories.d.ts} +1 -1
  202. package/dist/types/utils/components.utils.d.ts +16 -9
  203. package/dist/types/utils/locale.utils.d.ts +13 -6
  204. package/dist/types/utils/test.utils.d.ts +13 -1
  205. package/loader/index.js +1 -1
  206. package/package.json +45 -14
  207. package/readme.md +9 -35
  208. package/dist/cjs/css-shim-a22512c4.js +0 -6
  209. package/dist/cjs/mg-badge_20.cjs.entry.js +0 -4661
  210. package/dist/cjs/shadow-css-8940f82d.js +0 -390
  211. package/dist/collection/stories/buttons.stories.js +0 -43
  212. package/dist/collection/stories/messages.stories.js +0 -44
  213. package/dist/collection/stories/tags.stories.js +0 -13
  214. package/dist/esm/css-shim-7c240feb.js +0 -4
  215. package/dist/esm/mg-badge_20.entry.js +0 -4638
  216. package/dist/esm/shadow-css-5d2d01ce.js +0 -388
  217. package/dist/esm-es5/css-shim-7c240feb.js +0 -1
  218. package/dist/esm-es5/index-e3e84606.js +0 -1
  219. package/dist/esm-es5/index.js +0 -0
  220. package/dist/esm-es5/loader.js +0 -1
  221. package/dist/esm-es5/mg-badge_20.entry.js +0 -2
  222. package/dist/esm-es5/mg-components.js +0 -1
  223. package/dist/esm-es5/shadow-css-5d2d01ce.js +0 -12
  224. package/dist/mg-components/mg-components.js +0 -132
  225. package/dist/mg-components/p-1cd24462.system.js +0 -1
  226. package/dist/mg-components/p-2e2f6b27.system.entry.js +0 -2
  227. package/dist/mg-components/p-366a224e.js +0 -1
  228. package/dist/mg-components/p-422c429b.system.js +0 -1
  229. package/dist/mg-components/p-50ea2036.system.js +0 -1
  230. package/dist/mg-components/p-62fa3797.js +0 -1
  231. package/dist/mg-components/p-71d57b8b.system.js +0 -13
  232. package/dist/mg-components/p-9a215712.system.js +0 -1
  233. package/dist/mg-components/p-cbf0464b.entry.js +0 -1
  234. package/dist/mg-components/p-f6455ab3.js +0 -12
  235. package/dist/types/components/atoms/mg-tooltip/mg-tooltip.stories.d.ts +0 -11
  236. package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.stories.d.ts +0 -9
  237. package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.stories.d.ts +0 -14
  238. package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.stories.d.ts +0 -6
  239. package/dist/types/components/molecules/mg-tabs/mg-tabs.stories.d.ts +0 -7
  240. package/dist/types/stories/messages.stories.d.ts +0 -13
  241. package/dist/types/stories/tags.stories.d.ts +0 -5
@@ -1,14 +1,13 @@
1
- import { Component, Element, Event, h, Prop, State, Watch } from '@stencil/core';
1
+ import { Component, Element, Event, h, Prop, State, Watch, Method } from '@stencil/core';
2
2
  import { MgInput } from '../MgInput';
3
3
  import { types, InputError } from './mg-input-numeric.conf';
4
4
  import { createID, ClassList } from '../../../../utils/components.utils';
5
- import { messages } from '../../../../locales';
5
+ import { initLocales } from '../../../../locales/';
6
6
  import { localeCurrency, localeNumber } from '../../../../utils/locale.utils';
7
- import { InputClass } from '../MgInput.conf';
8
7
  export class MgInputNumeric {
9
8
  constructor() {
10
- // Classes
11
- this.classError = InputClass.ERROR;
9
+ // hasError (triggered by blur event)
10
+ this.hasError = false;
12
11
  /**
13
12
  * Identifier is used for the element ID (id is a reserved prop in Stencil.js)
14
13
  * If not set, it will be created.
@@ -39,6 +38,10 @@ export class MgInputNumeric {
39
38
  * Define numeric type
40
39
  */
41
40
  this.type = types[0];
41
+ /**
42
+ * Define currency
43
+ */
44
+ this.currency = 'USD';
42
45
  /**
43
46
  * Override integer length
44
47
  * integer is the number before the decimal point
@@ -53,33 +56,87 @@ export class MgInputNumeric {
53
56
  * Component classes
54
57
  */
55
58
  this.classList = new ClassList(['mg-input--numeric']);
59
+ /**
60
+ * Define if input has focus
61
+ */
62
+ this.hasFocus = false;
56
63
  /**
57
64
  * Handle input event
65
+ *
66
+ * @returns {void}
58
67
  */
59
68
  this.handleInput = () => {
60
69
  // Check validity
61
70
  this.checkValidity();
71
+ if (this.hasError) {
72
+ this.checkError();
73
+ }
62
74
  this.value = this.input.value;
63
75
  };
64
76
  /**
65
77
  * Handle focus event
78
+ *
79
+ * @returns {void}
66
80
  */
67
81
  this.handleFocus = () => {
68
- this.displayValue = this.value;
82
+ this.hasFocus = true;
69
83
  };
70
84
  /**
71
85
  * Handle blur event
86
+ *
87
+ * @returns {void}
72
88
  */
73
89
  this.handleBlur = () => {
74
- // Check validity
75
- this.checkValidity();
76
- this.checkError();
77
- // Display readonly value
78
- this.displayValue = this.readonlyValue;
90
+ // Display Error
91
+ this.displayError();
92
+ this.hasFocus = false;
93
+ };
94
+ /**
95
+ * Check if input is valid
96
+ *
97
+ * @returns {void}
98
+ */
99
+ this.checkValidity = () => {
100
+ if (!this.readonly) {
101
+ const validity = this.getInputError() === null;
102
+ // Set validity
103
+ this.valid = validity;
104
+ this.invalid = !validity;
105
+ //Send event
106
+ this.inputValid.emit(validity);
107
+ }
108
+ };
109
+ /**
110
+ * Set error message
111
+ *
112
+ * @returns {void}
113
+ */
114
+ this.setErrorMessage = () => {
115
+ const inputError = this.getInputError();
116
+ if (inputError === InputError.REQUIRED) {
117
+ this.errorMessage = this.messages.errors[inputError];
118
+ }
119
+ else {
120
+ this.errorMessage = this.messages.errors.numeric[inputError].replace('{min}', `${this.formatValue(this.min)}`).replace('{max}', `${this.formatValue(this.max)}`);
121
+ }
122
+ };
123
+ /**
124
+ * Check input errors
125
+ *
126
+ * @returns {void}
127
+ */
128
+ this.checkError = () => {
129
+ // Set error message
130
+ this.errorMessage = undefined;
131
+ // Update class
132
+ if (!this.valid) {
133
+ this.setErrorMessage();
134
+ }
79
135
  };
80
136
  /**
81
- * get input error code
82
- * @returns {null | InputError}
137
+ * Get input error code
138
+ *
139
+ * @returns {null | InputError} error code
83
140
  */
84
141
  this.getInputError = () => {
85
142
  let inputError = null;
@@ -90,7 +147,7 @@ export class MgInputNumeric {
90
147
  inputError = InputError.REQUIRED;
91
148
  }
92
149
  // Min & Max
93
- if (this.min !== undefined && this.numericValue < this.min && this.max === undefined) {
150
+ else if (this.min !== undefined && this.numericValue < this.min && this.max === undefined) {
94
151
  // Only a min value is set
95
152
  inputError = InputError.MIN;
96
153
  }
@@ -106,10 +163,22 @@ export class MgInputNumeric {
106
163
  };
107
164
  /**
108
165
  * Format value based on type
109
- * @param value {number}
166
+ *
167
+ * @param {number} value value to format
110
168
  * @returns {string} formated local value
111
169
  */
112
- this.formatValue = (value) => (this.type === 'currency' ? localeCurrency(value) : localeNumber(value));
170
+ this.formatValue = (value) => (this.type === 'currency' ? localeCurrency(value, this.locale, this.currency) : localeNumber(value, this.locale));
171
+ /**
172
+ * Validate append slot
173
+ *
174
+ * @returns {void}
175
+ */
176
+ this.validateAppendSlot = () => {
177
+ const slotAppendInput = this.element.querySelector('[slot="append-input"]');
178
+ if (slotAppendInput !== null) {
179
+ this.classList.add(slotAppendInput.nodeName === 'MG-BUTTON' ? 'mg-input--is-input-group-append' : 'mg-input--is-append-input-slot-content');
180
+ }
181
+ };
113
182
  }
114
183
  validateValue(newValue) {
115
184
  if (newValue !== undefined && newValue !== null) {
@@ -134,7 +203,7 @@ export class MgInputNumeric {
134
203
  // emit numeric value
135
204
  this.numericValue = this.value !== '' && this.value !== null ? parseFloat(this.value.replace(',', '.')) : null;
136
205
  this.valueChange.emit(this.numericValue);
137
- // Set readOnlyValue
206
+ // Set readonlyValue
138
207
  this.readonlyValue = this.numericValue !== null ? this.formatValue(this.numericValue) : '';
139
208
  }
140
209
  }
@@ -142,7 +211,6 @@ export class MgInputNumeric {
142
211
  if (!types.includes(newValue)) {
143
212
  throw new Error(`<mg-input-numeric> prop "type" must be one of : ${types.join(', ')}`);
144
213
  }
145
- this.classList.add(`mg-input--numeric--${this.type}`);
146
214
  }
147
215
  validateIntegerLength(newValue) {
148
216
  if (newValue < 1) {
@@ -155,80 +223,58 @@ export class MgInputNumeric {
155
223
  }
156
224
  }
157
225
  /**
158
- * Check if input is valid
159
- */
160
- checkValidity() {
161
- if (!this.readonly) {
162
- const validity = this.getInputError() === null;
163
- // Set validity
164
- this.valid = validity;
165
- this.invalid = !validity;
166
- }
167
- }
168
- /**
169
- * Set error message
170
- */
171
- setErrorMessage() {
172
- const inputError = this.getInputError();
173
- if (inputError === InputError.REQUIRED) {
174
- this.errorMessage = messages.errors[inputError];
175
- }
176
- else {
177
- this.errorMessage = messages.errors.numeric[inputError].replace('{min}', `${this.formatValue(this.min)}`).replace('{max}', `${this.formatValue(this.max)}`);
178
- }
179
- }
180
- /**
181
- * Check input errors
226
+ * Public method to display errors
227
+ *
228
+ * @returns {Promise<void>}
182
229
  */
183
- checkError() {
184
- // Set error message
185
- this.errorMessage = undefined;
186
- // Update class
187
- if (!this.valid) {
188
- this.setErrorMessage();
189
- this.classList.add(this.classError);
190
- }
191
- else {
192
- this.classList.delete(this.classError);
193
- }
230
+ async displayError() {
231
+ this.checkValidity();
232
+ this.checkError();
233
+ this.hasError = this.invalid;
194
234
  }
195
235
  /**
196
- * Validate append slot
236
+ * Displayed value in input
237
+ * Change on focus/blur
238
+ *
239
+ * @returns {string} display value
197
240
  */
198
- validateAppendSlot() {
199
- const slotAppendInput = this.element.querySelector('[slot="append-input"]');
200
- if (slotAppendInput !== null && slotAppendInput.querySelector('.mg-button') !== null) {
201
- this.classList.add('mg-input--is-input-group-append');
202
- this.classList = new ClassList(this.classList.classes);
203
- }
204
- else if (slotAppendInput !== null) {
205
- this.classList.add('mg-input--is-append-input-slot-content');
206
- this.classList = new ClassList(this.classList.classes);
207
- }
241
+ displayValue() {
242
+ return this.hasFocus ? this.value : this.readonlyValue;
208
243
  }
209
244
  /*************
210
245
  * Lifecycle *
211
246
  *************/
247
+ /**
248
+ * Check if component props are well configured on init
249
+ *
250
+ * @returns {ReturnType<typeof setTimeout>} timeout
251
+ */
212
252
  componentWillLoad() {
253
+ // Get locales
254
+ const locales = initLocales(this.element);
255
+ this.locale = locales.locale;
256
+ this.messages = locales.messages;
257
+ // Validate
213
258
  this.validateValue(this.value);
214
- // Set displayed value
215
- this.displayValue = this.readonlyValue;
216
259
  this.validateType(this.type);
217
260
  this.validateIntegerLength(this.integerLength);
218
261
  this.validateDecimalLength(this.decimalLength);
262
+ this.validateAppendSlot();
263
+ // Check validity when component is ready
219
264
  // return a promise to process action only in the FIRST render().
220
265
  // https://stenciljs.com/docs/component-lifecycle#componentwillload
221
- return setTimeout(() => this.checkValidity(), 0);
222
- }
223
- componentDidLoad() {
224
- this.validateAppendSlot();
266
+ return setTimeout(() => {
267
+ this.checkValidity();
268
+ }, 0);
225
269
  }
226
270
  /**
227
- * Check if component props are well configured on init
271
+ * Render
272
+ *
273
+ * @returns {HTMLElement} HTML Element
228
274
  */
229
275
  render() {
230
- return (h(MgInput, { identifier: this.identifier, classList: this.classList, label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, width: this.width, disabled: this.disabled, value: this.value, readonlyValue: this.readonlyValue, tooltip: this.tooltip, displayCharacterLeft: undefined, characterLeftTemplate: undefined, maxlength: undefined, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false },
231
- h("input", { type: "text", class: "mg-input__box", value: this.displayValue, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el => (this.input = el) }),
276
+ return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: this.mgWidth, disabled: this.disabled, value: this.value, readonlyValue: this.readonlyValue, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false },
277
+ h("input", { type: "text", class: "mg-input__box", value: this.displayValue(), id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el => (this.input = el) }),
232
278
  h("slot", { name: "append-input" })));
233
279
  }
234
280
  static get is() { return "mg-input-numeric"; }
@@ -266,7 +312,7 @@ export class MgInputNumeric {
266
312
  "references": {}
267
313
  },
268
314
  "required": false,
269
- "optional": true,
315
+ "optional": false,
270
316
  "docs": {
271
317
  "tags": [],
272
318
  "text": "Identifier is used for the element ID (id is a reserved prop in Stencil.js)\nIf not set, it will be created."
@@ -284,7 +330,7 @@ export class MgInputNumeric {
284
330
  "references": {}
285
331
  },
286
332
  "required": false,
287
- "optional": true,
333
+ "optional": false,
288
334
  "docs": {
289
335
  "tags": [],
290
336
  "text": "Input name\nIf not set the value equals the identifier"
@@ -305,7 +351,7 @@ export class MgInputNumeric {
305
351
  "optional": false,
306
352
  "docs": {
307
353
  "tags": [],
308
- "text": "Input label\nRequired"
354
+ "text": "Input label"
309
355
  },
310
356
  "attribute": "label",
311
357
  "reflect": false
@@ -416,7 +462,7 @@ export class MgInputNumeric {
416
462
  "reflect": false,
417
463
  "defaultValue": "false"
418
464
  },
419
- "width": {
465
+ "mgWidth": {
420
466
  "type": "any",
421
467
  "mutable": false,
422
468
  "complexType": {
@@ -435,7 +481,7 @@ export class MgInputNumeric {
435
481
  "tags": [],
436
482
  "text": "Define input width"
437
483
  },
438
- "attribute": "width",
484
+ "attribute": "mg-width",
439
485
  "reflect": false
440
486
  },
441
487
  "tooltip": {
@@ -490,6 +536,24 @@ export class MgInputNumeric {
490
536
  "reflect": false,
491
537
  "defaultValue": "types[0]"
492
538
  },
539
+ "currency": {
540
+ "type": "string",
541
+ "mutable": false,
542
+ "complexType": {
543
+ "original": "string",
544
+ "resolved": "string",
545
+ "references": {}
546
+ },
547
+ "required": false,
548
+ "optional": false,
549
+ "docs": {
550
+ "tags": [],
551
+ "text": "Define currency"
552
+ },
553
+ "attribute": "currency",
554
+ "reflect": false,
555
+ "defaultValue": "'USD'"
556
+ },
493
557
  "max": {
494
558
  "type": "number",
495
559
  "mutable": false,
@@ -598,7 +662,7 @@ export class MgInputNumeric {
598
662
  static get states() { return {
599
663
  "classList": {},
600
664
  "errorMessage": {},
601
- "displayValue": {}
665
+ "hasFocus": {}
602
666
  }; }
603
667
  static get events() { return [{
604
668
  "method": "valueChange",
@@ -608,14 +672,50 @@ export class MgInputNumeric {
608
672
  "composed": true,
609
673
  "docs": {
610
674
  "tags": [],
611
- "text": "Emmited event when value change"
675
+ "text": "Emited event when value change"
612
676
  },
613
677
  "complexType": {
614
678
  "original": "number",
615
679
  "resolved": "number",
616
680
  "references": {}
617
681
  }
682
+ }, {
683
+ "method": "inputValid",
684
+ "name": "input-valid",
685
+ "bubbles": true,
686
+ "cancelable": true,
687
+ "composed": true,
688
+ "docs": {
689
+ "tags": [],
690
+ "text": "Emited event when checking validity"
691
+ },
692
+ "complexType": {
693
+ "original": "boolean",
694
+ "resolved": "boolean",
695
+ "references": {}
696
+ }
618
697
  }]; }
698
+ static get methods() { return {
699
+ "displayError": {
700
+ "complexType": {
701
+ "signature": "() => Promise<void>",
702
+ "parameters": [],
703
+ "references": {
704
+ "Promise": {
705
+ "location": "global"
706
+ }
707
+ },
708
+ "return": "Promise<void>"
709
+ },
710
+ "docs": {
711
+ "text": "Public method to display errors",
712
+ "tags": [{
713
+ "name": "returns",
714
+ "text": undefined
715
+ }]
716
+ }
717
+ }
718
+ }; }
619
719
  static get elementRef() { return "element"; }
620
720
  static get watchers() { return [{
621
721
  "propName": "value",
@@ -2,20 +2,33 @@ import { h } from '@stencil/core';
2
2
  export default {
3
3
  component: 'mg-input-password',
4
4
  title: 'Molecules/Inputs/mg-input-password',
5
+ argTypes: {
6
+ mgWidth: {
7
+ options: [2, 4, 16, 'full'],
8
+ control: { type: 'select' },
9
+ },
10
+ },
11
+ parameters: { actions: { handles: ['value-change', 'input-valid'] } },
5
12
  };
6
13
  /**
7
14
  * 1. camelCase arguments must be written in the template, for exemple labelOnTop must be placed in the template as label-on-top={args.labelOnTop}
8
15
  * 2. boolean arguments with a default true value must be added like display-character-left={args.displayCharacterLeft ? 'true' : 'false'}
16
+ *
17
+ * @param {any} args component arguments
18
+ * @returns {HTMLElement} HTMLElement
9
19
  */
10
- const Template = args => {
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ const Template = (args) => {
11
22
  const labelOnTop = args.labelOnTop;
12
23
  delete args.labelOnTop;
13
24
  const labelHide = args.labelHide;
14
25
  delete args.labelHide;
15
26
  const helpText = args.helpText;
16
27
  delete args.helpText;
28
+ const mgWidth = args.mgWidth;
29
+ delete args.mgWidth;
17
30
  // return element
18
- return h("mg-input-password", Object.assign({}, args, { "label-on-top": labelOnTop, "label-hide": labelHide, "help-text": helpText }));
31
+ return h("mg-input-password", Object.assign({}, args, { "label-on-top": labelOnTop, "label-hide": labelHide, "help-text": helpText, "mg-width": mgWidth }));
19
32
  };
20
33
  /**
21
34
  * Global use
@@ -36,6 +49,7 @@ MgInputPassword.args = {
36
49
  required: true,
37
50
  disabled: false,
38
51
  readonly: false,
52
+ mgWidth: 'full',
39
53
  // Tooltip
40
54
  tooltip: 'This is a tooltip',
41
55
  // Help Text
@@ -10,16 +10,10 @@
10
10
  align-items: flex-start;
11
11
  min-height: var(--default-size);
12
12
  max-width: 100%;
13
- /* Style when input is not valid */
13
+ margin-bottom: var(--mg-inputs-margin-bottom, 0);
14
14
  /* Label */
15
15
  /* Label-on-top */
16
16
  }
17
- .mg-input.is-not-valid {
18
- color: hsl(var(--color-danger));
19
- }
20
- .mg-input.is-not-valid .mg-input__box {
21
- border-color: hsl(var(--color-danger));
22
- }
23
17
  .mg-input mg-input-title {
24
18
  flex-shrink: var(--mg-inputs-shrink, 1);
25
19
  width: var(--mg-inputs-title-width, auto);
@@ -73,6 +67,11 @@
73
67
  .mg-input__input-container mg-icon {
74
68
  display: flex;
75
69
  }
70
+ .mg-input__input-container .mg-input__help-text,
71
+ .mg-input__input-container .mg-input__error {
72
+ text-align: start;
73
+ font-size: 1.2rem;
74
+ }
76
75
 
77
76
  .mg-input__input {
78
77
  display: flex;
@@ -81,11 +80,22 @@
81
80
  .mg-input__input mg-tooltip {
82
81
  margin-top: calc((var(--default-size) - var(--mg-icon-regular-size)) / 2);
83
82
  }
84
- .mg-input__input + * {
85
- text-align: start;
83
+ .mg-input__input.mg-input__input--has-error .mg-input__box {
84
+ border-color: hsl(var(--color-danger));
85
+ }
86
+ .mg-input__input + .mg-input__help-text, .mg-input__input + .mg-input__error {
86
87
  margin-top: 0.5rem;
87
88
  }
88
89
 
90
+ .mg-input__error {
91
+ display: inline-block;
92
+ margin-top: 0.2rem;
93
+ padding: 0.3rem 0.8rem;
94
+ border-radius: 0.3rem;
95
+ background: hsl(var(--mg-inputs-error-bg-color));
96
+ color: hsl(var(--color-danger));
97
+ }
98
+
89
99
  /**
90
100
  * Style for input "box":
91
101
  * - input[type="text"]
@@ -106,6 +116,7 @@
106
116
  font-family: inherit;
107
117
  color: hsl(var(--color-dark));
108
118
  font-size: var(--font-size);
119
+ text-align: var(--mg-inputs-text-align, left);
109
120
  }
110
121
  .mg-input__box::placeholder {
111
122
  color: var(--mg-inputs-color);
@@ -145,6 +156,23 @@
145
156
  display: none;
146
157
  }
147
158
 
159
+ .mg-input.mg-input--label-on-top .mg-input__box {
160
+ width: auto;
161
+ max-width: 100%;
162
+ }
163
+
164
+ .mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]) {
165
+ --mg-button-border-radius-top-right: 0;
166
+ --mg-button-border-radius-bottom-right: 0;
167
+ }
168
+ .mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)) {
169
+ --mg-button-border-right-width: 0;
170
+ }
171
+ .mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type) {
172
+ --mg-button-border-radius-top-right: var(--mg-inputs-border-radius);
173
+ --mg-button-border-radius-bottom-right: var(--mg-inputs-border-radius);
174
+ }
175
+
148
176
  .mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]) {
149
177
  padding-top: calc((var(--default-size) - var(--mg-icon-regular-size)) / 2);
150
178
  }