@mgdis/mg-components 5.9.1 → 5.10.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.
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/mg-action-more_31.cjs.entry.js +345 -648
- package/dist/cjs/mg-components.cjs.js +1 -1
- package/dist/cjs/mg-item-more.cjs.entry.js +19 -43
- package/dist/cjs/{mg-menu.conf-9afe6571.js → mg-menu.conf-196151fe.js} +16 -21
- package/dist/collection/components/atoms/mg-badge/mg-badge.js +9 -12
- package/dist/collection/components/atoms/mg-button/mg-button.js +18 -27
- package/dist/collection/components/atoms/mg-card/mg-card.js +22 -15
- package/dist/collection/components/atoms/mg-character-left/mg-character-left.js +1 -4
- package/dist/collection/components/atoms/mg-divider/mg-divider.js +1 -2
- package/dist/collection/components/atoms/mg-icon/mg-icon.js +26 -23
- package/dist/collection/components/atoms/mg-input-title/mg-input-title.js +1 -4
- package/dist/collection/components/atoms/mg-tag/mg-tag.js +11 -16
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +12 -34
- package/dist/collection/components/molecules/inputs/MgInput.conf.js +4 -1
- package/dist/collection/components/molecules/inputs/MgInput.js +26 -24
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +10 -20
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +7 -17
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +14 -34
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +6 -13
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +10 -27
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +21 -45
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +17 -43
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +14 -22
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +17 -28
- package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js +11 -29
- package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js +20 -47
- package/dist/collection/components/molecules/mg-action-more/mg-action-more.js +11 -23
- package/dist/collection/components/molecules/mg-details/mg-details.js +1 -6
- package/dist/collection/components/molecules/mg-form/mg-form.js +8 -27
- package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js +1 -4
- package/dist/collection/components/molecules/mg-item-more/mg-item-more.js +4 -12
- package/dist/collection/components/molecules/mg-message/mg-message.js +12 -20
- package/dist/collection/components/molecules/mg-modal/mg-modal.js +8 -17
- package/dist/collection/components/molecules/mg-pagination/mg-pagination.js +11 -19
- package/dist/collection/components/molecules/mg-panel/mg-panel.js +11 -30
- package/dist/collection/components/molecules/mg-popover/mg-popover.js +8 -21
- package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js +3 -8
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +20 -36
- package/dist/collection/locales/index.js +2 -3
- package/dist/collection/utils/behaviors.utils.js +16 -32
- package/dist/collection/utils/components.utils.js +22 -33
- package/dist/collection/utils/locale.utils.js +14 -18
- package/dist/collection/utils/unit.test.utils.js +7 -15
- package/dist/components/MgInput.js +30 -24
- package/dist/components/components.utils.js +22 -33
- package/dist/components/index2.js +16 -21
- package/dist/components/mg-action-more.js +9 -21
- package/dist/components/mg-badge2.js +9 -12
- package/dist/components/mg-button2.js +18 -27
- package/dist/components/mg-card2.js +20 -13
- package/dist/components/mg-character-left2.js +1 -4
- package/dist/components/mg-details.js +1 -6
- package/dist/components/mg-divider.js +1 -2
- package/dist/components/mg-form.js +7 -23
- package/dist/components/mg-icon2.js +26 -23
- package/dist/components/mg-illustrated-message.js +1 -4
- package/dist/components/mg-input-checkbox.js +9 -16
- package/dist/components/mg-input-date.js +6 -13
- package/dist/components/mg-input-numeric.js +13 -30
- package/dist/components/mg-input-password.js +5 -9
- package/dist/components/mg-input-radio.js +9 -23
- package/dist/components/mg-input-select2.js +20 -41
- package/dist/components/mg-input-text2.js +15 -35
- package/dist/components/mg-input-textarea.js +13 -18
- package/dist/components/mg-input-title2.js +1 -4
- package/dist/components/mg-input-toggle.js +16 -24
- package/dist/components/mg-item-more.js +18 -42
- package/dist/components/mg-menu-item2.js +17 -44
- package/dist/components/mg-menu2.js +9 -27
- package/dist/components/mg-message.js +12 -20
- package/dist/components/mg-modal.js +8 -17
- package/dist/components/mg-pagination.js +11 -19
- package/dist/components/mg-panel.js +11 -30
- package/dist/components/mg-popover2.js +8 -21
- package/dist/components/mg-skip-links.js +3 -8
- package/dist/components/mg-tabs.js +20 -36
- package/dist/components/mg-tag.js +11 -16
- package/dist/components/mg-tooltip2.js +12 -34
- package/dist/esm/loader.js +1 -1
- package/dist/esm/mg-action-more_31.entry.js +345 -648
- package/dist/esm/mg-components.js +1 -1
- package/dist/esm/mg-item-more.entry.js +19 -43
- package/dist/esm/{mg-menu.conf-881fbd82.js → mg-menu.conf-9ca023ee.js} +16 -21
- package/dist/mg-components/mg-components.esm.js +1 -1
- package/dist/mg-components/{p-67ce7cb8.entry.js → p-97aaca3e.entry.js} +1 -1
- package/dist/mg-components/p-d891e707.entry.js +1 -0
- package/dist/types/components/atoms/mg-badge/mg-badge.d.ts +2 -5
- package/dist/types/components/atoms/mg-button/mg-button.d.ts +5 -14
- package/dist/types/components/atoms/mg-card/mg-card.d.ts +11 -8
- package/dist/types/components/atoms/mg-character-left/mg-character-left.d.ts +1 -4
- package/dist/types/components/atoms/mg-divider/mg-divider.d.ts +1 -2
- package/dist/types/components/atoms/mg-icon/mg-icon.d.ts +8 -7
- package/dist/types/components/atoms/mg-input-title/mg-input-title.d.ts +1 -4
- package/dist/types/components/atoms/mg-tag/mg-tag.d.ts +3 -8
- package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +11 -33
- package/dist/types/components/molecules/inputs/MgInput.conf.d.ts +2 -1
- package/dist/types/components/molecules/inputs/MgInput.d.ts +5 -6
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +5 -11
- package/dist/types/components/molecules/inputs/mg-input-date/mg-input-date.d.ts +4 -11
- package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +7 -26
- package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.d.ts +3 -7
- package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.d.ts +5 -18
- package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.conf.d.ts +2 -2
- package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.d.ts +9 -22
- package/dist/types/components/molecules/inputs/mg-input-text/mg-input-text.d.ts +3 -23
- package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.d.ts +4 -9
- package/dist/types/components/molecules/inputs/mg-input-toggle/mg-input-toggle.d.ts +2 -11
- package/dist/types/components/molecules/menu/mg-menu/mg-menu.d.ts +10 -29
- package/dist/types/components/molecules/menu/mg-menu-item/mg-menu-item.d.ts +21 -49
- package/dist/types/components/molecules/mg-action-more/mg-action-more.d.ts +3 -15
- package/dist/types/components/molecules/mg-details/mg-details.d.ts +1 -6
- package/dist/types/components/molecules/mg-form/mg-form.d.ts +3 -19
- package/dist/types/components/molecules/mg-illustrated-message/mg-illustrated-message.d.ts +1 -4
- package/dist/types/components/molecules/mg-item-more/mg-item-more.d.ts +2 -12
- package/dist/types/components/molecules/mg-message/mg-message.d.ts +4 -12
- package/dist/types/components/molecules/mg-modal/mg-modal.d.ts +3 -12
- package/dist/types/components/molecules/mg-pagination/mg-pagination.d.ts +5 -14
- package/dist/types/components/molecules/mg-panel/mg-panel.d.ts +4 -23
- package/dist/types/components/molecules/mg-popover/mg-popover.d.ts +3 -16
- package/dist/types/components/molecules/mg-skip-links/mg-skip-links.d.ts +2 -7
- package/dist/types/components/molecules/mg-tabs/mg-tabs.d.ts +15 -30
- package/dist/types/components.d.ts +22 -34
- package/dist/types/locales/index.d.ts +2 -3
- package/dist/types/utils/behaviors.utils.d.ts +14 -29
- package/dist/types/utils/components.utils.d.ts +19 -29
- package/dist/types/utils/locale.utils.d.ts +14 -18
- package/dist/types/utils/unit.test.utils.d.ts +11 -24
- package/package.json +11 -12
- package/dist/mg-components/p-9a93b7af.entry.js +0 -1
- /package/dist/mg-components/{p-367f92d2.js → p-0d3146d9.js} +0 -0
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MgItemMore type guard
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @returns {boolean} truthy if element is mg-item-more
|
|
3
|
+
* @param element - element to control type
|
|
4
|
+
* @returns truthy if element is mg-item-more
|
|
6
5
|
*/
|
|
7
6
|
const isMgItemMore = (element) => element.nodeName === 'MG-ITEM-MORE';
|
|
8
7
|
export var OverflowBehaviorElements;
|
|
@@ -19,8 +18,6 @@ export class OverflowBehavior {
|
|
|
19
18
|
**********/
|
|
20
19
|
/**
|
|
21
20
|
* Disconnect ResizeObserver
|
|
22
|
-
*
|
|
23
|
-
* @returns {void}
|
|
24
21
|
*/
|
|
25
22
|
this.disconnect = () => {
|
|
26
23
|
this._resizeObserver.disconnect();
|
|
@@ -30,9 +27,7 @@ export class OverflowBehavior {
|
|
|
30
27
|
************/
|
|
31
28
|
/**
|
|
32
29
|
* run overflow behavior
|
|
33
|
-
*
|
|
34
|
-
* @param {number} width width of the container. Optional.
|
|
35
|
-
* @returns {void}
|
|
30
|
+
* @param width - width of the container. Optional.
|
|
36
31
|
*/
|
|
37
32
|
this.run = (width) => {
|
|
38
33
|
if (this._moreElement === undefined) {
|
|
@@ -55,16 +50,13 @@ export class OverflowBehavior {
|
|
|
55
50
|
};
|
|
56
51
|
/**
|
|
57
52
|
* Get interactive children filtred by authorized nodeName ['MG-MENU-ITEM', 'MG-BUTTON']
|
|
58
|
-
*
|
|
59
|
-
* @
|
|
60
|
-
* @returns {Element[]} children
|
|
53
|
+
* @param element - element to parse
|
|
54
|
+
* @returns children
|
|
61
55
|
*/
|
|
62
56
|
this.getInteractiveItems = (element) => { var _a; return (((_a = element.children) === null || _a === void 0 ? void 0 : _a.length) > 0 ? Array.from(element.children) : []).filter(element => ['MG-MENU-ITEM', 'MG-BUTTON'].includes(element.nodeName)); };
|
|
63
57
|
/**
|
|
64
58
|
* Update displayed items in container from a given available space
|
|
65
|
-
*
|
|
66
|
-
* @param {number} availableWidth available width in container to display child items
|
|
67
|
-
* @returns {void}
|
|
59
|
+
* @param availableWidth - available width in container to display child items
|
|
68
60
|
*/
|
|
69
61
|
this.updateDisplayedItems = (availableWidth) => {
|
|
70
62
|
this.restoreItems();
|
|
@@ -83,11 +75,10 @@ export class OverflowBehavior {
|
|
|
83
75
|
};
|
|
84
76
|
/**
|
|
85
77
|
* Utility method to know if item overflow partialy or totaly in the container
|
|
86
|
-
*
|
|
87
|
-
* @param
|
|
88
|
-
* @param
|
|
89
|
-
* @
|
|
90
|
-
* @returns {boolean} truthy if element is overflow
|
|
78
|
+
* @param cumulateWidth - previous sibling elements cumulate width + item width
|
|
79
|
+
* @param item - item HTML element
|
|
80
|
+
* @param availableWidth - container available width
|
|
81
|
+
* @returns truthy if element is overflow
|
|
91
82
|
*/
|
|
92
83
|
this.isOverflowElement = (cumulateWidth, item, availableWidth) => {
|
|
93
84
|
if (item.previousElementSibling === null || this.isMoreElement(item))
|
|
@@ -99,17 +90,14 @@ export class OverflowBehavior {
|
|
|
99
90
|
};
|
|
100
91
|
/**
|
|
101
92
|
* Utility method to know if a given element is the 'MORE' element
|
|
102
|
-
*
|
|
103
|
-
* @
|
|
104
|
-
* @returns {boolean} truthy if element is the 'MORE' element
|
|
93
|
+
* @param element - element to match with 'MORE' element
|
|
94
|
+
* @returns truthy if element is the 'MORE' element
|
|
105
95
|
*/
|
|
106
96
|
this.isMoreElement = (element) => element.nodeName === 'MG-ITEM-MORE';
|
|
107
97
|
/**
|
|
108
98
|
* Toggle display item element
|
|
109
|
-
*
|
|
110
|
-
* @param
|
|
111
|
-
* @param {boolean} isHidden is item hidden
|
|
112
|
-
* @returns {void}
|
|
99
|
+
* @param item - item to control
|
|
100
|
+
* @param isHidden - is item hidden
|
|
113
101
|
*/
|
|
114
102
|
this.toggleItem = (item, isHidden) => {
|
|
115
103
|
const mgActionMenuindex = Number(item.getAttribute(OverflowBehaviorElements.BASE_INDEX));
|
|
@@ -122,10 +110,8 @@ export class OverflowBehavior {
|
|
|
122
110
|
};
|
|
123
111
|
/**
|
|
124
112
|
* Toggle element's hidde attribute
|
|
125
|
-
*
|
|
126
|
-
* @param
|
|
127
|
-
* @param {boolean} isHidden element is hidden
|
|
128
|
-
* @returns {void}
|
|
113
|
+
* @param element - element to toggle
|
|
114
|
+
* @param isHidden - element is hidden
|
|
129
115
|
*/
|
|
130
116
|
this.toggleElement = (element, isHidden) => {
|
|
131
117
|
if (isHidden)
|
|
@@ -135,8 +121,6 @@ export class OverflowBehavior {
|
|
|
135
121
|
};
|
|
136
122
|
/**
|
|
137
123
|
* Remove hidden attributes on all items
|
|
138
|
-
*
|
|
139
|
-
* @returns {void}
|
|
140
124
|
*/
|
|
141
125
|
this.restoreItems = () => {
|
|
142
126
|
[...this._baseChildren, this._moreElement].forEach(item => item.removeAttribute('hidden'));
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Create random ID
|
|
3
|
-
*
|
|
4
|
-
* @param
|
|
5
|
-
* @
|
|
6
|
-
* @returns {string} ID
|
|
3
|
+
* @param prefix - add prefix to created ID
|
|
4
|
+
* @param length - ID length
|
|
5
|
+
* @returns ID
|
|
7
6
|
*/
|
|
8
7
|
export const createID = (prefix = '', length = 10) => {
|
|
9
8
|
let ID = '';
|
|
@@ -22,9 +21,7 @@ export class ClassList {
|
|
|
22
21
|
constructor(classlist = []) {
|
|
23
22
|
/**
|
|
24
23
|
* Add class
|
|
25
|
-
*
|
|
26
|
-
* @param {string} className class name to add
|
|
27
|
-
* @returns {void}
|
|
24
|
+
* @param className - class name to add
|
|
28
25
|
*/
|
|
29
26
|
this.add = (className) => {
|
|
30
27
|
if (!this.has(className)) {
|
|
@@ -33,9 +30,7 @@ export class ClassList {
|
|
|
33
30
|
};
|
|
34
31
|
/**
|
|
35
32
|
* Delete class
|
|
36
|
-
*
|
|
37
|
-
* @param {string} className class name to delete
|
|
38
|
-
* @returns {void}
|
|
33
|
+
* @param className - class name to delete
|
|
39
34
|
*/
|
|
40
35
|
this.delete = (className) => {
|
|
41
36
|
const index = this.classes.indexOf(className);
|
|
@@ -45,17 +40,15 @@ export class ClassList {
|
|
|
45
40
|
};
|
|
46
41
|
/**
|
|
47
42
|
* Check if class exist in list
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
50
|
-
* @returns {boolean} class name is in the list
|
|
43
|
+
* @param className - class name to check
|
|
44
|
+
* @returns class name is in the list
|
|
51
45
|
*/
|
|
52
46
|
this.has = (className) => {
|
|
53
47
|
return this.classes.includes(className);
|
|
54
48
|
};
|
|
55
49
|
/**
|
|
56
50
|
* Join classes seperated by spaces
|
|
57
|
-
*
|
|
58
|
-
* @returns {string} joined values
|
|
51
|
+
* @returns joined values
|
|
59
52
|
*/
|
|
60
53
|
this.join = () => {
|
|
61
54
|
return this.classes.join(' ');
|
|
@@ -65,17 +58,15 @@ export class ClassList {
|
|
|
65
58
|
}
|
|
66
59
|
/**
|
|
67
60
|
* Check if all items are string
|
|
68
|
-
*
|
|
69
|
-
* @
|
|
70
|
-
* @returns {boolean} all items are string
|
|
61
|
+
* @param items - items to check
|
|
62
|
+
* @returns all items are string
|
|
71
63
|
*/
|
|
72
64
|
export const allItemsAreString = (items) => Array.isArray(items) && items.every(item => typeof item === 'string');
|
|
73
65
|
/**
|
|
74
66
|
* Check if element is a heading
|
|
75
|
-
*
|
|
76
|
-
* @param
|
|
77
|
-
* @
|
|
78
|
-
* @returns {boolean} element is a heading
|
|
67
|
+
* @param element - slotted element
|
|
68
|
+
* @param tagNames - allowed tag names list
|
|
69
|
+
* @returns element is a heading
|
|
79
70
|
*/
|
|
80
71
|
export const isTagName = (element, tagNames) => {
|
|
81
72
|
return tagNames.includes(element === null || element === void 0 ? void 0 : element.tagName.toLowerCase());
|
|
@@ -85,9 +76,9 @@ export const isTagName = (element, tagNames) => {
|
|
|
85
76
|
*/
|
|
86
77
|
export const focusableElements = 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"]), [identifier]';
|
|
87
78
|
/**
|
|
88
|
-
*
|
|
89
|
-
* @param
|
|
90
|
-
* @returns
|
|
79
|
+
* Get windows
|
|
80
|
+
* @param localWindow - the window we are lookink for other windows
|
|
81
|
+
* @returns The list of windows found
|
|
91
82
|
*/
|
|
92
83
|
export const getWindows = (localWindow) => {
|
|
93
84
|
const parentWindows = getParentWindows(localWindow);
|
|
@@ -96,10 +87,9 @@ export const getWindows = (localWindow) => {
|
|
|
96
87
|
};
|
|
97
88
|
/**
|
|
98
89
|
* Get parent windows
|
|
99
|
-
*
|
|
100
|
-
* @param
|
|
101
|
-
* @
|
|
102
|
-
* @returns {Window[]} The list of windows found
|
|
90
|
+
* @param localWindow - the window we are lookink for parents
|
|
91
|
+
* @param windows - The list of allready found windows
|
|
92
|
+
* @returns The list of windows found
|
|
103
93
|
*/
|
|
104
94
|
export const getParentWindows = (localWindow, windows = []) => {
|
|
105
95
|
// Check if is in iframe
|
|
@@ -119,10 +109,9 @@ export const getParentWindows = (localWindow, windows = []) => {
|
|
|
119
109
|
};
|
|
120
110
|
/**
|
|
121
111
|
* Get child windows
|
|
122
|
-
*
|
|
123
|
-
* @param
|
|
124
|
-
* @
|
|
125
|
-
* @returns {Window[]} The list of windows found
|
|
112
|
+
* @param localWindow - the window we are lookink for children
|
|
113
|
+
* @param windows - The list of allready found windows
|
|
114
|
+
* @returns The list of windows found
|
|
126
115
|
*/
|
|
127
116
|
const getChildWindows = (localWindow, windows = []) => {
|
|
128
117
|
if (localWindow.frames.length > 0) {
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Format number to the locale currency
|
|
3
|
-
*
|
|
4
|
-
* @param
|
|
5
|
-
* @param
|
|
6
|
-
* @
|
|
7
|
-
* @returns {string} formatted currency
|
|
3
|
+
* @param number - number to format
|
|
4
|
+
* @param locale - locale to apply
|
|
5
|
+
* @param currency - currency to apply
|
|
6
|
+
* @returns formatted currency
|
|
8
7
|
*/
|
|
9
8
|
export const localeCurrency = (number, locale, currency) => {
|
|
10
9
|
return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(number);
|
|
11
10
|
};
|
|
12
11
|
/**
|
|
13
12
|
* Format number to locale
|
|
14
|
-
*
|
|
15
|
-
* @param
|
|
16
|
-
* @
|
|
17
|
-
* @returns {string} formatted number
|
|
13
|
+
* @param number - number to format
|
|
14
|
+
* @param locale - locale to apply
|
|
15
|
+
* @returns formatted number
|
|
18
16
|
*/
|
|
19
17
|
export const localeNumber = (number, locale) => {
|
|
20
18
|
return new Intl.NumberFormat(locale).format(number);
|
|
@@ -25,10 +23,9 @@ export const localeNumber = (number, locale) => {
|
|
|
25
23
|
export const dateRegExp = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
|
|
26
24
|
/**
|
|
27
25
|
* Locale date format
|
|
28
|
-
*
|
|
29
|
-
* @param
|
|
30
|
-
* @
|
|
31
|
-
* @returns {string} formatted date
|
|
26
|
+
* @param date - date to format
|
|
27
|
+
* @param locale - locale to apply
|
|
28
|
+
* @returns formatted date
|
|
32
29
|
*/
|
|
33
30
|
export const localeDate = (date, locale) => {
|
|
34
31
|
if (typeof date !== 'string' || date === '' || !dateRegExp.test(date)) {
|
|
@@ -39,11 +36,10 @@ export const localeDate = (date, locale) => {
|
|
|
39
36
|
/**
|
|
40
37
|
* Get locale and messages
|
|
41
38
|
* We load the defined locale but for now we only support the first subtag for messages
|
|
42
|
-
*
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
-
* @
|
|
46
|
-
* @returns {{ locale: string; messages: Record<string, unknown> }} messages object
|
|
39
|
+
* @param element - element we need to get the language
|
|
40
|
+
* @param messages - messages to use
|
|
41
|
+
* @param defaultLocale - default messages locale
|
|
42
|
+
* @returns messages object
|
|
47
43
|
*/
|
|
48
44
|
export const getLocaleMessages = (element, messages, defaultLocale) => {
|
|
49
45
|
// Get local
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { MockCustomEvent } from '@stencil/core/mock-doc';
|
|
2
2
|
/**
|
|
3
3
|
* Clone Deep function
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
* @returns {unknown} cloned json
|
|
4
|
+
* @param obj - object to clone
|
|
5
|
+
* @returns cloned json
|
|
7
6
|
*/
|
|
8
7
|
export const cloneDeep = (obj) => JSON.parse(JSON.stringify(obj));
|
|
9
8
|
export const setupMutationObserverMock = ({ disconnect, observe, takeRecords }) => {
|
|
@@ -43,12 +42,11 @@ export const setupResizeObserverMock = ({ disconnect, observe }) => {
|
|
|
43
42
|
};
|
|
44
43
|
/**
|
|
45
44
|
* Utility function that mocks the `SubmitEvent` API. Recommended to execute inside `beforeEach`.
|
|
46
|
-
*
|
|
47
|
-
* @returns {void}
|
|
48
45
|
* @example
|
|
49
46
|
* ```
|
|
50
47
|
* setupSubmitEventMock();
|
|
51
48
|
* ```
|
|
49
|
+
* @returns custom event mock
|
|
52
50
|
*/
|
|
53
51
|
export const setupSubmitEventMock = () => {
|
|
54
52
|
class SubmitEvent extends MockCustomEvent {
|
|
@@ -67,11 +65,9 @@ export const setupSubmitEventMock = () => {
|
|
|
67
65
|
};
|
|
68
66
|
/**
|
|
69
67
|
* force popover id when component use randomed identifier
|
|
70
|
-
*
|
|
71
|
-
* @param
|
|
72
|
-
* @param
|
|
73
|
-
* @param {string} interactiveElement element where attribute 'aria-controls' is set
|
|
74
|
-
* @returns {void}
|
|
68
|
+
* @param component - element wich include mg-popover
|
|
69
|
+
* @param id - new fixed id
|
|
70
|
+
* @param interactiveElement - element where attribute 'aria-controls' is set
|
|
75
71
|
*/
|
|
76
72
|
export const forcePopoverId = (component, id, interactiveElement = 'button') => {
|
|
77
73
|
const popover = component.shadowRoot.querySelector('mg-popover');
|
|
@@ -82,12 +78,10 @@ export const forcePopoverId = (component, id, interactiveElement = 'button') =>
|
|
|
82
78
|
};
|
|
83
79
|
/**
|
|
84
80
|
* fix popper console.error in test
|
|
85
|
-
* it is generated in
|
|
81
|
+
* it is generated in `@popperjs/core/dist/cjs/popper.js l.1859`
|
|
86
82
|
* this is due to internal function isHTMLElement(), so we can not mock it directly.
|
|
87
83
|
* this function check if test DOM element mockHTMLElement instance is 'instanceof HTMLElement'
|
|
88
84
|
* so we only override the console.error side effect for this error
|
|
89
|
-
*
|
|
90
|
-
* @returns {void}
|
|
91
85
|
*/
|
|
92
86
|
export const mockConsoleError = () => {
|
|
93
87
|
jest.spyOn(console, 'error').mockImplementation(error => {
|
|
@@ -99,8 +93,6 @@ export const mockConsoleError = () => {
|
|
|
99
93
|
/**
|
|
100
94
|
* Add missing window.frames property to test context
|
|
101
95
|
* usefull for component with iframe listeners, ex: mg-popover
|
|
102
|
-
*
|
|
103
|
-
* @returns {void}
|
|
104
96
|
*/
|
|
105
97
|
export const mockWindowFrames = () => {
|
|
106
98
|
Object.defineProperty(window, 'frames', {
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { h } from '@stencil/core/internal/client';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Possible input width
|
|
5
|
+
*/
|
|
6
|
+
const widths = [2, 4, 16, 'full'];
|
|
7
|
+
|
|
3
8
|
/**
|
|
4
9
|
* Apply in all input child node the aria-describedby attribute
|
|
5
|
-
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @
|
|
9
|
-
* @returns {VNode[]} Children with aria-describedby attribute
|
|
10
|
+
* @param children - Represent scoped elements
|
|
11
|
+
* @param ariaDescribedbyIDs - List of IDs
|
|
12
|
+
* @param utils - Stencil.js utils
|
|
13
|
+
* @returns Children with aria-describedby attribute
|
|
10
14
|
*/
|
|
11
15
|
const applyAriadescribedBy = (children, ariaDescribedbyIDs, utils) => utils.map(children, child => {
|
|
12
16
|
if (['input', 'select', 'textarea'].includes(child.vtag)) {
|
|
@@ -19,32 +23,36 @@ const applyAriadescribedBy = (children, ariaDescribedbyIDs, utils) => utils.map(
|
|
|
19
23
|
});
|
|
20
24
|
/**
|
|
21
25
|
* Add classes based on props
|
|
22
|
-
*
|
|
23
|
-
* @param {MgInputProps} props MgInput Interface Props
|
|
26
|
+
* @param props - MgInput Interface Props
|
|
24
27
|
*/
|
|
25
28
|
const manageClasses = (props) => {
|
|
26
|
-
props.
|
|
29
|
+
props.classCollection.add('mg-input');
|
|
27
30
|
if (props.labelOnTop)
|
|
28
|
-
props.
|
|
31
|
+
props.classCollection.add('mg-input--label-on-top');
|
|
32
|
+
else
|
|
33
|
+
props.classCollection.delete('mg-input--label-on-top');
|
|
29
34
|
if (props.readonly)
|
|
30
|
-
props.
|
|
35
|
+
props.classCollection.add('mg-input--readonly');
|
|
36
|
+
else
|
|
37
|
+
props.classCollection.delete('mg-input--readonly');
|
|
38
|
+
widths.forEach(width => {
|
|
39
|
+
props.classCollection.delete(`mg-input--width-${width}`);
|
|
40
|
+
});
|
|
31
41
|
if (props.mgWidth !== undefined)
|
|
32
|
-
props.
|
|
42
|
+
props.classCollection.add(`mg-input--width-${props.mgWidth}`);
|
|
33
43
|
};
|
|
34
44
|
/**
|
|
35
45
|
* Get tagname
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
38
|
-
* @returns {string} tag name
|
|
46
|
+
* @param isFieldset - is fieldset
|
|
47
|
+
* @returns tag name
|
|
39
48
|
*/
|
|
40
49
|
const getTagName = (isFieldset) => (isFieldset ? 'fieldset' : 'div');
|
|
41
50
|
/**
|
|
42
51
|
* Get input template
|
|
43
|
-
*
|
|
44
|
-
* @param
|
|
45
|
-
* @param
|
|
46
|
-
* @
|
|
47
|
-
* @returns {VNode[]} input template
|
|
52
|
+
* @param props - MgInput Interface Props
|
|
53
|
+
* @param children - Represent scoped elements
|
|
54
|
+
* @param utils - Stencil.js utils
|
|
55
|
+
* @returns input template
|
|
48
56
|
*/
|
|
49
57
|
const MgInput = (props, children, utils) => {
|
|
50
58
|
/**
|
|
@@ -100,19 +108,17 @@ const MgInput = (props, children, utils) => {
|
|
|
100
108
|
const TagName = getTagName(props.isFieldset);
|
|
101
109
|
/**
|
|
102
110
|
* Get tooltip node
|
|
103
|
-
*
|
|
104
|
-
* @returns {VNode[]} mg-tooltip
|
|
111
|
+
* @returns mg-tooltip
|
|
105
112
|
*/
|
|
106
113
|
const getTooltip = () => (h("mg-tooltip", { identifier: `${props.identifier}-tooltip`, message: props.tooltip },
|
|
107
114
|
h("mg-icon", { icon: "info-circle" })));
|
|
108
115
|
/**
|
|
109
116
|
* Get input title (label) node
|
|
110
117
|
* Display asterisk only if not disabled and not readonly
|
|
111
|
-
*
|
|
112
|
-
* @returns {VNode[]} mg-input-title
|
|
118
|
+
* @returns mg-input-title
|
|
113
119
|
*/
|
|
114
120
|
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));
|
|
115
|
-
return (h(TagName, { class: props.
|
|
121
|
+
return (h(TagName, { class: props.classCollection.join() },
|
|
116
122
|
props.labelOnTop ? (h("div", { class: "mg-input__title" },
|
|
117
123
|
getInputTitle(),
|
|
118
124
|
!props.readonly && props.tooltip && getTooltip())) : (getInputTitle()),
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Create random ID
|
|
3
|
-
*
|
|
4
|
-
* @param
|
|
5
|
-
* @
|
|
6
|
-
* @returns {string} ID
|
|
3
|
+
* @param prefix - add prefix to created ID
|
|
4
|
+
* @param length - ID length
|
|
5
|
+
* @returns ID
|
|
7
6
|
*/
|
|
8
7
|
const createID = (prefix = '', length = 10) => {
|
|
9
8
|
let ID = '';
|
|
@@ -22,9 +21,7 @@ class ClassList {
|
|
|
22
21
|
constructor(classlist = []) {
|
|
23
22
|
/**
|
|
24
23
|
* Add class
|
|
25
|
-
*
|
|
26
|
-
* @param {string} className class name to add
|
|
27
|
-
* @returns {void}
|
|
24
|
+
* @param className - class name to add
|
|
28
25
|
*/
|
|
29
26
|
this.add = (className) => {
|
|
30
27
|
if (!this.has(className)) {
|
|
@@ -33,9 +30,7 @@ class ClassList {
|
|
|
33
30
|
};
|
|
34
31
|
/**
|
|
35
32
|
* Delete class
|
|
36
|
-
*
|
|
37
|
-
* @param {string} className class name to delete
|
|
38
|
-
* @returns {void}
|
|
33
|
+
* @param className - class name to delete
|
|
39
34
|
*/
|
|
40
35
|
this.delete = (className) => {
|
|
41
36
|
const index = this.classes.indexOf(className);
|
|
@@ -45,17 +40,15 @@ class ClassList {
|
|
|
45
40
|
};
|
|
46
41
|
/**
|
|
47
42
|
* Check if class exist in list
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
50
|
-
* @returns {boolean} class name is in the list
|
|
43
|
+
* @param className - class name to check
|
|
44
|
+
* @returns class name is in the list
|
|
51
45
|
*/
|
|
52
46
|
this.has = (className) => {
|
|
53
47
|
return this.classes.includes(className);
|
|
54
48
|
};
|
|
55
49
|
/**
|
|
56
50
|
* Join classes seperated by spaces
|
|
57
|
-
*
|
|
58
|
-
* @returns {string} joined values
|
|
51
|
+
* @returns joined values
|
|
59
52
|
*/
|
|
60
53
|
this.join = () => {
|
|
61
54
|
return this.classes.join(' ');
|
|
@@ -65,17 +58,15 @@ class ClassList {
|
|
|
65
58
|
}
|
|
66
59
|
/**
|
|
67
60
|
* Check if all items are string
|
|
68
|
-
*
|
|
69
|
-
* @
|
|
70
|
-
* @returns {boolean} all items are string
|
|
61
|
+
* @param items - items to check
|
|
62
|
+
* @returns all items are string
|
|
71
63
|
*/
|
|
72
64
|
const allItemsAreString = (items) => Array.isArray(items) && items.every(item => typeof item === 'string');
|
|
73
65
|
/**
|
|
74
66
|
* Check if element is a heading
|
|
75
|
-
*
|
|
76
|
-
* @param
|
|
77
|
-
* @
|
|
78
|
-
* @returns {boolean} element is a heading
|
|
67
|
+
* @param element - slotted element
|
|
68
|
+
* @param tagNames - allowed tag names list
|
|
69
|
+
* @returns element is a heading
|
|
79
70
|
*/
|
|
80
71
|
const isTagName = (element, tagNames) => {
|
|
81
72
|
return tagNames.includes(element === null || element === void 0 ? void 0 : element.tagName.toLowerCase());
|
|
@@ -85,9 +76,9 @@ const isTagName = (element, tagNames) => {
|
|
|
85
76
|
*/
|
|
86
77
|
const focusableElements = 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"]), [identifier]';
|
|
87
78
|
/**
|
|
88
|
-
*
|
|
89
|
-
* @param
|
|
90
|
-
* @returns
|
|
79
|
+
* Get windows
|
|
80
|
+
* @param localWindow - the window we are lookink for other windows
|
|
81
|
+
* @returns The list of windows found
|
|
91
82
|
*/
|
|
92
83
|
const getWindows = (localWindow) => {
|
|
93
84
|
const parentWindows = getParentWindows(localWindow);
|
|
@@ -96,10 +87,9 @@ const getWindows = (localWindow) => {
|
|
|
96
87
|
};
|
|
97
88
|
/**
|
|
98
89
|
* Get parent windows
|
|
99
|
-
*
|
|
100
|
-
* @param
|
|
101
|
-
* @
|
|
102
|
-
* @returns {Window[]} The list of windows found
|
|
90
|
+
* @param localWindow - the window we are lookink for parents
|
|
91
|
+
* @param windows - The list of allready found windows
|
|
92
|
+
* @returns The list of windows found
|
|
103
93
|
*/
|
|
104
94
|
const getParentWindows = (localWindow, windows = []) => {
|
|
105
95
|
// Check if is in iframe
|
|
@@ -119,10 +109,9 @@ const getParentWindows = (localWindow, windows = []) => {
|
|
|
119
109
|
};
|
|
120
110
|
/**
|
|
121
111
|
* Get child windows
|
|
122
|
-
*
|
|
123
|
-
* @param
|
|
124
|
-
* @
|
|
125
|
-
* @returns {Window[]} The list of windows found
|
|
112
|
+
* @param localWindow - the window we are lookink for children
|
|
113
|
+
* @param windows - The list of allready found windows
|
|
114
|
+
* @returns The list of windows found
|
|
126
115
|
*/
|
|
127
116
|
const getChildWindows = (localWindow, windows = []) => {
|
|
128
117
|
if (localWindow.frames.length > 0) {
|
|
@@ -150,21 +150,19 @@ const fr = {
|
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
152
|
* Format number to the locale currency
|
|
153
|
-
*
|
|
154
|
-
* @param
|
|
155
|
-
* @param
|
|
156
|
-
* @
|
|
157
|
-
* @returns {string} formatted currency
|
|
153
|
+
* @param number - number to format
|
|
154
|
+
* @param locale - locale to apply
|
|
155
|
+
* @param currency - currency to apply
|
|
156
|
+
* @returns formatted currency
|
|
158
157
|
*/
|
|
159
158
|
const localeCurrency = (number, locale, currency) => {
|
|
160
159
|
return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(number);
|
|
161
160
|
};
|
|
162
161
|
/**
|
|
163
162
|
* Format number to locale
|
|
164
|
-
*
|
|
165
|
-
* @param
|
|
166
|
-
* @
|
|
167
|
-
* @returns {string} formatted number
|
|
163
|
+
* @param number - number to format
|
|
164
|
+
* @param locale - locale to apply
|
|
165
|
+
* @returns formatted number
|
|
168
166
|
*/
|
|
169
167
|
const localeNumber = (number, locale) => {
|
|
170
168
|
return new Intl.NumberFormat(locale).format(number);
|
|
@@ -175,10 +173,9 @@ const localeNumber = (number, locale) => {
|
|
|
175
173
|
const dateRegExp = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
|
|
176
174
|
/**
|
|
177
175
|
* Locale date format
|
|
178
|
-
*
|
|
179
|
-
* @param
|
|
180
|
-
* @
|
|
181
|
-
* @returns {string} formatted date
|
|
176
|
+
* @param date - date to format
|
|
177
|
+
* @param locale - locale to apply
|
|
178
|
+
* @returns formatted date
|
|
182
179
|
*/
|
|
183
180
|
const localeDate = (date, locale) => {
|
|
184
181
|
if (typeof date !== 'string' || date === '' || !dateRegExp.test(date)) {
|
|
@@ -189,11 +186,10 @@ const localeDate = (date, locale) => {
|
|
|
189
186
|
/**
|
|
190
187
|
* Get locale and messages
|
|
191
188
|
* We load the defined locale but for now we only support the first subtag for messages
|
|
192
|
-
*
|
|
193
|
-
* @param
|
|
194
|
-
* @param
|
|
195
|
-
* @
|
|
196
|
-
* @returns {{ locale: string; messages: Record<string, unknown> }} messages object
|
|
189
|
+
* @param element - element we need to get the language
|
|
190
|
+
* @param messages - messages to use
|
|
191
|
+
* @param defaultLocale - default messages locale
|
|
192
|
+
* @returns messages object
|
|
197
193
|
*/
|
|
198
194
|
const getLocaleMessages = (element, messages, defaultLocale) => {
|
|
199
195
|
// Get local
|
|
@@ -213,9 +209,8 @@ const defaultLocale = 'en';
|
|
|
213
209
|
const messages = { en, fr };
|
|
214
210
|
/**
|
|
215
211
|
* Get Intl object
|
|
216
|
-
*
|
|
217
|
-
* @
|
|
218
|
-
* @returns {{ locale: string; messages: Record<string, unknown> }} messages object
|
|
212
|
+
* @param element - element we need to get the language
|
|
213
|
+
* @returns messages object
|
|
219
214
|
*/
|
|
220
215
|
const initLocales = (element) => getLocaleMessages(element, messages, defaultLocale);
|
|
221
216
|
|