@mgdis/mg-components 5.0.0 → 5.2.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 (120) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/{mg-badge_24.cjs.entry.js → mg-badge_27.cjs.entry.js} +892 -295
  3. package/dist/cjs/mg-components.cjs.js +1 -1
  4. package/dist/collection/collection-manifest.json +2 -0
  5. package/dist/collection/components/atoms/mg-badge/mg-badge.js +1 -1
  6. package/dist/collection/components/atoms/mg-button/doc/mg-button.stories.js +1 -0
  7. package/dist/collection/components/atoms/mg-button/mg-button.css +8 -0
  8. package/dist/collection/components/atoms/mg-button/mg-button.js +41 -3
  9. package/dist/collection/components/atoms/mg-card/doc/mg-card.stories.js +18 -0
  10. package/dist/collection/components/atoms/mg-card/mg-card.css +7 -0
  11. package/dist/collection/components/atoms/mg-card/mg-card.js +26 -0
  12. package/dist/collection/components/atoms/mg-divider/doc/mg-divider.stories.js +18 -0
  13. package/dist/collection/components/atoms/mg-divider/mg-divider.css +9 -0
  14. package/dist/collection/components/atoms/mg-divider/mg-divider.js +57 -0
  15. package/dist/collection/components/atoms/mg-tag/mg-tag.js +1 -1
  16. package/dist/collection/components/atoms/mg-tooltip/doc/mg-tooltip.stories.js +0 -5
  17. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.conf.js +0 -20
  18. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.css +1 -1
  19. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +2 -1
  20. package/dist/collection/components/molecules/inputs/MgInput.js +3 -11
  21. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +41 -20
  22. package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +50 -39
  23. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.css +25 -6
  24. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +42 -33
  25. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.css +25 -6
  26. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +36 -17
  27. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +35 -14
  28. package/dist/collection/components/molecules/inputs/mg-input-select/doc/mg-input-select.stories.js +2 -3
  29. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.css +28 -6
  30. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +36 -17
  31. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.css +25 -6
  32. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +38 -19
  33. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.css +25 -6
  34. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +37 -18
  35. package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +1 -1
  36. package/dist/collection/components/molecules/mg-details/doc/mg-details.stories.js +1 -0
  37. package/dist/collection/components/molecules/mg-details/mg-details.css +29 -0
  38. package/dist/collection/components/molecules/mg-details/mg-details.js +26 -4
  39. package/dist/collection/components/molecules/mg-form/mg-form.js +73 -27
  40. package/dist/collection/components/molecules/mg-illustrated-message/doc/mg-illustrated-message.stories.js +6 -6
  41. package/dist/collection/components/molecules/mg-message/mg-message.js +1 -1
  42. package/dist/collection/components/molecules/mg-modal/mg-modal.css +2 -1
  43. package/dist/collection/components/molecules/mg-modal/mg-modal.js +48 -4
  44. package/dist/collection/components/molecules/mg-panel/mg-panel.css +5 -14
  45. package/dist/collection/components/molecules/mg-popover/doc/mg-popover.stories.js +0 -5
  46. package/dist/collection/components/molecules/mg-popover/mg-popover.css +1 -1
  47. package/dist/collection/components/molecules/mg-popover/mg-popover.js +3 -2
  48. package/dist/collection/utils/components.utils.js +10 -6
  49. package/dist/collection/utils/unit.test.utils.js +51 -0
  50. package/dist/collection/variables.css +23 -8
  51. package/dist/components/MgInput.js +4 -12
  52. package/dist/components/components.utils.js +11 -7
  53. package/dist/components/index.d.ts +2 -0
  54. package/dist/components/index.js +2 -0
  55. package/dist/components/mg-badge2.js +1 -1
  56. package/dist/components/mg-button2.js +23 -4
  57. package/dist/components/mg-card.d.ts +11 -0
  58. package/dist/components/mg-card.js +42 -0
  59. package/dist/components/mg-details.js +8 -3
  60. package/dist/components/mg-divider.d.ts +11 -0
  61. package/dist/components/mg-divider.js +51 -0
  62. package/dist/components/mg-form.js +67 -26
  63. package/dist/components/mg-input-checkbox.js +36 -21
  64. package/dist/components/mg-input-date.js +44 -39
  65. package/dist/components/mg-input-numeric.js +37 -34
  66. package/dist/components/mg-input-password.js +32 -19
  67. package/dist/components/mg-input-radio.js +30 -15
  68. package/dist/components/mg-input-select2.js +32 -19
  69. package/dist/components/mg-input-text2.js +34 -21
  70. package/dist/components/mg-input-textarea.js +32 -19
  71. package/dist/components/mg-input-toggle.js +1 -1
  72. package/dist/components/mg-message.js +1 -1
  73. package/dist/components/mg-modal.js +49 -5
  74. package/dist/components/mg-panel.js +1 -1
  75. package/dist/components/mg-popover.js +3 -2
  76. package/dist/components/mg-tag.js +1 -1
  77. package/dist/components/mg-tooltip2.js +2 -4
  78. package/dist/esm/loader.js +1 -1
  79. package/dist/esm/{mg-badge_24.entry.js → mg-badge_27.entry.js} +839 -245
  80. package/dist/esm/mg-components.js +1 -1
  81. package/dist/mg-components/mg-components.css +1 -1
  82. package/dist/mg-components/mg-components.esm.js +1 -1
  83. package/dist/mg-components/p-b2b07c3f.entry.js +1 -0
  84. package/dist/mg-components/variables.css +23 -8
  85. package/dist/types/components/atoms/mg-button/mg-button.d.ts +8 -2
  86. package/dist/types/components/atoms/mg-card/doc/mg-card.stories.d.ts +6 -0
  87. package/dist/types/components/atoms/mg-card/mg-card.d.ts +11 -0
  88. package/dist/types/components/atoms/mg-divider/doc/mg-divider.stories.d.ts +6 -0
  89. package/dist/types/components/atoms/mg-divider/mg-divider.d.ts +15 -0
  90. package/dist/types/components/atoms/mg-tooltip/doc/mg-tooltip.stories.d.ts +0 -6
  91. package/dist/types/components/atoms/mg-tooltip/mg-tooltip.conf.d.ts +0 -8
  92. package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +1 -1
  93. package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +10 -8
  94. package/dist/types/components/molecules/inputs/mg-input-date/mg-input-date.d.ts +3 -8
  95. package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +3 -8
  96. package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.d.ts +4 -3
  97. package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.d.ts +4 -2
  98. package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.d.ts +4 -3
  99. package/dist/types/components/molecules/inputs/mg-input-text/mg-input-text.d.ts +5 -4
  100. package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.d.ts +4 -3
  101. package/dist/types/components/molecules/mg-details/mg-details.d.ts +4 -0
  102. package/dist/types/components/molecules/mg-form/mg-form.d.ts +21 -1
  103. package/dist/types/components/molecules/mg-message/mg-message.d.ts +3 -0
  104. package/dist/types/components/molecules/mg-modal/mg-modal.d.ts +11 -0
  105. package/dist/types/components/molecules/mg-popover/doc/mg-popover.stories.d.ts +0 -6
  106. package/dist/types/components/molecules/mg-popover/mg-popover.d.ts +1 -1
  107. package/dist/types/components.d.ts +55 -6
  108. package/dist/types/utils/components.utils.d.ts +7 -3
  109. package/package.json +9 -9
  110. package/dist/cjs/index-179621c8.js +0 -244
  111. package/dist/cjs/mg-modal.cjs.entry.js +0 -128
  112. package/dist/collection/components/molecules/mg-popover/mg-popover.conf.js +0 -20
  113. package/dist/collection/utils/test.utils.js +0 -38
  114. package/dist/esm/index-7efedd97.js +0 -238
  115. package/dist/esm/mg-modal.entry.js +0 -124
  116. package/dist/mg-components/p-5f89600c.js +0 -1
  117. package/dist/mg-components/p-b60a4c53.entry.js +0 -1
  118. package/dist/mg-components/p-df947fa5.entry.js +0 -1
  119. package/dist/types/components/molecules/mg-popover/mg-popover.conf.d.ts +0 -8
  120. package/dist/types/utils/test.utils.d.ts +0 -17
