@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,15 +1,11 @@
1
- import { Component, Event, h, Prop, State } from '@stencil/core';
1
+ import { Component, Element, Event, h, Prop, State, 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 MgInputPassword {
7
6
  constructor() {
8
- /************
9
- * Internal *
10
- ************/
11
- // classes
12
- this.classError = InputClass.ERROR;
7
+ // hasError (triggered by blur event)
8
+ this.hasError = false;
13
9
  /**
14
10
  * Identifier is used for the element ID (id is a reserved prop in Stencil.js)
15
11
  * If not set, it will be created.
@@ -39,7 +35,7 @@ export class MgInputPassword {
39
35
  /**
40
36
  * Define input width
41
37
  */
42
- this.width = 'full';
38
+ this.mgWidth = 'full';
43
39
  /**
44
40
  * Component classes
45
41
  */
@@ -49,56 +45,80 @@ export class MgInputPassword {
49
45
  */
50
46
  this.handleInput = () => {
51
47
  this.checkValidity();
48
+ if (this.hasError) {
49
+ this.checkError();
50
+ }
52
51
  this.value = this.input.value;
53
- this.valueChange.emit(this.value);
54
52
  };
55
53
  /**
56
54
  * Handle blur event
57
55
  */
58
56
  this.handleBlur = () => {
59
- this.checkValidity();
60
- this.checkError();
57
+ this.displayError();
58
+ };
59
+ /**
60
+ * Check if input is valid
61
+ */
62
+ this.checkValidity = () => {
63
+ if (!this.readonly && this.input !== undefined) {
64
+ const validity = this.input.checkValidity();
65
+ // Set validity
66
+ this.valid = validity;
67
+ this.invalid = !validity;
68
+ //Send event
69
+ this.inputValid.emit(validity);
70
+ }
71
+ };
72
+ /**
73
+ * Check input errors
74
+ */
75
+ this.checkError = () => {
76
+ // Set error message
77
+ this.errorMessage = undefined;
78
+ // required
79
+ if (!this.valid && this.input.validity.valueMissing) {
80
+ this.errorMessage = this.messages.errors.required;
81
+ }
61
82
  };
62
83
  }
63
- /**
64
- * Check if input is valid
65
- */
66
- checkValidity() {
67
- if (!this.readonly && this.input !== undefined) {
68
- const validity = this.input.checkValidity();
69
- // Set validity
70
- this.valid = validity;
71
- this.invalid = !validity;
72
- }
84
+ handleValue(newValue) {
85
+ this.valueChange.emit(newValue);
73
86
  }
74
87
  /**
75
- * Check input errors
88
+ * Public method to display errors
89
+ *
90
+ * @returns {Promise<void>}
76
91
  */
77
- checkError() {
78
- // Set error message
79
- this.errorMessage = undefined;
80
- // required
81
- if (!this.valid && this.input.validity.valueMissing) {
82
- this.errorMessage = messages.errors.required;
83
- }
84
- // Update class
85
- if (this.valid) {
86
- this.classList.delete(this.classError);
87
- }
88
- else {
89
- this.classList.add(this.classError);
90
- }
92
+ async displayError() {
93
+ this.checkValidity();
94
+ this.checkError();
95
+ this.hasError = this.invalid;
91
96
  }
92
97
  /*************
93
98
  * Lifecycle *
94
99
  *************/
100
+ /**
101
+ * Check if component props are well configured on init
102
+ *
103
+ * @returns {ReturnType<typeof setTimeout>} timeout
104
+ */
95
105
  componentWillLoad() {
106
+ // Get locales
107
+ this.messages = initLocales(this.element).messages;
108
+ // Check validity when component is ready
96
109
  // return a promise to process action only in the FIRST render().
97
110
  // https://stenciljs.com/docs/component-lifecycle#componentwillload
98
- return setTimeout(() => this.checkValidity(), 0);
111
+ return setTimeout(() => {
112
+ this.checkValidity();
113
+ }, 0);
99
114
  }
115
+ /**
116
+ * Render
117
+ *
118
+ * @returns {HTMLElement} HTML Element
119
+ */
100
120
  render() {
101
- 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.value !== undefined ? '•'.repeat(this.value.length) : undefined, tooltip: this.tooltip, displayCharacterLeft: false, characterLeftTemplate: undefined, maxlength: undefined, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false },
121
+ 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.value !== undefined ? '•'.repeat(this.value.length) : undefined, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false },
102
122
  h("input", { type: "password", class: "mg-input__box", value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, ref: el => (this.input = el) })));
103
123
  }
104
124
  static get is() { return "mg-input-password"; }
@@ -136,7 +156,7 @@ export class MgInputPassword {
136
156
  "references": {}
137
157
  },
138
158
  "required": false,
139
- "optional": true,
159
+ "optional": false,
140
160
  "docs": {
141
161
  "tags": [],
142
162
  "text": "Identifier is used for the element ID (id is a reserved prop in Stencil.js)\nIf not set, it will be created."
@@ -154,7 +174,7 @@ export class MgInputPassword {
154
174
  "references": {}
155
175
  },
156
176
  "required": false,
157
- "optional": true,
177
+ "optional": false,
158
178
  "docs": {
159
179
  "tags": [],
160
180
  "text": "Input name\nIf not set the value equals the identifier"
@@ -175,7 +195,7 @@ export class MgInputPassword {
175
195
  "optional": false,
176
196
  "docs": {
177
197
  "tags": [],
178
- "text": "Input label\nRequired"
198
+ "text": "Input label"
179
199
  },
180
200
  "attribute": "label",
181
201
  "reflect": false
@@ -286,7 +306,7 @@ export class MgInputPassword {
286
306
  "reflect": false,
287
307
  "defaultValue": "false"
288
308
  },
289
- "width": {
309
+ "mgWidth": {
290
310
  "type": "any",
291
311
  "mutable": false,
292
312
  "complexType": {
@@ -305,7 +325,7 @@ export class MgInputPassword {
305
325
  "tags": [],
306
326
  "text": "Define input width"
307
327
  },
308
- "attribute": "width",
328
+ "attribute": "mg-width",
309
329
  "reflect": false,
310
330
  "defaultValue": "'full'"
311
331
  },
@@ -355,7 +375,7 @@ export class MgInputPassword {
355
375
  "optional": false,
356
376
  "docs": {
357
377
  "tags": [],
358
- "text": "Define input pattern to validate"
378
+ "text": "Define input valid state"
359
379
  },
360
380
  "attribute": "valid",
361
381
  "reflect": false
@@ -372,7 +392,7 @@ export class MgInputPassword {
372
392
  "optional": false,
373
393
  "docs": {
374
394
  "tags": [],
375
- "text": "Define input pattern error message"
395
+ "text": "Define input invalid state"
376
396
  },
377
397
  "attribute": "invalid",
378
398
  "reflect": false
@@ -390,12 +410,53 @@ export class MgInputPassword {
390
410
  "composed": true,
391
411
  "docs": {
392
412
  "tags": [],
393
- "text": "Emmited event when value change"
413
+ "text": "Emited event when value change"
394
414
  },
395
415
  "complexType": {
396
416
  "original": "string",
397
417
  "resolved": "string",
398
418
  "references": {}
399
419
  }
420
+ }, {
421
+ "method": "inputValid",
422
+ "name": "input-valid",
423
+ "bubbles": true,
424
+ "cancelable": true,
425
+ "composed": true,
426
+ "docs": {
427
+ "tags": [],
428
+ "text": "Emited event when checking validity"
429
+ },
430
+ "complexType": {
431
+ "original": "boolean",
432
+ "resolved": "boolean",
433
+ "references": {}
434
+ }
435
+ }]; }
436
+ static get methods() { return {
437
+ "displayError": {
438
+ "complexType": {
439
+ "signature": "() => Promise<void>",
440
+ "parameters": [],
441
+ "references": {
442
+ "Promise": {
443
+ "location": "global"
444
+ }
445
+ },
446
+ "return": "Promise<void>"
447
+ },
448
+ "docs": {
449
+ "text": "Public method to display errors",
450
+ "tags": [{
451
+ "name": "returns",
452
+ "text": undefined
453
+ }]
454
+ }
455
+ }
456
+ }; }
457
+ static get elementRef() { return "element"; }
458
+ static get watchers() { return [{
459
+ "propName": "value",
460
+ "methodName": "handleValue"
400
461
  }]; }
401
462
  }
@@ -8,12 +8,17 @@ export default {
8
8
  control: { type: 'radio' },
9
9
  },
10
10
  },
11
+ parameters: { actions: { handles: ['value-change', 'input-valid'] } },
11
12
  };
12
13
  /**
13
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}
14
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
15
19
  */
16
- const Template = args => {
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ const Template = (args) => {
17
22
  const labelOnTop = args.labelOnTop;
18
23
  delete args.labelOnTop;
19
24
  const helpText = args.helpText;
@@ -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,17 +80,29 @@
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
  * Manage style when input needs to be a fieldset, like checkbox and radio.
91
101
  */
92
102
  fieldset.mg-input {
93
103
  border: 0;
94
- margin: 0;
104
+ margin-left: 0;
105
+ margin-right: 0;
95
106
  padding: 0;
96
107
  }
97
108
  fieldset.mg-input input[type=radio],
@@ -110,7 +121,7 @@ fieldset.mg-input.mg-input--label-on-top .mg-input__input-group-container {
110
121
  }
111
122
 
112
123
  .mg-input__input-container mg-tooltip {
113
- margin-left: 2rem;
124
+ margin-left: 3rem;
114
125
  }
115
126
 
116
127
  /* input group container */
@@ -133,6 +144,9 @@ fieldset.mg-input.mg-input--label-on-top .mg-input__input-group-container {
133
144
  display: flex;
134
145
  align-items: top;
135
146
  }
147
+ .mg-input__input-group.mg-input__input-group--disabled label {
148
+ opacity: 0.3;
149
+ }
136
150
 
137
151
  /**
138
152
  * A11Y
@@ -1,12 +1,14 @@
1
- import { Component, Event, h, Prop, State, Watch } from '@stencil/core';
1
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ import { Component, Element, Event, h, Prop, State, Watch, Method } from '@stencil/core';
2
4
  import { MgInput } from '../MgInput';
3
5
  import { createID, ClassList, allItemsAreString } from '../../../../utils/components.utils';
4
- import { messages } from '../../../../locales';
5
- import { InputClass } from '../MgInput.conf';
6
+ import { initLocales } from '../../../../locales';
6
7
  /**
7
8
  * type Option validation function
8
- * @param option
9
- * @returns {boolean}
9
+ *
10
+ * @param {RadioOption} option radio option
11
+ * @returns {boolean} radio option type is valid
10
12
  */
11
13
  const isOption = (option) => typeof option === 'object' && typeof option.title === 'string' && option.value !== undefined;
12
14
  export class MgInputRadio {
@@ -14,8 +16,6 @@ export class MgInputRadio {
14
16
  /************
15
17
  * Internal *
16
18
  ************/
17
- // classes
18
- this.classError = InputClass.ERROR;
19
19
  // HTML selector
20
20
  this.inputs = [];
21
21
  /**
@@ -58,25 +58,61 @@ export class MgInputRadio {
58
58
  this.classList = new ClassList(['mg-input--radio']);
59
59
  /**
60
60
  * Handle input event
61
+ *
62
+ * @param {event} event input event
63
+ * @returns {void}
61
64
  */
62
65
  this.handleInput = (event) => {
63
66
  this.checkValidity();
64
67
  this.value = this.options[event.target.value].value;
65
- this.valueChange.emit(this.value);
66
68
  };
67
69
  /**
68
70
  * Handle blur event
71
+ *
72
+ * @returns {void}
69
73
  */
70
74
  this.handleBlur = () => {
71
75
  this.checkValidity();
72
76
  this.checkError();
73
77
  };
78
+ /**
79
+ * Check if input is valid
80
+ *
81
+ * @returns {void}
82
+ */
83
+ this.checkValidity = () => {
84
+ if (!this.readonly) {
85
+ const validity = this.getInvalidElement() === undefined;
86
+ // Set validity
87
+ this.valid = validity;
88
+ this.invalid = !validity;
89
+ //Send event
90
+ this.inputValid.emit(validity);
91
+ }
92
+ };
93
+ /**
94
+ * Check input errors
95
+ *
96
+ * @returns {void}
97
+ */
98
+ this.checkError = () => {
99
+ const invalidElement = this.getInvalidElement();
100
+ // Set error message
101
+ this.errorMessage = undefined;
102
+ if (!this.valid && invalidElement.validity.valueMissing) {
103
+ this.errorMessage = this.messages.errors.required;
104
+ }
105
+ };
74
106
  /**
75
107
  * get invalid element
76
- * @returns element: HTMLInputElement
108
+ *
109
+ * @returns {HTMLInputElement} element
77
110
  */
78
111
  this.getInvalidElement = () => this.inputs.find((element) => !element.disabled && !element.checkValidity());
79
112
  }
113
+ handleValue(newValue) {
114
+ this.valueChange.emit(newValue);
115
+ }
80
116
  validateItems(newValue) {
81
117
  // Validate if items have required min length
82
118
  if (typeof newValue === 'object' && newValue.length < 2) {
@@ -95,47 +131,42 @@ export class MgInputRadio {
95
131
  }
96
132
  }
97
133
  /**
98
- * Check if input is valid
134
+ * Public method to display errors
135
+ *
136
+ * @returns {Promise<void>}
99
137
  */
100
- checkValidity() {
101
- if (!this.readonly) {
102
- const validity = this.getInvalidElement() === undefined;
103
- // Set validity
104
- this.valid = validity;
105
- this.invalid = !validity;
106
- }
107
- }
108
- /**
109
- * Check input errors
110
- */
111
- checkError() {
112
- const invalidElement = this.getInvalidElement();
113
- // Set error message
114
- this.errorMessage = undefined;
115
- if (!this.valid && invalidElement.validity.valueMissing) {
116
- this.errorMessage = messages.errors.required;
117
- }
118
- // Update class
119
- if (this.valid) {
120
- this.classList.delete(this.classError);
121
- }
122
- else {
123
- this.classList.add(this.classError);
124
- }
138
+ async displayError() {
139
+ this.checkValidity();
140
+ this.checkError();
125
141
  }
126
142
  /*************
127
143
  * Lifecycle *
128
144
  *************/
145
+ /**
146
+ * Check if component props are well configured on init
147
+ *
148
+ * @returns {ReturnType<typeof setTimeout>} timeout
149
+ */
129
150
  componentWillLoad() {
130
- // Check items format
151
+ // Get locales
152
+ this.messages = initLocales(this.element).messages;
153
+ // Validate
131
154
  this.validateItems(this.items);
155
+ // Check validity when component is ready
132
156
  // return a promise to process action only in the FIRST render().
133
157
  // https://stenciljs.com/docs/component-lifecycle#componentwillload
134
- return setTimeout(() => this.checkValidity(), 0);
158
+ return setTimeout(() => {
159
+ this.checkValidity();
160
+ }, 0);
135
161
  }
162
+ /**
163
+ * Render
164
+ *
165
+ * @returns {HTMLElement} HTML Element
166
+ */
136
167
  render() {
137
- return (h(MgInput, { identifier: this.identifier, classList: this.classList, label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, disabled: this.disabled, readonly: this.readonly, width: undefined, value: this.value && this.value.toString(), readonlyValue: this.value && this.value.toString(), tooltip: this.tooltip, displayCharacterLeft: undefined, characterLeftTemplate: undefined, maxlength: undefined, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: true },
138
- h("ul", { class: `mg-input__input-group-container${this.inputVerticalList ? ' mg-input__input-group-container--vertical' : ''}` }, this.options.map((input, index) => (h("li", { class: "mg-input__input-group" },
168
+ return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, disabled: this.disabled, readonly: this.readonly, mgWidth: undefined, value: this.value, readonlyValue: this.value, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: true },
169
+ h("ul", { class: { 'mg-input__input-group-container': true, 'mg-input__input-group-container--vertical': this.inputVerticalList } }, this.options.map((input, index) => (h("li", { class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } },
139
170
  h("input", { type: "radio", id: this.identifier + '_' + index, name: this.identifier, value: index, checked: JSON.stringify(this.value) === JSON.stringify(this.options[index].value), disabled: this.disabled || input.disabled, required: this.required, onBlur: this.handleBlur, onInput: this.handleInput, ref: el => this.inputs.push(el) }),
140
171
  h("label", { htmlFor: this.identifier + '_' + index }, input.title)))))));
141
172
  }
@@ -233,7 +264,7 @@ export class MgInputRadio {
233
264
  "optional": false,
234
265
  "docs": {
235
266
  "tags": [],
236
- "text": "Input label\nRequired"
267
+ "text": "Input label"
237
268
  },
238
269
  "attribute": "label",
239
270
  "reflect": false
@@ -392,7 +423,7 @@ export class MgInputRadio {
392
423
  "optional": false,
393
424
  "docs": {
394
425
  "tags": [],
395
- "text": "Force valid component"
426
+ "text": "Define input valid state"
396
427
  },
397
428
  "attribute": "valid",
398
429
  "reflect": false
@@ -409,7 +440,7 @@ export class MgInputRadio {
409
440
  "optional": false,
410
441
  "docs": {
411
442
  "tags": [],
412
- "text": "Force invalid component"
443
+ "text": "Define input invalid state"
413
444
  },
414
445
  "attribute": "invalid",
415
446
  "reflect": false
@@ -435,8 +466,48 @@ export class MgInputRadio {
435
466
  "resolved": "any",
436
467
  "references": {}
437
468
  }
469
+ }, {
470
+ "method": "inputValid",
471
+ "name": "input-valid",
472
+ "bubbles": true,
473
+ "cancelable": true,
474
+ "composed": true,
475
+ "docs": {
476
+ "tags": [],
477
+ "text": "Emited event when checking validity"
478
+ },
479
+ "complexType": {
480
+ "original": "boolean",
481
+ "resolved": "boolean",
482
+ "references": {}
483
+ }
438
484
  }]; }
485
+ static get methods() { return {
486
+ "displayError": {
487
+ "complexType": {
488
+ "signature": "() => Promise<void>",
489
+ "parameters": [],
490
+ "references": {
491
+ "Promise": {
492
+ "location": "global"
493
+ }
494
+ },
495
+ "return": "Promise<void>"
496
+ },
497
+ "docs": {
498
+ "text": "Public method to display errors",
499
+ "tags": [{
500
+ "name": "returns",
501
+ "text": undefined
502
+ }]
503
+ }
504
+ }
505
+ }; }
506
+ static get elementRef() { return "element"; }
439
507
  static get watchers() { return [{
508
+ "propName": "value",
509
+ "methodName": "handleValue"
510
+ }, {
440
511
  "propName": "items",
441
512
  "methodName": "validateItems"
442
513
  }]; }
@@ -1,13 +1,30 @@
1
1
  import { h } from '@stencil/core';
2
+ import messages from '../../../../../locales/en/messages.json';
2
3
  export default {
3
4
  component: 'mg-input-select',
4
5
  title: 'Molecules/Inputs/mg-input-select',
6
+ argTypes: {
7
+ placeholder: {
8
+ table: {
9
+ defaultValue: { summary: messages.input.select.placeholder },
10
+ },
11
+ },
12
+ mgWidth: {
13
+ options: [undefined, 2, 4, 16, 'full'],
14
+ control: { type: 'select' },
15
+ },
16
+ },
17
+ parameters: { actions: { handles: ['value-change', 'input-valid'] } },
5
18
  };
6
19
  /**
7
20
  * 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
21
  * 2. boolean arguments with a default true value must be added like display-character-left={args.displayCharacterLeft ? 'true' : 'false'}
22
+ *
23
+ * @param {any} args component arguments
24
+ * @returns {HTMLElement} HTMLElement
9
25
  */
10
- const Template = args => {
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ const Template = (args) => {
11
28
  const labelOnTop = args.labelOnTop;
12
29
  delete args.labelOnTop;
13
30
  const labelHide = args.labelHide;
@@ -18,8 +35,10 @@ const Template = args => {
18
35
  delete args.placeholderDisabled;
19
36
  const placeholderHide = args.placeholderHide;
20
37
  delete args.placeholderHide;
38
+ const mgWidth = args.mgWidth;
39
+ delete args.mgWidth;
21
40
  // return element
22
- return (h("mg-input-select", Object.assign({}, args, { "label-on-top": labelOnTop, "label-hide": labelHide, "help-text": helpText, "placeholder-hide": placeholderHide, "placeholder-disabled": placeholderDisabled })));
41
+ return (h("mg-input-select", Object.assign({}, args, { "label-on-top": labelOnTop, "label-hide": labelHide, "help-text": helpText, "placeholder-hide": placeholderHide, "placeholder-disabled": placeholderDisabled, "mg-width": mgWidth })));
23
42
  };
24
43
  export const MgInputSelect = Template.bind({});
25
44
  MgInputSelect.args = {
@@ -36,6 +55,7 @@ MgInputSelect.args = {
36
55
  readonly: false,
37
56
  disabled: false,
38
57
  items: ['blu', 'bli', 'blo', 'bla'],
58
+ mgWidth: undefined,
39
59
  // Tooltip
40
60
  tooltip: 'This is a tooltip',
41
61
  // Help Text