@mgdis/mg-components 4.0.1 → 4.1.1

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 (124) hide show
  1. package/dist/.storybook/utils.js +24 -0
  2. package/dist/cjs/{index-a39c5567.js → index-179621c8.js} +11 -0
  3. package/dist/cjs/{index-88560a66.js → index-dd2c7f7b.js} +47 -0
  4. package/dist/cjs/loader.cjs.js +3 -3
  5. package/dist/cjs/{mg-badge_21.cjs.entry.js → mg-badge_24.cjs.entry.js} +2363 -214
  6. package/dist/cjs/mg-components.cjs.js +26 -3
  7. package/dist/cjs/mg-modal.cjs.entry.js +2 -2
  8. package/dist/collection/collection-manifest.json +3 -1
  9. package/dist/collection/components/atoms/mg-badge/doc/mg-badge.stories.js +9 -5
  10. package/dist/collection/components/atoms/mg-button/doc/mg-button.stories.js +15 -12
  11. package/dist/collection/components/atoms/mg-button/mg-button.conf.js +4 -0
  12. package/dist/collection/components/atoms/mg-button/mg-button.js +46 -20
  13. package/dist/collection/components/atoms/mg-character-left/doc/mg-character-left.stories.js +9 -12
  14. package/dist/collection/components/atoms/mg-icon/doc/mg-icon.stories.js +11 -3
  15. package/dist/collection/components/atoms/mg-icon/mg-icon.conf.js +13 -0
  16. package/dist/collection/components/atoms/mg-input-title/doc/mg-input-title.stories.js +9 -9
  17. package/dist/collection/components/atoms/mg-tag/doc/mg-tag.stories.js +9 -7
  18. package/dist/collection/components/atoms/mg-tooltip/doc/mg-tooltip.stories.js +27 -8
  19. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.conf.js +6 -0
  20. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +64 -11
  21. package/dist/collection/components/molecules/inputs/mg-input-checkbox/doc/mg-input-checkbox.stories.js +3 -15
  22. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.css +4 -3
  23. package/dist/collection/components/molecules/inputs/mg-input-date/doc/mg-input-date.stories.js +3 -12
  24. package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.css +4 -3
  25. package/dist/collection/components/molecules/inputs/mg-input-numeric/doc/mg-input-numeric.stories.js +3 -14
  26. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.css +4 -3
  27. package/dist/collection/components/molecules/inputs/mg-input-password/doc/mg-input-password.stories.js +3 -14
  28. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.css +4 -3
  29. package/dist/collection/components/molecules/inputs/mg-input-radio/doc/mg-input-radio.stories.js +3 -14
  30. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.css +4 -3
  31. package/dist/collection/components/molecules/inputs/mg-input-select/doc/mg-input-select.stories.js +3 -16
  32. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.css +4 -3
  33. package/dist/collection/components/molecules/inputs/mg-input-text/doc/mg-input-text.stories.js +11 -22
  34. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.css +4 -3
  35. package/dist/collection/components/molecules/inputs/mg-input-textarea/doc/mg-input-textarea.stories.js +4 -13
  36. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.css +4 -3
  37. package/dist/collection/components/molecules/inputs/mg-input-toggle/doc/mg-input-toggle.stories.js +17 -38
  38. package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.css +4 -3
  39. package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +16 -7
  40. package/dist/collection/components/molecules/mg-details/doc/mg-details.stories.js +25 -0
  41. package/dist/collection/components/molecules/mg-details/mg-details.css +14 -0
  42. package/dist/collection/components/molecules/mg-details/mg-details.js +141 -0
  43. package/dist/collection/components/molecules/mg-form/doc/mg-form.stories.js +9 -6
  44. package/dist/collection/components/molecules/mg-form/mg-form.css +1 -1
  45. package/dist/collection/components/molecules/mg-form/mg-form.js +48 -4
  46. package/dist/collection/components/molecules/mg-illustrated-message/doc/mg-illustrated-message.stories.js +22 -0
  47. package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.css +37 -0
  48. package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js +74 -0
  49. package/dist/collection/components/molecules/mg-message/doc/mg-message.stories.js +9 -15
  50. package/dist/collection/components/molecules/mg-modal/doc/mg-modal.stories.js +23 -31
  51. package/dist/collection/components/molecules/mg-pagination/doc/mg-pagination.stories.js +7 -11
  52. package/dist/collection/components/molecules/mg-panel/doc/mg-panel.stories.js +16 -26
  53. package/dist/collection/components/molecules/mg-panel/mg-panel.js +1 -6
  54. package/dist/collection/components/molecules/mg-popover/doc/mg-popover.stories.js +13 -17
  55. package/dist/collection/components/molecules/mg-popover/mg-popover.css +1 -1
  56. package/dist/collection/components/molecules/mg-popover/mg-popover.js +24 -8
  57. package/dist/collection/components/molecules/mg-tabs/doc/mg-tabs.stories.js +11 -12
  58. package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +14 -14
  59. package/dist/collection/stories/helpers.stories.js +11 -3
  60. package/dist/collection/stories/icons.stories.js +10 -2
  61. package/dist/collection/stories/typography.stories.js +8 -1
  62. package/dist/collection/utils/components.utils.js +10 -0
  63. package/dist/components/components.utils.js +11 -1
  64. package/dist/components/index.d.ts +25 -23
  65. package/dist/components/index.js +2 -0
  66. package/dist/components/mg-button2.js +6 -14
  67. package/dist/components/mg-details.d.ts +11 -0
  68. package/dist/components/mg-details.js +87 -0
  69. package/dist/components/mg-form.js +35 -5
  70. package/dist/components/mg-icon2.js +13 -0
  71. package/dist/components/mg-illustrated-message.d.ts +11 -0
  72. package/dist/components/mg-illustrated-message.js +68 -0
  73. package/dist/components/mg-input-checkbox.js +1 -1
  74. package/dist/components/mg-input-date.js +1 -1
  75. package/dist/components/mg-input-numeric.js +1 -1
  76. package/dist/components/mg-input-password.js +1 -1
  77. package/dist/components/mg-input-radio.js +1 -1
  78. package/dist/components/mg-input-select2.js +1 -1
  79. package/dist/components/mg-input-text2.js +1 -1
  80. package/dist/components/mg-input-textarea.js +1 -1
  81. package/dist/components/mg-input-toggle.js +17 -8
  82. package/dist/components/mg-panel.js +0 -4
  83. package/dist/components/mg-popover.js +10 -9
  84. package/dist/components/mg-tabs.js +5 -4
  85. package/dist/components/mg-tooltip2.js +73 -11
  86. package/dist/esm/{index-e51ae032.js → index-7efedd97.js} +11 -1
  87. package/dist/esm/{index-bca81100.js → index-f58b769f.js} +47 -1
  88. package/dist/esm/loader.js +3 -3
  89. package/dist/esm/{mg-badge_21.entry.js → mg-badge_24.entry.js} +2360 -214
  90. package/dist/esm/mg-components.js +26 -3
  91. package/dist/esm/mg-modal.entry.js +2 -2
  92. package/dist/mg-components/mg-components.css +1 -1
  93. package/dist/mg-components/mg-components.esm.js +1 -1
  94. package/dist/mg-components/{p-462d648a.entry.js → p-2a3d8f60.entry.js} +1 -1
  95. package/dist/mg-components/p-5f89600c.js +1 -0
  96. package/dist/mg-components/p-b6df1cac.js +2 -0
  97. package/dist/mg-components/p-c8779533.entry.js +1 -0
  98. package/dist/types/components/atoms/mg-button/doc/mg-button.stories.d.ts +6 -0
  99. package/dist/types/components/atoms/mg-button/mg-button.conf.d.ts +8 -0
  100. package/dist/types/components/atoms/mg-button/mg-button.d.ts +11 -0
  101. package/dist/types/components/atoms/mg-character-left/doc/mg-character-left.stories.d.ts +0 -10
  102. package/dist/types/components/atoms/mg-tooltip/doc/mg-tooltip.stories.d.ts +1 -6
  103. package/dist/types/components/atoms/mg-tooltip/mg-tooltip.conf.d.ts +5 -0
  104. package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +25 -1
  105. package/dist/types/components/molecules/mg-details/doc/mg-details.stories.d.ts +11 -0
  106. package/dist/types/components/molecules/mg-details/mg-details.d.ts +49 -0
  107. package/dist/types/components/molecules/mg-form/mg-form.d.ts +13 -0
  108. package/dist/types/components/molecules/mg-illustrated-message/doc/mg-illustrated-message.stories.d.ts +6 -0
  109. package/dist/types/components/molecules/mg-illustrated-message/mg-illustrated-message.d.ts +28 -0
  110. package/dist/types/components/molecules/mg-popover/doc/mg-popover.stories.d.ts +4 -1
  111. package/dist/types/components/molecules/mg-popover/mg-popover.d.ts +6 -1
  112. package/dist/types/components.d.ts +95 -0
  113. package/dist/types/home/runner/work/mg-components/mg-components/.stencil/.storybook/utils.d.ts +1 -0
  114. package/dist/types/utils/components.utils.d.ts +8 -0
  115. package/package.json +11 -11
  116. package/dist/cjs/mg-popover.cjs.entry.js +0 -170
  117. package/dist/cjs/popper-71bf3058.js +0 -1790
  118. package/dist/esm/mg-popover.entry.js +0 -166
  119. package/dist/esm/popper-93ecb064.js +0 -1788
  120. package/dist/mg-components/p-4c66f794.js +0 -1
  121. package/dist/mg-components/p-5126ab10.entry.js +0 -1
  122. package/dist/mg-components/p-766c918b.entry.js +0 -1
  123. package/dist/mg-components/p-780bd52d.js +0 -1
  124. package/dist/mg-components/p-b14a3443.js +0 -2