@@ -3,6 +3,8 @@ import { createID, ClassList } from '../../../utils/components.utils';
3
3
  import { initLocales } from '../../../locales';
4
4
  export class MgForm {
5
5
  constructor() {
6
+ // Classes
7
+ this.classAllRequired = 'mg-form--all-required';
6
8
  /**
7
9
  * Identifier is used for the element ID (id is a reserved prop in Stencil.js)
8
10
  * If not set, it will be created.
@@ -32,17 +34,24 @@ export class MgForm {
32
34
  * @returns {void}
33
35
  */
34
36
  this.setRequiredMessage = () => {
35
- // Get required fields
36
- const requiredInputs = this.mgInputs.filter(input => input.required && !input.disabled && !this.disabled);
37
- // All fields are required
38
- // mg-input-toggle can not be required
39
- if (requiredInputs.length > 0 && requiredInputs.length === this.mgInputs.filter(input => input.nodeName !== 'MG-INPUT-TOGGLE').length) {
40
- this.requiredMessage = this.messages.form.allRequired;
41
- this.classList.add('mg-form--all-required');
42
- }
43
- // Some fields are required
44
- else if (requiredInputs.length > 0) {
45
- this.requiredMessage = this.messages.form.required;
37
+ // init required message
38
+ this.requiredMessage = null;
39
+ this.classList.delete(this.classAllRequired);
40
+ // If the form is disabled or readonly none of them are required
41
+ // Check if all fields are not editable (readonly or disabled)
42
+ if (!this.disabled && !this.readonly && !this.mgInputs.every(input => input.disabled || input.readonly)) {
43
+ // Get required fields
44
+ const requiredInputs = this.mgInputs.filter(input => input.required && !input.disabled && !input.readonly);
45
+ // All fields are required
46
+ // mg-input-toggle can not be required
47
+ if (requiredInputs.length > 0 && requiredInputs.length === this.mgInputs.filter(input => input.nodeName !== 'MG-INPUT-TOGGLE').length) {
48
+ this.requiredMessage = this.messages.form.allRequired;
49
+ this.classList.add(this.classAllRequired);
50
+ }
51
+ // Some fields are required
52
+ else if (requiredInputs.length > 0) {
53
+ this.requiredMessage = this.messages.form.required;
54
+ }
46
55
  }
47
56
  };
48
57
  /**
@@ -51,15 +60,46 @@ export class MgForm {
51
60
  * @returns {void}
52
61
  */
53
62
  this.checkValidity = () => {
54
- const validity = !this.mgInputs.some(input => input.invalid);
55
- this.valid = validity;
56
- this.invalid = !validity;
57
- this.formValid.emit(validity);
63
+ // Update required on input event
64
+ this.setRequiredMessage();
65
+ this.valid = !this.mgInputs.some(input => input.invalid);
66
+ this.invalid = !this.valid;
67
+ // We need to send valid event if it is the same value
68
+ this.formValid.emit(this.valid);
58
69
  };
70
+ /**
71
+ * Handle Form Submit
72
+ *
73
+ * @param {SubmitEvent} event submit event
74
+ * @returns {void}
75
+ */
59
76
  this.handleFormSubmit = (event) => {
60
77
  event.preventDefault();
61
78
  this.formSubmit.emit();
62
79
  };
80
+ /**
81
+ * Set mgInputs
82
+ *
83
+ * @returns {void}
84
+ */
85
+ this.setMgInputs = () => {
86
+ // Get slotted mgInputs
87
+ this.mgInputs = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-INPUT-'));
88
+ // Set inputs readonly or disabled based on form configuration
89
+ // Othewise listen to events
90
+ this.mgInputs.map(input => {
91
+ if (this.readonly)
92
+ input.readonly = true;
93
+ else if (this.disabled)
94
+ input.disabled = true;
95
+ else
96
+ input.addEventListener('input-valid', this.checkValidity);
97
+ });
98
+ };
99
+ }
100
+ handleAttributeChange() {
101
+ this.setMgInputs();
102
+ this.setRequiredMessage();
63
103
  }
64
104
  /**
65
105
  * Public method to display errors
@@ -85,26 +125,18 @@ export class MgForm {
85
125
  componentWillLoad() {
86
126
  // Get locales
87
127
  this.messages = initLocales(this.element).messages;
88
- // Get slotted mgInputs
89
- this.mgInputs = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-INPUT-'));
90
128
  // Get slotted mgButtons
91
- this.mgButtons = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-BUTTON'));
129
+ this.mgButtons = Array.from(this.element.querySelectorAll('mg-button'));
92
130
  // Set button form identifier
93
131
  this.mgButtons.forEach(mgButton => {
94
132
  mgButton.setAttribute('form', this.identifier);
95
133
  });
134
+ // Set mgInputs
135
+ this.setMgInputs();
96
136
  // Define required message
97
137
  this.setRequiredMessage();
98
138
  // Check validity when slotted mgInputs are ready
99
139
  Promise.all(this.mgInputs.map(async (input) => {
100
- // Set inputs readonly or disabled based on form configuration
101
- // Othewise listen to events
102
- if (this.readonly)
103
- input.readonly = true;
104
- else if (this.disabled)
105
- input.disabled = true;
106
- else
107
- input.addEventListener('input-valid', this.checkValidity);
108
140
  try {
109
141
  await input.componentOnReady();
110
142
  }
@@ -127,6 +159,10 @@ export class MgForm {
127
159
  });
128
160
  }
129
161
  });
162
+ // Update mgInputs when mgForm content change
163
+ new MutationObserver(() => {
164
+ this.setMgInputs();
165
+ }).observe(this.element, { childList: true });
130
166
  }
131
167
  /**
132
168
  * Render
@@ -260,7 +296,8 @@ export class MgForm {
260
296
  }
261
297
  static get states() {
262
298
  return {
263
- "classList": {}
299
+ "classList": {},
300
+ "requiredMessage": {}
264
301
  };
265
302
  }
266
303
  static get events() {
@@ -320,4 +357,13 @@ export class MgForm {
320
357
  };
321
358
  }
322
359
  static get elementRef() { return "element"; }
360
+ static get watchers() {
361
+ return [{
362
+ "propName": "readonly",
363
+ "methodName": "handleAttributeChange"
364
+ }, {
365
+ "propName": "disabled",
366
+ "methodName": "handleAttributeChange"
367
+ }];
368
+ }
323
369
  }
@@ -5,13 +5,13 @@ export default {
5
5
  title: 'Molecules/mg-illustrated-message',
6
6
  };
7
7
  /**
8
- * 1. camelCase arguments must be written in the template, for exemple labelOnTop must be placed in the template as label-on-top={args.labelOnTop}
9
- * 2. boolean arguments with a default true value must be added like display-character-left={args.displayCharacterLeft ? 'true' : 'false'}
8
+ * Template
9
+ *
10
+ * @param {any} args component arguments
11
+ * @returns {HTMLElement} HTMLElement
10
12
  */
11
- const Template = args => {
12
- // return element
13
- return (h("mg-illustrated-message", Object.assign({}, filterArgs(args, { size: 'regular', direction: 'vertical' })), h("svg", { slot: "illustration", width: "190", height: "350", viewBox: "0 0 190 350", xmlns: "http://www.w3.org/2000/svg" }, 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" })), h("h2", { slot: "title" }, "Lorem Ipsum"), h("h3", { slot: "details" }, "The standard Lorem Ipsum passage, used since the 1500s"), 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.")));
14
- };
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ const Template = (args) => (h("mg-illustrated-message", Object.assign({}, filterArgs(args, { size: 'regular', direction: 'vertical' })), h("svg", { slot: "illustration", width: "190", height: "350", viewBox: "0 0 190 350", xmlns: "http://www.w3.org/2000/svg" }, 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" })), h("h2", { slot: "title" }, "Lorem Ipsum"), h("h3", { slot: "details" }, "The standard Lorem Ipsum passage, used since the 1500s"), 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.")));
15
15
  export const MgIllustratedMessage = Template.bind({});
16
16
  MgIllustratedMessage.args = {
17
17
  size: 'regular',
@@ -7,7 +7,7 @@ export class MgMessage {
7
7
  /************
8
8
  * Internal *
9
9
  ************/
10
- // classes
10
+ // Classes
11
11
  this.classHide = 'mg-message--hide';
12
12
  // IDs
13
13
  this.closeButtonId = '';
@@ -7,12 +7,13 @@
7
7
  right: 0;
8
8
  bottom: 0;
9
9
  left: 0;
10
- z-index: 1000;
10
+ z-index: 2000;
11
11
  padding: 2rem 0;
12
12
  background-color: hsla(var(--color-light), 85%);
13
13
  }
14
14
  .mg-modal__dialog {
15
15
  display: flex;
16
+ position: relative;
16
17
  flex-direction: column;
17
18
  align-self: center;
18
19
  row-gap: 3rem;
@@ -1,11 +1,8 @@
1
1
  import { h } from '@stencil/core';
2
- import { createID, ClassList } from '../../../utils/components.utils';
2
+ import { createID, ClassList, focusableElements } from '../../../utils/components.utils';
3
3
  import { initLocales } from '../../../locales';
4
4
  export class MgModal {
5
5
  constructor() {
6
- /************
7
- * Internal *
8
- ************/
9
6
  // Classes
10
7
  this.classHide = 'mg-modal--hide';
11
8
  // IDs
@@ -36,6 +33,37 @@ export class MgModal {
36
33
  * Component classes
37
34
  */
38
35
  this.classList = new ClassList(['mg-modal']);
36
+ this.setFocus = () => {
37
+ // Get all focusable elements
38
+ this.modalFocusableElements = Array.from(this.element.querySelectorAll(focusableElements)).reduce((acc, focusableElement) => {
39
+ acc.push(focusableElement.shadowRoot !== null ? focusableElement.shadowRoot.querySelector(focusableElements) || focusableElement : focusableElement);
40
+ return acc;
41
+ }, []);
42
+ // When close button is enabled it's the first focusable element.
43
+ if (this.closeButton) {
44
+ this.modalFocusableElements.unshift(this.element.shadowRoot.querySelector(`.mg-modal__close-button mg-button`));
45
+ }
46
+ // It at least one
47
+ if (this.modalFocusableElements.length >= 1) {
48
+ // Set focus on first element
49
+ this.modalFocusableElements[0].focus();
50
+ // Add event listener on last element
51
+ const lastFocusableElement = this.modalFocusableElements[this.modalFocusableElements.length - 1];
52
+ lastFocusableElement.addEventListener('keydown', event => {
53
+ if (event.key === 'Tab' && !event.shiftKey) {
54
+ event.preventDefault();
55
+ this.modalFocusableElements[0].focus();
56
+ }
57
+ });
58
+ // Add event listener on first element (case shift + tab)
59
+ this.modalFocusableElements[0].addEventListener('keydown', event => {
60
+ if (event.key === 'Tab' && event.shiftKey) {
61
+ event.preventDefault();
62
+ lastFocusableElement.focus();
63
+ }
64
+ });
65
+ }
66
+ };
39
67
  /*************
40
68
  * Handlers *
41
69
  *************/
@@ -100,6 +128,22 @@ export class MgModal {
100
128
  this.validateModalTitle(this.modalTitle);
101
129
  this.validateHide(this.hide);
102
130
  }
131
+ /**
132
+ * Add observer on component to set focus when displayed
133
+ *
134
+ * @returns {void}
135
+ */
136
+ componentDidLoad() {
137
+ new MutationObserver(mutationList => {
138
+ if (mutationList.some(mutation => mutation.attributeName === 'aria-hidden' && mutation.target.ariaHidden === null)) {
139
+ this.setFocus();
140
+ }
141
+ }).observe(this.element.shadowRoot.getElementById(this.identifier), { attributes: true });
142
+ // Set focus if display on load
143
+ if (!this.hide) {
144
+ this.setFocus();
145
+ }
146
+ }
103
147
  /**
104
148
  * Render
105
149
  *
@@ -1,9 +1,8 @@
1
1
  .mg-panel {
2
2
  background-color: hsl(var(--mg-panel-background));
3
3
  border-radius: var(--mg-panel-border-radius);
4
- box-shadow: var(--box-shadow);
4
+ box-shadow: var(--mg-panel-box-shadow);
5
5
  }
6
-
7
6
  .mg-panel__header {
8
7
  display: flex;
9
8
  flex-wrap: wrap;
@@ -11,22 +10,14 @@
11
10
  padding: 0 1rem 0 0.3rem;
12
11
  align-items: flex-start;
13
12
  }
14
-
15
- .mg-panel__header-left,
16
- .mg-panel__header-right {
13
+ .mg-panel__header-left, .mg-panel__header-right {
17
14
  display: flex;
18
15
  margin: 0.3rem 0;
19
16
  }
20
-
21
- .mg-panel__header-left--full {
22
- flex: 1 1 auto;
23
- }
24
-
25
17
  .mg-panel__header-right {
26
18
  padding-left: 0.3rem;
27
19
  flex: 1 auto;
28
20
  }
29
-
30
21
  .mg-panel__header-left mg-input-text {
31
22
  flex-grow: 1;
32
23
  margin-left: 0.3rem;
@@ -34,16 +25,16 @@
34
25
  .mg-panel__header-left mg-button + mg-button:not([slot=append-input]) {
35
26
  margin-left: 0.3rem;
36
27
  }
37
-
28
+ .mg-panel__header-left.mg-panel__header-left--full {
29
+ flex: 1 1 auto;
30
+ }
38
31
  .mg-panel__collapse-button-content {
39
32
  --font-size: 1.4rem;
40
33
  --mg-button-font-weight: 600;
41
34
  }
42
-
43
35
  .mg-panel__content {
44
36
  padding: var(--mg-panel-content-padding);
45
37
  }
46
-
47
38
  .mg-panel ::slotted([slot=header-right]) {
48
39
  display: flex;
49
40
  flex-wrap: wrap;
@@ -1,6 +1,5 @@
1
1
  import { h } from '@stencil/core';
2
2
  import { filterArgs } from '../../../../../.storybook/utils';
3
- import { placements } from '../mg-popover.conf';
4
3
  export default {
5
4
  component: 'mg-popover',
6
5
  title: 'Molecules/mg-popover',
@@ -11,11 +10,7 @@ export default {
11
10
  },
12
11
  argTypes: {
13
12
  placement: {
14
- options: placements,
15
13
  control: { type: 'select' },
16
- table: {
17
- defaultValue: { summary: 'bottom' },
18
- },
19
14
  },
20
15
  },
21
16
  };
@@ -8,7 +8,7 @@ mg-popover::slotted(*) {
8
8
  .mg-popover {
9
9
  display: none;
10
10
  padding: 1.5rem;
11
- z-index: 9999;
11
+ z-index: 1000;
12
12
  border-radius: 0.5rem;
13
13
  background-color: hsl(var(--mg-popover-background-color));
14
14
  box-shadow: var(--box-shadow);
@@ -123,6 +123,7 @@ export class MgPopover {
123
123
  // Create popperjs popover
124
124
  this.popper = createPopper(interactiveElement, this.popover, {
125
125
  placement: this.placement,
126
+ strategy: 'fixed',
126
127
  modifiers: [
127
128
  {
128
129
  name: 'offset',
@@ -150,7 +151,7 @@ export class MgPopover {
150
151
  * @returns {HTMLElement} HTML Element
151
152
  */
152
153
  render() {
153
- return (h(Host, null, h("slot", null), h("div", { id: this.identifier, class: "mg-popover" }, !this.disabled && this.closeButton && (h("mg-button", { identifier: this.closeButtonId, "is-icon": true, variant: "flat", label: this.messages.general.close, onClick: this.handleCloseButton }, h("mg-icon", { icon: "cross" }))), h("div", { class: "mg-popover__title" }, h("slot", { name: "title" })), h("slot", { name: "content" }), h("div", { class: "mg-popover__arrow", "data-popper-arrow": true }))));
154
+ return (h(Host, null, h("slot", null), h("div", { id: this.identifier, class: "mg-popover" }, this.closeButton && (h("mg-button", { identifier: this.closeButtonId, "is-icon": true, variant: "flat", label: this.messages.general.close, onClick: this.handleCloseButton }, h("mg-icon", { icon: "cross" }))), h("div", { class: "mg-popover__title" }, h("slot", { name: "title" })), h("slot", { name: "content" }), h("div", { class: "mg-popover__arrow", "data-popper-arrow": true }))));
154
155
  }
155
156
  static get is() { return "mg-popover"; }
156
157
  static get encapsulation() { return "shadow"; }
@@ -193,7 +194,7 @@ export class MgPopover {
193
194
  "references": {
194
195
  "Placement": {
195
196
  "location": "import",
196
- "path": "./mg-popover.conf"
197
+ "path": "@popperjs/core"
197
198
  }
198
199
  }
199
200
  },
@@ -5,7 +5,7 @@
5
5
  * @param {number} length ID length
6
6
  * @returns {string} ID
7
7
  */
8
- export function createID(prefix = '', length = 10) {
8
+ export const createID = (prefix = '', length = 10) => {
9
9
  let ID = '';
10
10
  const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
11
11
  const charsLength = chars.length;
@@ -13,7 +13,7 @@ export function createID(prefix = '', length = 10) {
13
13
  ID += chars.charAt(Math.floor(Math.random() * charsLength));
14
14
  }
15
15
  return (prefix !== '' ? `${prefix}-` : '') + ID;
16
- }
16
+ };
17
17
  /**
18
18
  * Class to manage component classlist
19
19
  * Set() are not working when imported in project
@@ -69,9 +69,9 @@ export class ClassList {
69
69
  * @param {string[]} items items to check
70
70
  * @returns {boolean} all items are string
71
71
  */
72
- export function allItemsAreString(items) {
72
+ export const allItemsAreString = (items) => {
73
73
  return items && items.every(item => typeof item === 'string');
74
- }
74
+ };
75
75
  /**
76
76
  * Check if element is a heading
77
77
  *
@@ -79,6 +79,10 @@ export function allItemsAreString(items) {
79
79
  * @param {string[]} tagNames allowed tag names list
80
80
  * @returns {boolean} element is a heading
81
81
  */
82
- export function isTagName(element, tagNames) {
82
+ export const isTagName = (element, tagNames) => {
83
83
  return tagNames.includes(element === null || element === void 0 ? void 0 : element.tagName.toLowerCase());
84
- }
84
+ };
85
+ /**
86
+ * Focusable elements query selector
87
+ */
88
+ export const focusableElements = 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"]), [identifier]';
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Clone Deep function
3
+ *
4
+ * @param {unknown} obj object to clone
5
+ * @returns {unknown} cloned json
6
+ */
7
+ export const cloneDeep = (obj) => JSON.parse(JSON.stringify(obj));
8
+ /**
9
+ * Utility function that mocks the `MutationObserver` API. Recommended to execute inside `beforeEach`.
10
+ *
11
+ * @param mutationObserverMock - Parameter that is sent to the `Object.defineProperty`
12
+ * overwrite method. `jest.fn()` mock functions can be passed here if the goal is to not only
13
+ * mock the resize observer, but its methods.
14
+ * You can manually fire an intersection entry:
15
+ * @param {Function} mutationObserverMock.disconnect disconnect function
16
+ * @param {Function} mutationObserverMock.observe observe fnuction
17
+ * @param {Function} mutationObserverMock.takeRecords takeRecords fnuction
18
+ * @returns {MutationObserver} Mocked MutationObserver
19
+ * @example
20
+ * ```
21
+ * let fireMo;
22
+ * setupMutationObserverMock({
23
+ * observe: function () {
24
+ * fireMo = this.cb;
25
+ * },
26
+ * });
27
+ * ...
28
+ * fireMo([{ type: 'childList', addedNodes: [AMockElemenet, AnotherMockElemenet], target: yourMockElemenet }]);;
29
+ * ```
30
+ */
31
+ export const setupMutationObserverMock = ({ disconnect, observe, takeRecords }) => {
32
+ class MockMutationObserver {
33
+ constructor(fn) {
34
+ this.disconnect = disconnect;
35
+ this.observe = observe;
36
+ this.takeRecords = takeRecords;
37
+ this.cb = fn;
38
+ }
39
+ }
40
+ Object.defineProperty(window, 'MutationObserver', {
41
+ writable: true,
42
+ configurable: true,
43
+ value: MockMutationObserver,
44
+ });
45
+ Object.defineProperty(global, 'MutationObserver', {
46
+ writable: true,
47
+ configurable: true,
48
+ value: MockMutationObserver,
49
+ });
50
+ return MockMutationObserver;
51
+ };
@@ -77,15 +77,15 @@
77
77
  --color-light: var(--color-light-h), var(--color-light-s), var(--color-light-l);
78
78
 
79
79
  /* Primary */
80
- --color-primary-h: hsl(var(--color-dark-h));
81
- --color-primary-s: hsl(var(--color-dark-s));
82
- --color-primary-l: hsl(var(--color-dark-l));
80
+ --color-primary-h: var(--color-dark-h);
81
+ --color-primary-s: var(--color-dark-s);
82
+ --color-primary-l: var(--color-dark-l);
83
83
  --color-primary: hsl(var(--color-dark));
84
84
 
85
85
  /* Secondary */
86
- --color-secondary-h: hsl(var(--color-neutral-h));
87
- --color-secondary-s: hsl(var(--color-neutral-s));
88
- --color-secondary-l: hsl(var(--color-neutral-l));
86
+ --color-secondary-h: var(--color-neutral-h);
87
+ --color-secondary-s: var(--color-neutral-s);
88
+ --color-secondary-l: var(--color-neutral-l);
89
89
  --color-secondary: hsl(var(--color-neutral));
90
90
 
91
91
  /* Shadow */
@@ -168,17 +168,32 @@
168
168
  /*
169
169
  <mg-panel>
170
170
  */
171
-
172
171
  --mg-panel-border-radius: 0.5rem;
173
172
  --mg-panel-background: var(--color-info-h) var(--color-info-s) calc(var(--color-info-l) + 68%);
173
+ --mg-panel-box-shadow: var(--box-shadow);
174
174
  --mg-panel-content-padding: 1.5rem;
175
175
 
176
176
  /*
177
177
  <mg-illustrated-message>
178
178
  */
179
-
180
179
  --mg-illustrated-message-padding-vertical: 4rem;
181
180
 
181
+ /*
182
+ <mg-card>
183
+ */
184
+ --mg-card-padding: 1.6rem;
185
+ --mg-card-border-radius: 0.5rem;
186
+ --mg-card-background: hsl(var(--color-light));
187
+ --mg-card-border: 0.1rem solid hsla(var(--color-dark), 5%);
188
+ --mg-card-box-shadow: var(--box-shadow);
189
+
190
+ /*
191
+ <mg-divider>
192
+ */
193
+ --mg-divider-background-color: hsla(var(--color-dark), 15%);
194
+ --mg-divider-thickness: 0.1rem;
195
+ --mg-divider-vertical-spacing: 4rem;
196
+
182
197
  /*
183
198
  Layout
184
199
  */
@@ -77,15 +77,6 @@ const MgInput = (props, children, utils) => {
77
77
  if (typeof props.errorMessage === 'string' && props.errorMessage !== '') {
78
78
  ariaDescribedbyIDs.add(helpTextErrorId);
79
79
  }
80
- /**
81
- * Update input(s) in children
82
- */
83
- if (props.readonly) {
84
- children = children.filter(child => child.$name$ === 'append-input');
85
- }
86
- else {
87
- children = applyAriadescribedBy(children, ariaDescribedbyIDs, utils);
88
- }
89
80
  /**
90
81
  * Return template
91
82
  *
@@ -111,19 +102,20 @@ const MgInput = (props, children, utils) => {
111
102
  h("mg-icon", { icon: "info-circle" })));
112
103
  /**
113
104
  * Get input title (label) node
105
+ * Display asterisk only if not disabled and not readonly
114
106
  *
115
107
  * @returns {VNode[]} mg-input-title
116
108
  */
117
- const getInputTitle = () => (h("mg-input-title", { identifier: props.identifier, class: props.labelHide ? 'sr-only' : undefined, required: props.required && !props.disabled, "is-legend": props.isFieldset }, props.label));
109
+ const getInputTitle = () => (h("mg-input-title", { identifier: props.identifier, class: props.labelHide ? 'sr-only' : undefined, required: props.required && !props.disabled && !props.readonly, "is-legend": props.isFieldset }, props.label));
118
110
  return (h(TagName, { class: props.classList.join() },
119
111
  props.labelOnTop ? (h("div", { class: "mg-input__title" },
120
112
  getInputTitle(),
121
113
  !props.readonly && props.tooltip && getTooltip())) : (getInputTitle()),
122
114
  props.readonly ? (h("div", { class: "mg-input__input-container" },
123
115
  h("strong", null, props.readonlyValue || props.value),
124
- children)) : (h("div", { class: "mg-input__input-container" },
116
+ children.filter(child => child.$name$ === 'append-input'))) : (h("div", { class: "mg-input__input-container" },
125
117
  h("div", { class: { 'mg-input__input': true, 'mg-input__input--has-error': props.errorMessage !== undefined } },
126
- children,
118
+ applyAriadescribedBy(children, ariaDescribedbyIDs, utils),
127
119
  !props.labelOnTop && props.tooltip && getTooltip()),
128
120
  props.helpText && h("div", { id: helpTextId, class: "mg-input__help-text", innerHTML: props.helpText }),
129
121
  props.errorMessage && !props.readonly && !props.disabled && (h("div", { id: helpTextErrorId, class: "mg-input__error", innerHTML: props.errorMessage, "aria-live": "assertive" }))))));
@@ -5,7 +5,7 @@
5
5
  * @param {number} length ID length
6
6
  * @returns {string} ID
7
7
  */
8
- function createID(prefix = '', length = 10) {
8
+ const createID = (prefix = '', length = 10) => {
9
9
  let ID = '';
10
10
  const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
11
11
  const charsLength = chars.length;
@@ -13,7 +13,7 @@ function createID(prefix = '', length = 10) {
13
13
  ID += chars.charAt(Math.floor(Math.random() * charsLength));
14
14
  }
15
15
  return (prefix !== '' ? `${prefix}-` : '') + ID;
16
- }
16
+ };
17
17
  /**
18
18
  * Class to manage component classlist
19
19
  * Set() are not working when imported in project
@@ -69,9 +69,9 @@ class ClassList {
69
69
  * @param {string[]} items items to check
70
70
  * @returns {boolean} all items are string
71
71
  */
72
- function allItemsAreString(items) {
72
+ const allItemsAreString = (items) => {
73
73
  return items && items.every(item => typeof item === 'string');
74
- }
74
+ };
75
75
  /**
76
76
  * Check if element is a heading
77
77
  *
@@ -79,8 +79,12 @@ function allItemsAreString(items) {
79
79
  * @param {string[]} tagNames allowed tag names list
80
80
  * @returns {boolean} element is a heading
81
81
  */
82
- function isTagName(element, tagNames) {
82
+ const isTagName = (element, tagNames) => {
83
83
  return tagNames.includes(element === null || element === void 0 ? void 0 : element.tagName.toLowerCase());
84
- }
84
+ };
85
+ /**
86
+ * Focusable elements query selector
87
+ */
88
+ const focusableElements = 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"]), [identifier]';
85
89
 
86
- export { ClassList as C, allItemsAreString as a, createID as c, isTagName as i };
90
+ export { ClassList as C, allItemsAreString as a, createID as c, focusableElements as f, isTagName as i };
@@ -1,8 +1,10 @@
1
1
  /* MgComponents custom elements */
2
2
  export { MgBadge as MgBadge } from '../types/components/atoms/mg-badge/mg-badge';
3
3
  export { MgButton as MgButton } from '../types/components/atoms/mg-button/mg-button';
4
+ export { MgCard as MgCard } from '../types/components/atoms/mg-card/mg-card';
4
5
  export { MgCharacterLeft as MgCharacterLeft } from '../types/components/atoms/mg-character-left/mg-character-left';
5
6
  export { MgDetails as MgDetails } from '../types/components/molecules/mg-details/mg-details';
7
+ export { MgDivider as MgDivider } from '../types/components/atoms/mg-divider/mg-divider';
6
8
  export { MgForm as MgForm } from '../types/components/molecules/mg-form/mg-form';
7
9
  export { MgIcon as MgIcon } from '../types/components/atoms/mg-icon/mg-icon';
8
10
  export { MgIllustratedMessage as MgIllustratedMessage } from '../types/components/molecules/mg-illustrated-message/mg-illustrated-message';
@@ -1,8 +1,10 @@
1
1
  export { setAssetPath, setPlatformOptions } from '@stencil/core/internal/client';
2
2
  export { MgBadge, defineCustomElement as defineCustomElementMgBadge } from './mg-badge.js';
3
3
  export { MgButton, defineCustomElement as defineCustomElementMgButton } from './mg-button.js';
4
+ export { MgCard, defineCustomElement as defineCustomElementMgCard } from './mg-card.js';
4
5
  export { MgCharacterLeft, defineCustomElement as defineCustomElementMgCharacterLeft } from './mg-character-left.js';
5
6
  export { MgDetails, defineCustomElement as defineCustomElementMgDetails } from './mg-details.js';
7
+ export { MgDivider, defineCustomElement as defineCustomElementMgDivider } from './mg-divider.js';
6
8
  export { MgForm, defineCustomElement as defineCustomElementMgForm } from './mg-form.js';
7
9
  export { MgIcon, defineCustomElement as defineCustomElementMgIcon } from './mg-icon.js';
8
10
  export { MgIllustratedMessage, defineCustomElement as defineCustomElementMgIllustratedMessage } from './mg-illustrated-message.js';