@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,8 +1,7 @@
1
- import { Component, Event, h, Prop, State, Element } from '@stencil/core';
1
+ import { Component, Event, h, Prop, State, Element, Method, Watch } from '@stencil/core';
2
2
  import { MgInput } from '../MgInput';
3
3
  import { createID, ClassList } from '../../../../utils/components.utils';
4
- import { messages } from '../../../../locales';
5
- import { InputClass } from '../MgInput.conf';
4
+ import { initLocales } from '../../../../locales';
6
5
  export class MgInputText {
7
6
  constructor() {
8
7
  /************
@@ -10,7 +9,10 @@ export class MgInputText {
10
9
  ************/
11
10
  // classes
12
11
  this.classFocus = 'is-focused';
13
- this.classError = InputClass.ERROR;
12
+ this.classIsInputGroupAppend = 'mg-input--is-input-group-append';
13
+ this.classHasIcon = 'mg-input--has-icon';
14
+ // hasError (triggered by blur event)
15
+ this.hasError = false;
14
16
  /**
15
17
  * Identifier is used for the element ID (id is a reserved prop in Stencil.js)
16
18
  * If not set, it will be created.
@@ -48,7 +50,7 @@ export class MgInputText {
48
50
  /**
49
51
  * Define input width
50
52
  */
51
- this.width = 'full';
53
+ this.mgWidth = 'full';
52
54
  /**
53
55
  * Define if component should display character left
54
56
  */
@@ -59,14 +61,20 @@ export class MgInputText {
59
61
  this.classList = new ClassList(['mg-input--text']);
60
62
  /**
61
63
  * Handle input event
64
+ *
65
+ * @returns {void}
62
66
  */
63
67
  this.handleInput = () => {
64
68
  this.checkValidity();
69
+ if (this.hasError) {
70
+ this.checkError();
71
+ }
65
72
  this.value = this.input.value;
66
- this.valueChange.emit(this.value);
67
73
  };
68
74
  /**
69
75
  * Handle focus event
76
+ *
77
+ * @returns {void}
70
78
  */
71
79
  this.handleFocus = () => {
72
80
  this.classList.add(this.classFocus);
@@ -74,17 +82,52 @@ export class MgInputText {
74
82
  };
75
83
  /**
76
84
  * Handle blur event
85
+ *
86
+ * @returns {void}
77
87
  */
78
88
  this.handleBlur = () => {
79
89
  // Manage focus
80
90
  this.classList.delete(this.classFocus);
81
91
  this.classList = new ClassList(this.classList.classes);
82
- // Check validity
83
- this.checkValidity();
84
- this.checkError();
92
+ // Display Error
93
+ this.displayError();
94
+ };
95
+ /**
96
+ * Check if input is valid
97
+ *
98
+ * @returns {void}
99
+ */
100
+ this.checkValidity = () => {
101
+ if (!this.readonly && this.input !== undefined) {
102
+ const validity = this.input.checkValidity();
103
+ // Set validity
104
+ this.valid = validity;
105
+ this.invalid = !validity;
106
+ //Send event
107
+ this.inputValid.emit(validity);
108
+ }
109
+ };
110
+ /**
111
+ * Check input errors
112
+ *
113
+ * @returns {void}
114
+ */
115
+ this.checkError = () => {
116
+ // Set error message
117
+ this.errorMessage = undefined;
118
+ // Does not match pattern
119
+ if (!this.valid && this.input.validity.patternMismatch) {
120
+ this.errorMessage = this.patternErrorMessage;
121
+ }
122
+ // required
123
+ else if (!this.valid && this.input.validity.valueMissing) {
124
+ this.errorMessage = this.messages.errors.required;
125
+ }
85
126
  };
86
127
  /**
87
128
  * Validate patern configuration
129
+ *
130
+ * @returns {void}
88
131
  */
89
132
  this.validatePattern = () => {
90
133
  if (this.pattern &&
@@ -94,76 +137,89 @@ export class MgInputText {
94
137
  throw new Error('<mg-input-text> prop "pattern" must be paired with the prop "patternErrorMessage"');
95
138
  }
96
139
  };
140
+ /**
141
+ * Validate append slot
142
+ *
143
+ * @returns {void}
144
+ */
145
+ this.validateAppendSlot = () => {
146
+ const slotAppendInput = Array.from(this.element.querySelectorAll('[slot="append-input"]'));
147
+ if (slotAppendInput.length === 1) {
148
+ this.classList.add(slotAppendInput[0].nodeName === 'MG-BUTTON' ? this.classIsInputGroupAppend : 'mg-input--is-append-input-slot-content');
149
+ }
150
+ else if (slotAppendInput.filter(slot => slot.nodeName === 'MG-BUTTON').length > 1) {
151
+ this.classList.add(this.classIsInputGroupAppend);
152
+ this.classList.add('mg-input--has-buttons-group-append');
153
+ }
154
+ };
97
155
  }
98
- /**
99
- * Check if input is valid
100
- */
101
- checkValidity() {
102
- if (!this.readonly && this.input !== undefined) {
103
- const validity = this.input.checkValidity();
104
- // Set validity
105
- this.valid = validity;
106
- this.invalid = !validity;
107
- }
156
+ handleValue(newValue) {
157
+ this.valueChange.emit(newValue);
108
158
  }
109
- /**
110
- * Check input errors
111
- */
112
- checkError() {
113
- // Set error message
114
- this.errorMessage = undefined;
115
- // Does not match pattern
116
- if (!this.valid && this.input.validity.patternMismatch) {
117
- this.errorMessage = this.patternErrorMessage;
118
- }
119
- // required
120
- else if (!this.valid && this.input.validity.valueMissing) {
121
- this.errorMessage = messages.errors.required;
122
- }
123
- // Update class
124
- if (this.valid) {
125
- this.classList.delete(this.classError);
159
+ validateIcon(newValue) {
160
+ if (newValue !== undefined) {
161
+ this.classList.add(this.classHasIcon);
126
162
  }
127
163
  else {
128
- this.classList.add(this.classError);
164
+ this.classList.delete(this.classHasIcon);
129
165
  }
130
166
  }
131
167
  /**
132
- * Validate append slot
168
+ * Public method to play input focus
169
+ *
170
+ * @returns {Promise<void>}
133
171
  */
134
- validateAppendSlot() {
135
- const slotAppendInput = this.element.querySelector('[slot="append-input"]');
136
- if (slotAppendInput !== null && slotAppendInput.querySelector('.mg-button') !== null) {
137
- this.classList.add('mg-input--is-input-group-append');
138
- this.classList = new ClassList(this.classList.classes);
139
- }
140
- else if (slotAppendInput !== null) {
141
- this.classList.add('mg-input--is-append-input-slot-content');
142
- this.classList = new ClassList(this.classList.classes);
143
- }
172
+ async setFocus() {
173
+ this.input.focus();
174
+ }
175
+ /**
176
+ * Public method to display errors
177
+ *
178
+ * @returns {Promise<void>}
179
+ */
180
+ async displayError() {
181
+ this.checkValidity();
182
+ this.checkError();
183
+ this.hasError = this.invalid;
144
184
  }
145
185
  /*************
146
186
  * Lifecycle *
147
187
  *************/
148
188
  /**
149
189
  * Check if component props are well configured on init
190
+ *
191
+ * @returns {ReturnType<typeof setTimeout>} timeout
150
192
  */
151
193
  componentWillLoad() {
152
- if (this.icon !== undefined) {
153
- this.classList.add('mg-input--has-icon');
154
- }
194
+ // Get locales
195
+ this.messages = initLocales(this.element).messages;
196
+ this.characterLeftId = `${this.identifier}-character-left`;
197
+ // Validate
198
+ this.validateIcon(this.icon);
155
199
  this.validatePattern();
200
+ this.validateAppendSlot();
201
+ // Check validity when component is ready
156
202
  // return a promise to process action only in the FIRST render().
157
203
  // https://stenciljs.com/docs/component-lifecycle#componentwillload
158
- return setTimeout(() => this.checkValidity(), 0);
159
- }
160
- componentDidLoad() {
161
- this.validateAppendSlot();
204
+ return setTimeout(() => {
205
+ this.checkValidity();
206
+ }, 0);
162
207
  }
208
+ /**
209
+ * Render
210
+ *
211
+ * @returns {HTMLElement} HTML Element
212
+ */
163
213
  render() {
164
- 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: undefined, tooltip: this.tooltip, displayCharacterLeft: this.displayCharacterLeft, characterLeftTemplate: this.characterLeftTemplate, maxlength: this.maxlength, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false },
165
- this.icon !== undefined && h("mg-icon", { icon: this.icon }),
166
- h("input", { type: this.type, class: "mg-input__box", value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, maxlength: this.maxlength, disabled: this.disabled, required: this.required, pattern: this.pattern, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el => (this.input = el) }),
214
+ return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [this.characterLeftId], 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: undefined, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false },
215
+ h("div", { class: "mg-input__with-character-left", style: {
216
+ '--mg-character-left-message-length': (this.displayCharacterLeft
217
+ ? (this.maxlength - (this.value || '').length).toString().length + this.maxlength.toString().length + 1
218
+ : 0).toString(),
219
+ } },
220
+ this.icon !== undefined && h("mg-icon", { icon: this.icon }),
221
+ h("input", { type: this.type, class: "mg-input__box", value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, maxlength: this.maxlength, disabled: this.disabled, required: this.required, pattern: this.pattern, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el => (this.input = el) }),
222
+ this.displayCharacterLeft && this.maxlength && (h("mg-character-left", { identifier: this.characterLeftId, characters: this.value, maxlength: this.maxlength }))),
167
223
  h("slot", { name: "append-input" })));
168
224
  }
169
225
  static get is() { return "mg-input-text"; }
@@ -201,7 +257,7 @@ export class MgInputText {
201
257
  "references": {}
202
258
  },
203
259
  "required": false,
204
- "optional": true,
260
+ "optional": false,
205
261
  "docs": {
206
262
  "tags": [],
207
263
  "text": "Identifier is used for the element ID (id is a reserved prop in Stencil.js)\nIf not set, it will be created."
@@ -219,7 +275,7 @@ export class MgInputText {
219
275
  "references": {}
220
276
  },
221
277
  "required": false,
222
- "optional": true,
278
+ "optional": false,
223
279
  "docs": {
224
280
  "tags": [],
225
281
  "text": "Input name\nIf not set the value equals the identifier"
@@ -240,7 +296,7 @@ export class MgInputText {
240
296
  "optional": false,
241
297
  "docs": {
242
298
  "tags": [],
243
- "text": "Input label\nRequired"
299
+ "text": "Input label"
244
300
  },
245
301
  "attribute": "label",
246
302
  "reflect": false
@@ -404,7 +460,7 @@ export class MgInputText {
404
460
  "reflect": false,
405
461
  "defaultValue": "false"
406
462
  },
407
- "width": {
463
+ "mgWidth": {
408
464
  "type": "any",
409
465
  "mutable": false,
410
466
  "complexType": {
@@ -423,7 +479,7 @@ export class MgInputText {
423
479
  "tags": [],
424
480
  "text": "Define input width"
425
481
  },
426
- "attribute": "width",
482
+ "attribute": "mg-width",
427
483
  "reflect": false,
428
484
  "defaultValue": "'full'"
429
485
  },
@@ -496,23 +552,6 @@ export class MgInputText {
496
552
  "reflect": false,
497
553
  "defaultValue": "true"
498
554
  },
499
- "characterLeftTemplate": {
500
- "type": "string",
501
- "mutable": false,
502
- "complexType": {
503
- "original": "string",
504
- "resolved": "string",
505
- "references": {}
506
- },
507
- "required": false,
508
- "optional": false,
509
- "docs": {
510
- "tags": [],
511
- "text": "Template to use for characters left sentence"
512
- },
513
- "attribute": "character-left-template",
514
- "reflect": false
515
- },
516
555
  "helpText": {
517
556
  "type": "string",
518
557
  "mutable": false,
@@ -542,7 +581,7 @@ export class MgInputText {
542
581
  "optional": false,
543
582
  "docs": {
544
583
  "tags": [],
545
- "text": "Define input pattern to validate"
584
+ "text": "Define input valid state"
546
585
  },
547
586
  "attribute": "valid",
548
587
  "reflect": false
@@ -559,7 +598,7 @@ export class MgInputText {
559
598
  "optional": false,
560
599
  "docs": {
561
600
  "tags": [],
562
- "text": "Define input pattern error message"
601
+ "text": "Define input invalid state"
563
602
  },
564
603
  "attribute": "invalid",
565
604
  "reflect": false
@@ -577,13 +616,75 @@ export class MgInputText {
577
616
  "composed": true,
578
617
  "docs": {
579
618
  "tags": [],
580
- "text": "Emmited event when value change"
619
+ "text": "Emited event when value change"
581
620
  },
582
621
  "complexType": {
583
622
  "original": "string",
584
623
  "resolved": "string",
585
624
  "references": {}
586
625
  }
626
+ }, {
627
+ "method": "inputValid",
628
+ "name": "input-valid",
629
+ "bubbles": true,
630
+ "cancelable": true,
631
+ "composed": true,
632
+ "docs": {
633
+ "tags": [],
634
+ "text": "Emited event when checking validity"
635
+ },
636
+ "complexType": {
637
+ "original": "boolean",
638
+ "resolved": "boolean",
639
+ "references": {}
640
+ }
587
641
  }]; }
642
+ static get methods() { return {
643
+ "setFocus": {
644
+ "complexType": {
645
+ "signature": "() => Promise<void>",
646
+ "parameters": [],
647
+ "references": {
648
+ "Promise": {
649
+ "location": "global"
650
+ }
651
+ },
652
+ "return": "Promise<void>"
653
+ },
654
+ "docs": {
655
+ "text": "Public method to play input focus",
656
+ "tags": [{
657
+ "name": "returns",
658
+ "text": undefined
659
+ }]
660
+ }
661
+ },
662
+ "displayError": {
663
+ "complexType": {
664
+ "signature": "() => Promise<void>",
665
+ "parameters": [],
666
+ "references": {
667
+ "Promise": {
668
+ "location": "global"
669
+ }
670
+ },
671
+ "return": "Promise<void>"
672
+ },
673
+ "docs": {
674
+ "text": "Public method to display errors",
675
+ "tags": [{
676
+ "name": "returns",
677
+ "text": undefined
678
+ }]
679
+ }
680
+ }
681
+ }; }
588
682
  static get elementRef() { return "element"; }
683
+ static get watchers() { return [{
684
+ "propName": "value",
685
+ "methodName": "handleValue"
686
+ }, {
687
+ "propName": "icon",
688
+ "methodName": "validateIcon"
689
+ }]; }
589
690
  }
@@ -2,12 +2,23 @@ import { h } from '@stencil/core';
2
2
  export default {
3
3
  component: 'mg-input-textarea',
4
4
  title: 'Molecules/Inputs/mg-input-textarea',
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;
@@ -16,12 +27,12 @@ const Template = args => {
16
27
  delete args.patternErrorMessage;
17
28
  const displayCharacterLeft = args.displayCharacterLeft;
18
29
  delete args.displayCharacterLeft;
19
- const characterLeftTemplate = args.characterLeftTemplate;
20
- delete args.characterLeftTemplate;
21
30
  const helpText = args.helpText;
22
31
  delete args.helpText;
32
+ const mgWidth = args.mgWidth;
33
+ delete args.mgWidth;
23
34
  // return element
24
- return (h("mg-input-textarea", Object.assign({}, args, { "label-on-top": labelOnTop, "label-hide": labelHide, "pattern-error-message": patternErrorMessage, "display-character-left": displayCharacterLeft, "character-left-template": characterLeftTemplate, "help-text": helpText })));
35
+ return (h("mg-input-textarea", Object.assign({}, args, { "label-on-top": labelOnTop, "label-hide": labelHide, "pattern-error-message": patternErrorMessage, "display-character-left": displayCharacterLeft ? 'true' : 'false', "help-text": helpText, "mg-width": mgWidth })));
25
36
  };
26
37
  export const MgInputTextarea = Template.bind({});
27
38
  MgInputTextarea.args = {
@@ -42,11 +53,11 @@ MgInputTextarea.args = {
42
53
  pattern: undefined,
43
54
  patternErrorMessage: undefined,
44
55
  rows: 3,
56
+ mgWidth: 'full',
45
57
  // Tooltip
46
58
  tooltip: 'This is a tooltip',
47
59
  // Nb Char Left
48
60
  displayCharacterLeft: true,
49
- characterLeftTemplate: '{counter} characters left.',
50
61
  // Help Text
51
62
  helpText: 'Help text with html <strong>bold</strong>, <em>italic</em>.',
52
63
  };
@@ -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
  }
@@ -174,13 +202,14 @@
174
202
  }
175
203
 
176
204
  /**
177
- * Manage display mg-character-left on focus
205
+ * Set mg-character-left with inputs
178
206
  */
179
207
  .mg-input mg-character-left {
180
- display: none;
208
+ opacity: 0.6;
209
+ font-size: 1.1rem;
181
210
  }
182
- .mg-input.is-focused mg-character-left {
183
- display: block;
211
+ .mg-input.mg-input--has-display-character-left .mg-input__input + .mg-input__help-text, .mg-input.mg-input--has-display-character-left .mg-input__input + .mg-input__error {
212
+ margin-top: 0;
184
213
  }
185
214
 
186
215
  /**
@@ -206,7 +235,34 @@
206
235
 
207
236
  /* Component Custom Style */
208
237
  .mg-input .mg-input__box {
238
+ display: block;
209
239
  height: auto;
240
+ resize: none;
241
+ }
242
+ .mg-input .mg-input__box.mg-input__box--resizable {
243
+ resize: both;
244
+ }
245
+ .mg-input .mg-input__box.mg-input__box--resizable-horizontal {
246
+ resize: horizontal;
247
+ }
248
+ .mg-input .mg-input__box.mg-input__box--resizable-vertical {
249
+ resize: vertical;
250
+ }
251
+
252
+ /**
253
+ * Character left
254
+ */
255
+ .mg-input__with-character-left {
256
+ width: 100%;
257
+ }
258
+ .mg-input__with-character-left mg-character-left {
259
+ display: block;
260
+ visibility: hidden;
261
+ margin-top: 0.2rem;
262
+ text-align: end;
263
+ }
264
+ .mg-input.is-focused .mg-input__with-character-left mg-character-left {
265
+ visibility: visible;
210
266
  }
211
267
 
212
268
  /* Firefox selector */