@@ -1,4 +1,5 @@
1
1
  import { h } from '@stencil/core';
2
+ import { filterArgs } from '../../../../../../.storybook/utils';
2
3
  export default {
3
4
  component: 'mg-input-toggle',
4
5
  title: 'Molecules/Inputs/mg-input-toggle',
@@ -29,50 +30,28 @@ const args = {
29
30
  helpText: 'Help text with html <strong>bold</strong>, <em>italic</em>.',
30
31
  };
31
32
  /**
32
- * 1. camelCase arguments must be written in the template, for exemple labelOnTop must be placed in the template as label-on-top={args.labelOnTop}
33
- * 2. boolean arguments with a default true value must be added like display-character-left={args.displayCharacterLeft ? 'true' : 'false'}
33
+ * Template
34
34
  *
35
35
  * @param {any} args component arguments
36
36
  * @returns {HTMLElement} HTMLElement
37
37
  */
38
38
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
- const Template = (args) => {
40
- // Extract slot so it won't be render as an attribute
41
- const labelOnTop = args.labelOnTop;
42
- delete args.labelOnTop;
43
- const labelHide = args.labelHide;
44
- delete args.labelHide;
45
- const isIcon = args.isIcon;
46
- delete args.isIcon;
47
- const isOnOff = args.isOnOff;
48
- delete args.isOnOff;
49
- const helpText = args.helpText;
50
- delete args.helpText;
51
- // return element
52
- return (h("mg-input-toggle", Object.assign({}, args, { "label-on-top": labelOnTop, "label-hide": labelHide, "help-text": helpText, "is-icon": isIcon, "is-on-off": isOnOff }),
53
- h("span", { slot: "item-1" }, "Non"),
54
- h("span", { slot: "item-2" }, "Oui")));
55
- };
39
+ const Template = (args) => (h("mg-input-toggle", Object.assign({}, filterArgs(args)),
40
+ h("span", { slot: "item-1" }, "Non"),
41
+ h("span", { slot: "item-2" }, "Oui")));
56
42
  export const MgInputToggle = Template.bind({});
57
43
  MgInputToggle.args = Object.assign({}, args);
58
- const TemplateIcon = args => {
59
- // Extract slot so it won't be render as an attribute
60
- const labelOnTop = args.labelOnTop;
61
- delete args.labelOnTop;
62
- const helpText = args.helpText;
63
- delete args.helpText;
64
- const labelHide = args.labelHide;
65
- delete args.labelHide;
66
- const isIcon = args.isIcon;
67
- delete args.isIcon;
68
- const isOnOff = args.isOnOff;
69
- delete args.isOnOff;
70
- // return element
71
- return (h("mg-input-toggle", Object.assign({}, args, { "label-on-top": labelOnTop, "label-hide": labelHide, "help-text": helpText, "is-icon": isIcon, "is-on-off": isOnOff }),
72
- h("span", { slot: "item-1" },
73
- h("mg-icon", { icon: "cross" })),
74
- h("span", { slot: "item-2" },
75
- h("mg-icon", { icon: "check" }))));
76
- };
44
+ /**
45
+ * Template
46
+ *
47
+ * @param {any} args component arguments
48
+ * @returns {HTMLElement} HTMLElement
49
+ */
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
+ const TemplateIcon = (args) => (h("mg-input-toggle", Object.assign({}, filterArgs(args)),
52
+ h("span", { slot: "item-1" },
53
+ h("mg-icon", { icon: "cross" })),
54
+ h("span", { slot: "item-2" },
55
+ h("mg-icon", { icon: "check" }))));
77
56
  export const MgInputToggleWithIcon = TemplateIcon.bind({});
78
57
  MgInputToggleWithIcon.args = Object.assign(Object.assign({}, args), { isIcon: true, isOnOff: true });
@@ -64,9 +64,6 @@
64
64
  height: var(--mg-icon-regular-size);
65
65
  margin-left: var(--mg-inputs-spacer);
66
66
  }
67
- .mg-input__input-container mg-icon {
68
- display: flex;
69
- }
70
67
  .mg-input__input-container .mg-input__help-text,
71
68
  .mg-input__input-container .mg-input__error {
72
69
  text-align: start;
@@ -96,6 +93,10 @@
96
93
  color: hsl(var(--color-danger));
97
94
  }
98
95
 
96
+ .mg-input__input mg-icon, .mg-input__error mg-icon {
97
+ display: flex;
98
+ }
99
+
99
100
  /**
100
101
  * A11Y
101
102
  */
@@ -145,14 +145,23 @@ export class MgInputToggle {
145
145
  * @returns {void}
146
146
  */
147
147
  setChecked() {
148
- // has "value" props type is not a boolean, it is bind/render as an attributes/props
149
- // true props will be represent by "true" string so we convert it has boolean
150
- // true attribute will be represent by "" string so we convert it has boolean
151
- // https://stenciljs.com/docs/properties
152
- if (['', 'true'].includes(this.value) && this.options.find(option => option.value) !== undefined) {
153
- this.value = true;
148
+ const optionTrueValueIndex = this.options.map(option => option.value).findIndex(value => value === true);
149
+ if ([0, 1].includes(optionTrueValueIndex)) {
150
+ // has "value" props type is not a boolean, it is bind/render as an attributes/props
151
+ // true props will be represent by "true" string so we convert it has boolean
152
+ // true attribute will be represent by "" string so we convert it has boolean
153
+ // https://stenciljs.com/docs/properties
154
+ if (['', 'true'].includes(this.value) && this.options.find(option => option.value) !== undefined) {
155
+ this.value = true;
156
+ }
157
+ // when options are boolean values and ordered as [true,false] instead [false,true]
158
+ // we need to reversed the checked value logic
159
+ const selectedValue = this.value === this.options[optionTrueValueIndex].value;
160
+ this.checked = optionTrueValueIndex === 0 ? !selectedValue : selectedValue;
161
+ }
162
+ else {
163
+ this.checked = this.value === this.options[1].value;
154
164
  }
155
- this.checked = this.value === this.options[1].value;
156
165
  }
157
166
  /*************
158
167
  * Lifecycle *
@@ -0,0 +1,25 @@
1
+ import { h } from '@stencil/core';
2
+ import { filterArgs } from '../../../../../.storybook/utils';
3
+ export default {
4
+ component: 'mg-details',
5
+ title: 'Molecules/mg-details',
6
+ parameters: { actions: { handles: ['expanded-change'] } },
7
+ };
8
+ /**
9
+ * Template
10
+ *
11
+ * @param {any} args component arguments
12
+ * @returns {HTMLElement} HTMLElement
13
+ */
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ const Template = (args) => (h("mg-details", Object.assign({}, filterArgs(args)),
16
+ args.slotSummary && h("span", { slot: "summary", innerHTML: args.slotSummary }),
17
+ args.slotDetails && h("p", { slot: "details", innerHTML: args.slotDetails })));
18
+ export const MgDetails = Template.bind({});
19
+ MgDetails.args = {
20
+ slotSummary: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
21
+ slotDetails: 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
22
+ toggleClosed: 'Show details',
23
+ toggleOpened: 'Hide details',
24
+ expanded: false,
25
+ };
@@ -0,0 +1,14 @@
1
+ .mg-details summary {
2
+ display: flex;
3
+ align-items: baseline;
4
+ cursor: pointer;
5
+ }
6
+
7
+ .mg-details__toggle {
8
+ margin-left: 1.5rem;
9
+ flex-shrink: 0;
10
+ }
11
+
12
+ .mg-details__details {
13
+ margin-top: 1.5rem;
14
+ }
@@ -0,0 +1,141 @@
1
+ import { Component, Event, h, Prop, Watch } from '@stencil/core';
2
+ export class MgDetails {
3
+ constructor() {
4
+ /**
5
+ * Define if details are diplayed
6
+ */
7
+ this.expanded = false;
8
+ /**
9
+ * Handle details toggle
10
+ *
11
+ * @returns {void}
12
+ */
13
+ this.handleToggle = () => {
14
+ this.expanded = this.details.open;
15
+ };
16
+ }
17
+ validateTitles(newValue) {
18
+ if (newValue === undefined || newValue === '') {
19
+ throw new Error('<mg-details> prop "toggleClosed" and "toggleOpened" must be defined.');
20
+ }
21
+ }
22
+ handleExpanded(newValue) {
23
+ this.expandedChange.emit(newValue);
24
+ }
25
+ /*************
26
+ * Lifecycle *
27
+ *************/
28
+ /**
29
+ * Check if component props are well configured on init
30
+ *
31
+ * @returns {void}
32
+ */
33
+ componentWillLoad() {
34
+ this.validateTitles(this.toggleClosed);
35
+ this.validateTitles(this.toggleOpened);
36
+ }
37
+ /**
38
+ * Render
39
+ *
40
+ * @returns {HTMLElement} HTML Element
41
+ */
42
+ render() {
43
+ return (h("details", { class: "mg-details", onToggle: this.handleToggle, open: this.expanded, ref: el => (this.details = el) },
44
+ h("summary", null,
45
+ h("slot", { name: "summary" }),
46
+ h("span", { class: "mg-details__toggle" },
47
+ h("mg-icon", { icon: this.expanded ? 'chevron-up' : 'chevron-down' }),
48
+ " ",
49
+ this.expanded ? this.toggleOpened : this.toggleClosed)),
50
+ h("div", { class: "mg-details__details" },
51
+ h("slot", { name: "details" }))));
52
+ }
53
+ static get is() { return "mg-details"; }
54
+ static get encapsulation() { return "shadow"; }
55
+ static get originalStyleUrls() { return {
56
+ "$": ["mg-details.scss"]
57
+ }; }
58
+ static get styleUrls() { return {
59
+ "$": ["mg-details.css"]
60
+ }; }
61
+ static get properties() { return {
62
+ "toggleClosed": {
63
+ "type": "string",
64
+ "mutable": false,
65
+ "complexType": {
66
+ "original": "string",
67
+ "resolved": "string",
68
+ "references": {}
69
+ },
70
+ "required": false,
71
+ "optional": false,
72
+ "docs": {
73
+ "tags": [],
74
+ "text": "Displayed title when details are closed"
75
+ },
76
+ "attribute": "toggle-closed",
77
+ "reflect": false
78
+ },
79
+ "toggleOpened": {
80
+ "type": "string",
81
+ "mutable": false,
82
+ "complexType": {
83
+ "original": "string",
84
+ "resolved": "string",
85
+ "references": {}
86
+ },
87
+ "required": false,
88
+ "optional": false,
89
+ "docs": {
90
+ "tags": [],
91
+ "text": "Displayed title when details are opened"
92
+ },
93
+ "attribute": "toggle-opened",
94
+ "reflect": false
95
+ },
96
+ "expanded": {
97
+ "type": "boolean",
98
+ "mutable": true,
99
+ "complexType": {
100
+ "original": "boolean",
101
+ "resolved": "boolean",
102
+ "references": {}
103
+ },
104
+ "required": false,
105
+ "optional": false,
106
+ "docs": {
107
+ "tags": [],
108
+ "text": "Define if details are diplayed"
109
+ },
110
+ "attribute": "expanded",
111
+ "reflect": false,
112
+ "defaultValue": "false"
113
+ }
114
+ }; }
115
+ static get events() { return [{
116
+ "method": "expandedChange",
117
+ "name": "expanded-change",
118
+ "bubbles": true,
119
+ "cancelable": true,
120
+ "composed": true,
121
+ "docs": {
122
+ "tags": [],
123
+ "text": "Emmited event when expanded change"
124
+ },
125
+ "complexType": {
126
+ "original": "boolean",
127
+ "resolved": "boolean",
128
+ "references": {}
129
+ }
130
+ }]; }
131
+ static get watchers() { return [{
132
+ "propName": "toggleClosed",
133
+ "methodName": "validateTitles"
134
+ }, {
135
+ "propName": "toggleOpened",
136
+ "methodName": "validateTitles"
137
+ }, {
138
+ "propName": "expanded",
139
+ "methodName": "handleExpanded"
140
+ }]; }
141
+ }
@@ -1,8 +1,9 @@
1
1
  import { h } from '@stencil/core';
2
+ import { filterArgs } from '../../../../../.storybook/utils';
2
3
  export default {
3
4
  component: 'mg-form',
4
5
  title: 'Molecules/mg-form',
5
- parameters: { actions: { handles: ['form-valid'] } },
6
+ parameters: { actions: { handles: ['form-valid', 'form-submit'] } },
6
7
  };
7
8
  const args = {
8
9
  identifier: 'identifier',
@@ -11,8 +12,7 @@ const args = {
11
12
  disabled: false,
12
13
  };
13
14
  /**
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}
15
- * 2. boolean arguments with a default true value must be added like display-character-left={args.displayCharacterLeft ? 'true' : 'false'}
15
+ * Template
16
16
  *
17
17
  * @param {any} args component arguments
18
18
  * @returns {HTMLElement} HTMLElement
@@ -21,17 +21,20 @@ const args = {
21
21
  const Template = (args) => {
22
22
  let form;
23
23
  let submit;
24
- return (h("mg-form", Object.assign({}, args, { ref: el => {
24
+ return (h("mg-form", Object.assign({}, filterArgs(args), { ref: el => {
25
25
  form = el;
26
26
  form.addEventListener('form-valid', e => {
27
27
  submit.disabled = !e.detail;
28
28
  });
29
+ form.addEventListener('form-submit', () => {
30
+ window.alert('Your form has been submitted');
31
+ });
29
32
  } }),
30
33
  h("mg-input-checkbox", { identifier: "mg-input-checkbox", label: "mg-input-checkbox label", value: [
31
34
  { title: 'oui', value: false },
32
35
  { title: 'non', value: false },
33
36
  ] }),
34
- h("mg-input-date", { required: true, identifier: "mg-input-date", label: "mg-input-date label" }),
37
+ h("mg-input-date", Object.assign({}, filterArgs({ required: true }), { identifier: "mg-input-date", label: "mg-input-date label" })),
35
38
  h("mg-input-numeric", { identifier: "mg-input-numeric", label: "mg-input-numeric label" }),
36
39
  h("mg-input-password", { identifier: "mg-input-password", label: "mg-input-password label" }),
37
40
  h("mg-input-radio", { identifier: "mg-input-radio", label: "mg-input-radio label", items: ['blu', 'bli', 'bla', 'blo'] }),
@@ -48,7 +51,7 @@ const Template = (args) => {
48
51
  h("mg-button", { id: "can-submit", disabled: true, ref: e => {
49
52
  submit = e;
50
53
  } }, "Submit"),
51
- h("mg-button", { variant: "secondary",
54
+ h("mg-button", { variant: "secondary", type: "button",
52
55
  // eslint-disable-next-line react/jsx-no-bind
53
56
  onClick: () => {
54
57
  form.displayError();
@@ -4,9 +4,9 @@
4
4
 
5
5
  .mg-form,
6
6
  .mg-form-group {
7
+ --mg-inputs-title-width: var(--mg-form-inputs-title-width, 15rem);
7
8
  --mg-inputs-margin-bottom: 1.5rem;
8
9
  --mg-inputs-title-horizontal-space: 3rem;
9
- --mg-inputs-title-width: 15rem;
10
10
  --mg-inputs-shrink: 0;
11
11
  }
12
12
  .mg-form.mg-form--all-required,
@@ -56,6 +56,10 @@ export class MgForm {
56
56
  this.invalid = !validity;
57
57
  this.formValid.emit(validity);
58
58
  };
59
+ this.handleFormSubmit = (event) => {
60
+ event.preventDefault();
61
+ this.formSubmit.emit();
62
+ };
59
63
  }
60
64
  /**
61
65
  * Public method to display errors
@@ -81,11 +85,17 @@ export class MgForm {
81
85
  componentWillLoad() {
82
86
  // Get locales
83
87
  this.messages = initLocales(this.element).messages;
84
- // Get slotted mgIputs
88
+ // Get slotted mgInputs
85
89
  this.mgInputs = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-INPUT-'));
90
+ // Get slotted mgButtons
91
+ this.mgButtons = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-BUTTON'));
92
+ // Set button form identifier
93
+ this.mgButtons.forEach(mgButton => {
94
+ mgButton.setAttribute('form', this.identifier);
95
+ });
86
96
  // Define required message
87
97
  this.setRequiredMessage();
88
- // Check validity when slotted mgImputs are ready
98
+ // Check validity when slotted mgInputs are ready
89
99
  Promise.all(this.mgInputs.map(async (input) => {
90
100
  // Set inputs readonly or disabled based on form configuration
91
101
  // Othewise listen to events
@@ -95,18 +105,37 @@ export class MgForm {
95
105
  input.disabled = true;
96
106
  else
97
107
  input.addEventListener('input-valid', this.checkValidity);
98
- await input.componentOnReady();
108
+ try {
109
+ await input.componentOnReady();
110
+ }
111
+ catch (_a) { } // prevent error with VueJS first render
99
112
  })).then(() => {
100
113
  this.checkValidity();
101
114
  });
102
115
  }
116
+ /**
117
+ * Add slot listeners
118
+ *
119
+ * @returns {void}
120
+ */
121
+ componentDidLoad() {
122
+ this.mgButtons.forEach(mgButton => {
123
+ // submit buttons should trigger form submition
124
+ const button = mgButton.querySelector('button');
125
+ if (['submit', null].includes(button.getAttribute('type'))) {
126
+ mgButton.addEventListener('click', () => {
127
+ this.form.dispatchEvent(new CustomEvent('submit', { bubbles: true }));
128
+ });
129
+ }
130
+ });
131
+ }
103
132
  /**
104
133
  * Render
105
134
  *
106
135
  * @returns {HTMLElement} HTML Element
107
136
  */
108
137
  render() {
109
- return (h("form", { class: this.classList.join(), id: this.identifier, name: this.name },
138
+ return (h("form", { class: this.classList.join(), id: this.identifier, name: this.name, ref: el => (this.form = el), onSubmit: this.handleFormSubmit },
110
139
  this.requiredMessage && h("p", { innerHTML: this.requiredMessage }),
111
140
  h("slot", null),
112
141
  !this.readonly && !this.disabled && h("slot", { name: "actions" })));
@@ -245,6 +274,21 @@ export class MgForm {
245
274
  "resolved": "boolean",
246
275
  "references": {}
247
276
  }
277
+ }, {
278
+ "method": "formSubmit",
279
+ "name": "form-submit",
280
+ "bubbles": true,
281
+ "cancelable": true,
282
+ "composed": true,
283
+ "docs": {
284
+ "tags": [],
285
+ "text": "Emitted event on form submit"
286
+ },
287
+ "complexType": {
288
+ "original": "boolean",
289
+ "resolved": "boolean",
290
+ "references": {}
291
+ }
248
292
  }]; }
249
293
  static get methods() { return {
250
294
  "displayError": {
@@ -0,0 +1,22 @@
1
+ import { h } from '@stencil/core';
2
+ export default {
3
+ component: 'mg-illustrated-message',
4
+ title: 'Molecules/mg-illustrated-message',
5
+ };
6
+ /**
7
+ * 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
+ * 2. boolean arguments with a default true value must be added like display-character-left={args.displayCharacterLeft ? 'true' : 'false'}
9
+ */
10
+ const Template = args => {
11
+ // return element
12
+ return (h("mg-illustrated-message", Object.assign({}, args),
13
+ h("svg", { slot: "illustration", width: "190", height: "350", viewBox: "0 0 190 350", xmlns: "http://www.w3.org/2000/svg" },
14
+ h("path", { "fill-rule": "evenodd", "clip-rule": "evenodd", d: "M0 0H15C23.2843 0 30 6.71573 30 15V290H40V15C40 6.71573 46.7157 0 55 0C63.2843 0 70 6.71573 70 15V275C70 277.761 67.7615 280 65 280H60V40H50V340H60V290H65C67.7615 290 70 292.239 70 295V340H80V295C80 291.158 78.5558 287.654 76.1805 285C78.5558 282.346 80 278.842 80 275V0H95C103.284 0 110 6.71573 110 15V25C110 28.8418 108.556 32.3462 106.181 35C108.556 37.6538 110 41.1582 110 45V305C110 307.761 107.761 310 105 310H100V45C100 42.2386 97.7615 40 95 40H90V325C90 333.284 96.7157 340 105 340H120V330H105C102.239 330 100 327.761 100 325V320H105C113.284 320 120 313.284 120 305V15C120 6.71573 126.716 0 135 0C143.284 0 150 6.71573 150 15V330H140V15C140 12.2386 137.761 10 135 10C132.239 10 130 12.2386 130 15V340H165C173.284 340 180 333.284 180 325V15C180 12.2386 177.761 10 175 10H170V325C170 327.761 167.761 330 165 330H160V0H175C183.284 0 190 6.71573 190 15V350H0V0ZM10 325C10 333.284 16.7157 340 25 340C33.2843 340 40 333.284 40 325V300H30V325C30 327.761 27.7615 330 25 330C22.2385 330 20 327.761 20 325V15C20 12.2386 17.7615 10 15 10H10V325ZM60 15V30H50V15C50 12.2386 52.2385 10 55 10C57.7615 10 60 12.2386 60 15ZM95 30H90V10H95C97.7615 10 100 12.2386 100 15V25C100 27.7614 97.7615 30 95 30Z", fill: "black" })),
15
+ h("h2", { slot: "title" }, "Lorem Ipsum"),
16
+ h("h3", { slot: "details" }, "The standard Lorem Ipsum passage, used since the 1500s"),
17
+ h("div", { slot: "details" }, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")));
18
+ };
19
+ export const MgIllustratedMessage = Template.bind({});
20
+ MgIllustratedMessage.args = {
21
+ size: 'regular',
22
+ };
@@ -0,0 +1,37 @@
1
+ .mg-illustrated-message {
2
+ margin: auto;
3
+ padding: 0 1.5rem;
4
+ max-width: 47.5rem;
5
+ box-sizing: border-box;
6
+ text-align: center;
7
+ }
8
+
9
+ .mg-illustrated-message__illustration {
10
+ max-height: 33.5rem;
11
+ }
12
+ .mg-illustrated-message__illustration ::slotted([slot=illustration]) {
13
+ width: auto;
14
+ height: auto;
15
+ max-width: 100%;
16
+ max-height: 33.5rem;
17
+ }
18
+ .mg-illustrated-message__illustration.mg-illustrated-message__illustration--small {
19
+ max-height: 6rem;
20
+ }
21
+ .mg-illustrated-message__illustration.mg-illustrated-message__illustration--small ::slotted([slot=illustration]) {
22
+ max-height: 6rem;
23
+ }
24
+
25
+ .mg-illustrated-message__title {
26
+ margin: 3rem 0 0;
27
+ }
28
+ .mg-illustrated-message__title ::slotted([slot=title]) {
29
+ margin: 0;
30
+ font-size: 2rem !important;
31
+ font-family: var(--font-family) !important;
32
+ font-weight: 400;
33
+ }
34
+
35
+ .mg-illustrated-message__details ::slotted([slot=details]) {
36
+ margin: 2rem 0 0;
37
+ }
@@ -0,0 +1,74 @@
1
+ import { Component, Element, h, Prop } from '@stencil/core';
2
+ import { isTagName } from '../../../utils/components.utils';
3
+ export class MgIllustratedMessage {
4
+ constructor() {
5
+ /**
6
+ * Define illustration size
7
+ */
8
+ this.size = 'regular';
9
+ }
10
+ /*************
11
+ * Lifecycle *
12
+ *************/
13
+ /**
14
+ * Check if component props are well configured on init
15
+ *
16
+ * @returns {void}
17
+ */
18
+ componentDidLoad() {
19
+ const headingTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
20
+ const imageTags = ['img', 'svg'];
21
+ if (!isTagName(this.element.querySelector('[slot="title"]'), headingTags)) {
22
+ throw new Error(`<mg-illustrated-message> Slotted title must be a heading: ${headingTags.join(', ')}`);
23
+ }
24
+ else if (!isTagName(this.element.querySelector('[slot="illustration"]'), imageTags)) {
25
+ throw new Error(`<mg-illustrated-message> Slotted illustration must be an image: ${imageTags.join(', ')}`);
26
+ }
27
+ }
28
+ /**
29
+ * Render
30
+ *
31
+ * @returns {HTMLElement} HTML Element
32
+ */
33
+ render() {
34
+ return (h("div", { class: "mg-illustrated-message" },
35
+ h("div", { class: {
36
+ 'mg-illustrated-message__illustration': true,
37
+ 'mg-illustrated-message__illustration--small': this.size === 'small',
38
+ } },
39
+ h("slot", { name: "illustration" })),
40
+ h("div", { class: "mg-illustrated-message__title" },
41
+ h("slot", { name: "title" })),
42
+ h("div", { class: "mg-illustrated-message__details" },
43
+ h("slot", { name: "details" }))));
44
+ }
45
+ static get is() { return "mg-illustrated-message"; }
46
+ static get encapsulation() { return "shadow"; }
47
+ static get originalStyleUrls() { return {
48
+ "$": ["mg-illustrated-message.scss"]
49
+ }; }
50
+ static get styleUrls() { return {
51
+ "$": ["mg-illustrated-message.css"]
52
+ }; }
53
+ static get properties() { return {
54
+ "size": {
55
+ "type": "string",
56
+ "mutable": false,
57
+ "complexType": {
58
+ "original": "'regular' | 'small'",
59
+ "resolved": "\"regular\" | \"small\"",
60
+ "references": {}
61
+ },
62
+ "required": false,
63
+ "optional": false,
64
+ "docs": {
65
+ "tags": [],
66
+ "text": "Define illustration size"
67
+ },
68
+ "attribute": "size",
69
+ "reflect": false,
70
+ "defaultValue": "'regular'"
71
+ }
72
+ }; }
73
+ static get elementRef() { return "element"; }
74
+ }
@@ -1,4 +1,5 @@
1
1
  import { h } from '@stencil/core';
2
+ import { filterArgs } from '../../../../../.storybook/utils';
2
3
  import { variants } from '../mg-message.conf';
3
4
  export default {
4
5
  component: 'mg-message',
@@ -15,22 +16,15 @@ export default {
15
16
  parameters: { actions: { handles: ['component-show', 'component-hide'] } },
16
17
  };
17
18
  /**
18
- * 1. camelCase arguments must be written in the template, for exemple labelOnTop must be placed in the template as label-on-top={args.labelOnTop}
19
- * 2. boolean arguments with a default true value must be added like display-character-left={args.displayCharacterLeft ? 'true' : 'false'}
19
+ * Template
20
+ *
21
+ * @param {any} args component arguments
22
+ * @returns {HTMLElement} HTMLElement
20
23
  */
21
- const Template = args => {
22
- // Extract slot so it won't be render as an attribute
23
- const slotContent = args.slotContent;
24
- delete args.slotContent;
25
- const slotActions = args.slotActions;
26
- delete args.slotActions;
27
- const closeButton = args.closeButton;
28
- delete args.closeButton;
29
- // return element
30
- return (h("mg-message", Object.assign({}, args, { "close-button": closeButton }),
31
- slotContent && h("span", { innerHTML: slotContent }),
32
- slotActions && h("span", { slot: "actions", innerHTML: slotActions })));
33
- };
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ const Template = (args) => (h("mg-message", Object.assign({}, filterArgs(args, { variant: variants[0] })),
26
+ args.slotContent && h("span", { innerHTML: args.slotContent }),
27
+ args.slotActions && h("span", { slot: "actions", innerHTML: args.slotActions })));
34
28
  export const MgMessage = Template.bind({});
35
29
  MgMessage.args = {
36
30
  slotContent: `<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>`,