@mgdis/mg-components 5.10.0 → 5.11.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.
- package/dist/cjs/{index-9e1091ab.js → index-03d2557d.js} +3 -0
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/mg-action-more_31.cjs.entry.js +444 -455
- package/dist/cjs/mg-components.cjs.js +2 -2
- package/dist/cjs/mg-item-more.cjs.entry.js +20 -29
- package/dist/cjs/{mg-menu.conf-1942ac70.js → mg-menu.conf-05ec32a3.js} +30 -16
- package/dist/collection/components/atoms/mg-badge/mg-badge.js +8 -9
- package/dist/collection/components/atoms/mg-button/mg-button.js +16 -20
- package/dist/collection/components/atoms/mg-card/mg-card.css +2 -0
- package/dist/collection/components/atoms/mg-card/mg-card.js +10 -12
- package/dist/collection/components/atoms/mg-character-left/mg-character-left.js +1 -2
- package/dist/collection/components/atoms/mg-divider/mg-divider.js +1 -1
- package/dist/collection/components/atoms/mg-icon/mg-icon.js +17 -19
- package/dist/collection/components/atoms/mg-input-title/mg-input-title.js +1 -2
- package/dist/collection/components/atoms/mg-tag/mg-tag.js +11 -13
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +20 -25
- package/dist/collection/components/molecules/inputs/MgInput.conf.js +4 -1
- package/dist/collection/components/molecules/inputs/MgInput.js +26 -18
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.conf.js +4 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.css +18 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +126 -19
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.css +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +7 -12
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.css +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +14 -22
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.css +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +6 -10
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.css +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +10 -18
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.css +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +21 -32
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.css +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +16 -31
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.css +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +13 -17
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.css +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +17 -23
- package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js +11 -18
- package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js +20 -29
- package/dist/collection/components/molecules/mg-action-more/mg-action-more.js +11 -15
- package/dist/collection/components/molecules/mg-details/mg-details.js +1 -3
- package/dist/collection/components/molecules/mg-form/mg-form.js +8 -19
- package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js +1 -2
- package/dist/collection/components/molecules/mg-item-more/mg-item-more.js +4 -7
- package/dist/collection/components/molecules/mg-message/mg-message.css +1 -0
- package/dist/collection/components/molecules/mg-message/mg-message.js +11 -14
- package/dist/collection/components/molecules/mg-modal/mg-modal.css +1 -0
- package/dist/collection/components/molecules/mg-modal/mg-modal.js +7 -11
- package/dist/collection/components/molecules/mg-pagination/mg-pagination.js +11 -13
- package/dist/collection/components/molecules/mg-panel/mg-panel.css +1 -0
- package/dist/collection/components/molecules/mg-panel/mg-panel.js +6 -15
- package/dist/collection/components/molecules/mg-popover/mg-popover.css +2 -0
- package/dist/collection/components/molecules/mg-popover/mg-popover.js +16 -16
- package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js +2 -4
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +20 -24
- package/dist/collection/locales/en/messages.json +7 -0
- package/dist/collection/locales/fr/messages.json +7 -0
- package/dist/collection/locales/index.js +2 -2
- package/dist/collection/styles/reset-mg-card-slotted-variables.scss +1 -0
- package/dist/collection/utils/behaviors.utils.js +16 -22
- package/dist/collection/utils/components.utils.js +21 -23
- package/dist/collection/utils/locale.utils.js +14 -14
- package/dist/collection/utils/unit.test.utils.js +7 -10
- package/dist/components/MgInput.js +30 -18
- package/dist/components/components.utils.js +21 -23
- package/dist/components/index2.js +30 -16
- package/dist/components/mg-action-more.js +9 -13
- package/dist/components/mg-badge2.js +8 -9
- package/dist/components/mg-button2.js +16 -20
- package/dist/components/mg-card2.js +9 -11
- package/dist/components/mg-character-left2.js +1 -2
- package/dist/components/mg-details.js +1 -3
- package/dist/components/mg-divider.js +1 -1
- package/dist/components/mg-form.js +7 -15
- package/dist/components/mg-icon2.js +17 -19
- package/dist/components/mg-illustrated-message.js +1 -2
- package/dist/components/mg-input-checkbox.js +126 -21
- package/dist/components/mg-input-date.js +7 -9
- package/dist/components/mg-input-numeric.js +14 -19
- package/dist/components/mg-input-password.js +6 -7
- package/dist/components/mg-input-radio.js +10 -15
- package/dist/components/mg-input-select2.js +21 -29
- package/dist/components/mg-input-text2.js +15 -24
- package/dist/components/mg-input-textarea.js +13 -14
- package/dist/components/mg-input-title2.js +1 -2
- package/dist/components/mg-input-toggle.js +17 -20
- package/dist/components/mg-item-more.js +18 -27
- package/dist/components/mg-menu-item2.js +17 -26
- package/dist/components/mg-menu2.js +9 -16
- package/dist/components/mg-message.js +12 -15
- package/dist/components/mg-modal.js +8 -12
- package/dist/components/mg-pagination.js +11 -13
- package/dist/components/mg-panel.js +7 -16
- package/dist/components/mg-popover2.js +17 -17
- package/dist/components/mg-skip-links.js +2 -4
- package/dist/components/mg-tabs.js +20 -24
- package/dist/components/mg-tag.js +11 -13
- package/dist/components/mg-tooltip2.js +20 -25
- package/dist/esm/{index-3249671d.js → index-407d5211.js} +3 -0
- package/dist/esm/loader.js +3 -3
- package/dist/esm/mg-action-more_31.entry.js +444 -455
- package/dist/esm/mg-components.js +3 -3
- package/dist/esm/mg-item-more.entry.js +20 -29
- package/dist/esm/{mg-menu.conf-2cc1bb67.js → mg-menu.conf-c8aa56ce.js} +30 -16
- package/dist/mg-components/locales/en/messages.json +7 -0
- package/dist/mg-components/locales/fr/messages.json +7 -0
- package/dist/mg-components/mg-components.css +1 -1
- package/dist/mg-components/mg-components.esm.js +1 -1
- package/dist/mg-components/p-3bf533f7.js +2 -0
- package/dist/mg-components/p-51c2def3.entry.js +1 -0
- package/dist/mg-components/p-b14be68b.js +1 -0
- package/dist/mg-components/{p-a56a3157.entry.js → p-d3ed97d3.entry.js} +1 -1
- package/dist/mg-components/styles/reset-mg-card-slotted-variables.scss +1 -0
- package/dist/types/components/atoms/mg-badge/mg-badge.d.ts +2 -3
- package/dist/types/components/atoms/mg-button/mg-button.d.ts +5 -9
- package/dist/types/components/atoms/mg-card/mg-card.d.ts +2 -6
- package/dist/types/components/atoms/mg-character-left/mg-character-left.d.ts +1 -2
- package/dist/types/components/atoms/mg-divider/mg-divider.d.ts +1 -1
- package/dist/types/components/atoms/mg-icon/mg-icon.d.ts +3 -5
- package/dist/types/components/atoms/mg-input-title/mg-input-title.d.ts +1 -2
- package/dist/types/components/atoms/mg-tag/mg-tag.d.ts +3 -5
- package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +15 -21
- package/dist/types/components/molecules/inputs/MgInput.conf.d.ts +2 -1
- package/dist/types/components/molecules/inputs/MgInput.d.ts +5 -5
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.conf.d.ts +8 -0
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +40 -7
- package/dist/types/components/molecules/inputs/mg-input-date/mg-input-date.d.ts +4 -6
- package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +7 -14
- package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.d.ts +3 -4
- package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.d.ts +5 -10
- 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 -13
- package/dist/types/components/molecules/inputs/mg-input-text/mg-input-text.d.ts +3 -12
- package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.d.ts +4 -5
- package/dist/types/components/molecules/inputs/mg-input-toggle/mg-input-toggle.d.ts +2 -6
- package/dist/types/components/molecules/menu/mg-menu/mg-menu.d.ts +10 -18
- package/dist/types/components/molecules/menu/mg-menu-item/mg-menu-item.d.ts +21 -31
- package/dist/types/components/molecules/mg-action-more/mg-action-more.d.ts +3 -10
- package/dist/types/components/molecules/mg-details/mg-details.d.ts +1 -3
- package/dist/types/components/molecules/mg-form/mg-form.d.ts +3 -11
- package/dist/types/components/molecules/mg-illustrated-message/mg-illustrated-message.d.ts +1 -2
- package/dist/types/components/molecules/mg-item-more/mg-item-more.d.ts +2 -7
- package/dist/types/components/molecules/mg-message/mg-message.d.ts +4 -7
- package/dist/types/components/molecules/mg-modal/mg-modal.d.ts +3 -7
- package/dist/types/components/molecules/mg-pagination/mg-pagination.d.ts +5 -9
- package/dist/types/components/molecules/mg-panel/mg-panel.d.ts +4 -13
- package/dist/types/components/molecules/mg-popover/mg-popover.d.ts +7 -9
- package/dist/types/components/molecules/mg-skip-links/mg-skip-links.d.ts +2 -4
- package/dist/types/components/molecules/mg-tabs/mg-tabs.d.ts +15 -19
- package/dist/types/components.d.ts +31 -35
- package/dist/types/locales/index.d.ts +16 -2
- package/dist/types/utils/behaviors.utils.d.ts +14 -20
- package/dist/types/utils/components.utils.d.ts +18 -20
- package/dist/types/utils/locale.utils.d.ts +14 -14
- package/dist/types/utils/unit.test.utils.d.ts +11 -17
- package/package.json +4 -4
- package/dist/mg-components/p-73156ac9.js +0 -1
- package/dist/mg-components/p-8fbc0d87.js +0 -2
- package/dist/mg-components/p-eb32bb18.entry.js +0 -1
|
@@ -3,8 +3,8 @@ import { createID, ClassList, allItemsAreString } from '../../../utils/component
|
|
|
3
3
|
import { sizes, Status } from './mg-tabs.conf';
|
|
4
4
|
/**
|
|
5
5
|
* type TabItem validation function
|
|
6
|
-
* @param
|
|
7
|
-
* @returns
|
|
6
|
+
* @param tab - tab item
|
|
7
|
+
* @returns tab item type is valid
|
|
8
8
|
*/
|
|
9
9
|
const isTabItem = (tab) => typeof tab === 'object' && typeof tab.label === 'string';
|
|
10
10
|
export class MgTabs {
|
|
@@ -18,32 +18,32 @@ export class MgTabs {
|
|
|
18
18
|
this.startIndex = 1;
|
|
19
19
|
/**
|
|
20
20
|
* Method to know if given tab has the given status
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
23
|
-
* @returns
|
|
21
|
+
* @param tab - item tab key to set to ACTIVE status
|
|
22
|
+
* @param status - status to valide
|
|
23
|
+
* @returns status comparaison
|
|
24
24
|
*/
|
|
25
25
|
this.tabHasStatus = (tab, status) => tab.status === status;
|
|
26
26
|
/**
|
|
27
27
|
* Method to get element id from index
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @returns
|
|
28
|
+
* @param element - to get id
|
|
29
|
+
* @param index - to generate id
|
|
30
|
+
* @returns generated element id
|
|
31
31
|
*/
|
|
32
32
|
this.getElementId = (element, index) => `${element}-${this.getTabItemIndex(index)}`;
|
|
33
33
|
/**
|
|
34
34
|
* Method to get tab item index
|
|
35
|
-
* @param
|
|
36
|
-
* @returns
|
|
35
|
+
* @param index - to get
|
|
36
|
+
* @returns index
|
|
37
37
|
*/
|
|
38
38
|
this.getTabItemIndex = (index) => index + this.startIndex;
|
|
39
39
|
/**
|
|
40
40
|
* Method to get the active-tab value
|
|
41
|
-
* @returns
|
|
41
|
+
* @returns of the active-tab
|
|
42
42
|
*/
|
|
43
43
|
this.getActiveTab = () => this.activeTab || this.getTabItemIndex(this.tabs.map((tab, index) => (Object.assign(Object.assign({}, tab), { index }))).find(tab => this.tabHasStatus(tab, Status.ACTIVE)).index);
|
|
44
44
|
/**
|
|
45
45
|
* Handle click events on tabs
|
|
46
|
-
* @param
|
|
46
|
+
* @param event - mouse event
|
|
47
47
|
*/
|
|
48
48
|
this.handleClick = (event) => {
|
|
49
49
|
const tabId = event.currentTarget.dataset.index;
|
|
@@ -58,14 +58,13 @@ export class MgTabs {
|
|
|
58
58
|
};
|
|
59
59
|
/**
|
|
60
60
|
* get navigation button class from given status
|
|
61
|
-
* @param
|
|
62
|
-
* @returns
|
|
61
|
+
* @param status - button tab status
|
|
62
|
+
* @returns button class/selector variant
|
|
63
63
|
*/
|
|
64
64
|
this.getNavigationButtonClass = (status) => `${this.buttonTabBaseClass}--${status}`;
|
|
65
65
|
/**
|
|
66
66
|
* Handle keyboard event on tabs
|
|
67
|
-
* @param
|
|
68
|
-
* @returns {void}
|
|
67
|
+
* @param event - mouse event
|
|
69
68
|
*/
|
|
70
69
|
this.handleKeydown = (event) => {
|
|
71
70
|
const parent = event.target.parentElement;
|
|
@@ -103,7 +102,6 @@ export class MgTabs {
|
|
|
103
102
|
};
|
|
104
103
|
/**
|
|
105
104
|
* Method to reset focus behavior
|
|
106
|
-
* @returns {void}
|
|
107
105
|
*/
|
|
108
106
|
this.resetFocus = () => {
|
|
109
107
|
// update asynchronously tabindex to prevent get focus on new tabindex at then end of event process
|
|
@@ -128,7 +126,7 @@ export class MgTabs {
|
|
|
128
126
|
this.items = undefined;
|
|
129
127
|
this.activeTab = undefined;
|
|
130
128
|
this.tabs = [];
|
|
131
|
-
this.
|
|
129
|
+
this.classCollection = new ClassList(['mg-tabs']);
|
|
132
130
|
}
|
|
133
131
|
validateLabel(newValue) {
|
|
134
132
|
if (typeof newValue !== 'string' || newValue.trim() === '') {
|
|
@@ -139,7 +137,7 @@ export class MgTabs {
|
|
|
139
137
|
if (!sizes.includes(newValue)) {
|
|
140
138
|
throw new Error(`<mg-tabs> prop "size" must be one of: ${sizes.join(', ')}`);
|
|
141
139
|
}
|
|
142
|
-
this.
|
|
140
|
+
this.classCollection.add(`mg-tabs--size-${this.size}`);
|
|
143
141
|
}
|
|
144
142
|
validateItems(newValue) {
|
|
145
143
|
// String array
|
|
@@ -182,7 +180,6 @@ export class MgTabs {
|
|
|
182
180
|
*************/
|
|
183
181
|
/**
|
|
184
182
|
* Check if component props are well configured on init
|
|
185
|
-
* @returns {void}
|
|
186
183
|
*/
|
|
187
184
|
componentWillLoad() {
|
|
188
185
|
// Check tabs format
|
|
@@ -194,7 +191,6 @@ export class MgTabs {
|
|
|
194
191
|
}
|
|
195
192
|
/**
|
|
196
193
|
* add listners
|
|
197
|
-
* @returns {void}
|
|
198
194
|
*/
|
|
199
195
|
componentDidLoad() {
|
|
200
196
|
document.addEventListener('click', (event) => {
|
|
@@ -204,10 +200,10 @@ export class MgTabs {
|
|
|
204
200
|
}
|
|
205
201
|
/**
|
|
206
202
|
* Render
|
|
207
|
-
* @returns
|
|
203
|
+
* @returns HTML Element
|
|
208
204
|
*/
|
|
209
205
|
render() {
|
|
210
|
-
return (h("div", { class: this.
|
|
206
|
+
return (h("div", { class: this.classCollection.join() }, h("header", { role: "tablist", "aria-label": this.label, class: "mg-tabs__header" }, this.tabs.map((tab, index) => (h("button", { key: tab.label, role: "tab", id: this.getElementId(this.identifier, index), class: {
|
|
211
207
|
[`${this.buttonTabBaseClass}`]: true,
|
|
212
208
|
[`${this.buttonTabBaseClass}--horizontal`]: true,
|
|
213
209
|
[`${this.getNavigationButtonClass(Status.ACTIVE)}`]: this.tabHasStatus(tab, Status.ACTIVE),
|
|
@@ -329,7 +325,7 @@ export class MgTabs {
|
|
|
329
325
|
static get states() {
|
|
330
326
|
return {
|
|
331
327
|
"tabs": {},
|
|
332
|
-
"
|
|
328
|
+
"classCollection": {}
|
|
333
329
|
};
|
|
334
330
|
}
|
|
335
331
|
static get events() {
|
|
@@ -17,6 +17,13 @@
|
|
|
17
17
|
"input": {
|
|
18
18
|
"select": {
|
|
19
19
|
"placeholder": "Select a value"
|
|
20
|
+
},
|
|
21
|
+
"checkbox": {
|
|
22
|
+
"selectedValues": "{nb} selected values",
|
|
23
|
+
"selectedValue": "{nb} selected value",
|
|
24
|
+
"editButton": "Edit",
|
|
25
|
+
"selectButton": "Select values",
|
|
26
|
+
"showButton": "Show"
|
|
20
27
|
}
|
|
21
28
|
},
|
|
22
29
|
"form": {
|
|
@@ -17,6 +17,13 @@
|
|
|
17
17
|
"input": {
|
|
18
18
|
"select": {
|
|
19
19
|
"placeholder": "Sélectionnez une valeur"
|
|
20
|
+
},
|
|
21
|
+
"checkbox": {
|
|
22
|
+
"selectedValues": "{nb} valeurs selectionnées",
|
|
23
|
+
"selectedValue": "{nb} valeur selectionnée",
|
|
24
|
+
"editButton": "Modifier",
|
|
25
|
+
"selectButton": "Sélectionner des valeurs",
|
|
26
|
+
"showButton": "Voir"
|
|
20
27
|
}
|
|
21
28
|
},
|
|
22
29
|
"form": {
|
|
@@ -5,7 +5,7 @@ const defaultLocale = 'en';
|
|
|
5
5
|
const messages = { en, fr };
|
|
6
6
|
/**
|
|
7
7
|
* Get Intl object
|
|
8
|
-
* @param
|
|
9
|
-
* @returns
|
|
8
|
+
* @param element - element we need to get the language
|
|
9
|
+
* @returns messages object
|
|
10
10
|
*/
|
|
11
11
|
export const initLocales = (element) => getLocaleMessages(element, messages, defaultLocale);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MgItemMore type guard
|
|
3
|
-
* @param
|
|
4
|
-
* @returns
|
|
3
|
+
* @param element - element to control type
|
|
4
|
+
* @returns truthy if element is mg-item-more
|
|
5
5
|
*/
|
|
6
6
|
const isMgItemMore = (element) => element.nodeName === 'MG-ITEM-MORE';
|
|
7
7
|
export var OverflowBehaviorElements;
|
|
@@ -18,7 +18,6 @@ export class OverflowBehavior {
|
|
|
18
18
|
**********/
|
|
19
19
|
/**
|
|
20
20
|
* Disconnect ResizeObserver
|
|
21
|
-
* @returns {void}
|
|
22
21
|
*/
|
|
23
22
|
this.disconnect = () => {
|
|
24
23
|
this._resizeObserver.disconnect();
|
|
@@ -28,8 +27,7 @@ export class OverflowBehavior {
|
|
|
28
27
|
************/
|
|
29
28
|
/**
|
|
30
29
|
* run overflow behavior
|
|
31
|
-
* @param
|
|
32
|
-
* @returns {void}
|
|
30
|
+
* @param width - width of the container. Optional.
|
|
33
31
|
*/
|
|
34
32
|
this.run = (width) => {
|
|
35
33
|
if (this._moreElement === undefined) {
|
|
@@ -52,14 +50,13 @@ export class OverflowBehavior {
|
|
|
52
50
|
};
|
|
53
51
|
/**
|
|
54
52
|
* Get interactive children filtred by authorized nodeName ['MG-MENU-ITEM', 'MG-BUTTON']
|
|
55
|
-
* @param
|
|
56
|
-
* @returns
|
|
53
|
+
* @param element - element to parse
|
|
54
|
+
* @returns children
|
|
57
55
|
*/
|
|
58
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)); };
|
|
59
57
|
/**
|
|
60
58
|
* Update displayed items in container from a given available space
|
|
61
|
-
* @param
|
|
62
|
-
* @returns {void}
|
|
59
|
+
* @param availableWidth - available width in container to display child items
|
|
63
60
|
*/
|
|
64
61
|
this.updateDisplayedItems = (availableWidth) => {
|
|
65
62
|
this.restoreItems();
|
|
@@ -78,10 +75,10 @@ export class OverflowBehavior {
|
|
|
78
75
|
};
|
|
79
76
|
/**
|
|
80
77
|
* Utility method to know if item overflow partialy or totaly in the container
|
|
81
|
-
* @param
|
|
82
|
-
* @param
|
|
83
|
-
* @param
|
|
84
|
-
* @returns
|
|
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
|
|
85
82
|
*/
|
|
86
83
|
this.isOverflowElement = (cumulateWidth, item, availableWidth) => {
|
|
87
84
|
if (item.previousElementSibling === null || this.isMoreElement(item))
|
|
@@ -93,15 +90,14 @@ export class OverflowBehavior {
|
|
|
93
90
|
};
|
|
94
91
|
/**
|
|
95
92
|
* Utility method to know if a given element is the 'MORE' element
|
|
96
|
-
* @param
|
|
97
|
-
* @returns
|
|
93
|
+
* @param element - element to match with 'MORE' element
|
|
94
|
+
* @returns truthy if element is the 'MORE' element
|
|
98
95
|
*/
|
|
99
96
|
this.isMoreElement = (element) => element.nodeName === 'MG-ITEM-MORE';
|
|
100
97
|
/**
|
|
101
98
|
* Toggle display item element
|
|
102
|
-
* @param
|
|
103
|
-
* @param
|
|
104
|
-
* @returns {void}
|
|
99
|
+
* @param item - item to control
|
|
100
|
+
* @param isHidden - is item hidden
|
|
105
101
|
*/
|
|
106
102
|
this.toggleItem = (item, isHidden) => {
|
|
107
103
|
const mgActionMenuindex = Number(item.getAttribute(OverflowBehaviorElements.BASE_INDEX));
|
|
@@ -114,9 +110,8 @@ export class OverflowBehavior {
|
|
|
114
110
|
};
|
|
115
111
|
/**
|
|
116
112
|
* Toggle element's hidde attribute
|
|
117
|
-
* @param
|
|
118
|
-
* @param
|
|
119
|
-
* @returns {void}
|
|
113
|
+
* @param element - element to toggle
|
|
114
|
+
* @param isHidden - element is hidden
|
|
120
115
|
*/
|
|
121
116
|
this.toggleElement = (element, isHidden) => {
|
|
122
117
|
if (isHidden)
|
|
@@ -126,7 +121,6 @@ export class OverflowBehavior {
|
|
|
126
121
|
};
|
|
127
122
|
/**
|
|
128
123
|
* Remove hidden attributes on all items
|
|
129
|
-
* @returns {void}
|
|
130
124
|
*/
|
|
131
125
|
this.restoreItems = () => {
|
|
132
126
|
[...this._baseChildren, this._moreElement].forEach(item => item.removeAttribute('hidden'));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Create random ID
|
|
3
|
-
* @param
|
|
4
|
-
* @param
|
|
5
|
-
* @returns
|
|
3
|
+
* @param prefix - add prefix to created ID
|
|
4
|
+
* @param length - ID length
|
|
5
|
+
* @returns ID
|
|
6
6
|
*/
|
|
7
7
|
export const createID = (prefix = '', length = 10) => {
|
|
8
8
|
let ID = '';
|
|
@@ -21,8 +21,7 @@ export class ClassList {
|
|
|
21
21
|
constructor(classlist = []) {
|
|
22
22
|
/**
|
|
23
23
|
* Add class
|
|
24
|
-
* @param
|
|
25
|
-
* @returns {void}
|
|
24
|
+
* @param className - class name to add
|
|
26
25
|
*/
|
|
27
26
|
this.add = (className) => {
|
|
28
27
|
if (!this.has(className)) {
|
|
@@ -31,8 +30,7 @@ export class ClassList {
|
|
|
31
30
|
};
|
|
32
31
|
/**
|
|
33
32
|
* Delete class
|
|
34
|
-
* @param
|
|
35
|
-
* @returns {void}
|
|
33
|
+
* @param className - class name to delete
|
|
36
34
|
*/
|
|
37
35
|
this.delete = (className) => {
|
|
38
36
|
const index = this.classes.indexOf(className);
|
|
@@ -42,15 +40,15 @@ export class ClassList {
|
|
|
42
40
|
};
|
|
43
41
|
/**
|
|
44
42
|
* Check if class exist in list
|
|
45
|
-
* @param
|
|
46
|
-
* @returns
|
|
43
|
+
* @param className - class name to check
|
|
44
|
+
* @returns class name is in the list
|
|
47
45
|
*/
|
|
48
46
|
this.has = (className) => {
|
|
49
47
|
return this.classes.includes(className);
|
|
50
48
|
};
|
|
51
49
|
/**
|
|
52
50
|
* Join classes seperated by spaces
|
|
53
|
-
* @returns
|
|
51
|
+
* @returns joined values
|
|
54
52
|
*/
|
|
55
53
|
this.join = () => {
|
|
56
54
|
return this.classes.join(' ');
|
|
@@ -60,15 +58,15 @@ export class ClassList {
|
|
|
60
58
|
}
|
|
61
59
|
/**
|
|
62
60
|
* Check if all items are string
|
|
63
|
-
* @param
|
|
64
|
-
* @returns
|
|
61
|
+
* @param items - items to check
|
|
62
|
+
* @returns all items are string
|
|
65
63
|
*/
|
|
66
64
|
export const allItemsAreString = (items) => Array.isArray(items) && items.every(item => typeof item === 'string');
|
|
67
65
|
/**
|
|
68
66
|
* Check if element is a heading
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
71
|
-
* @returns
|
|
67
|
+
* @param element - slotted element
|
|
68
|
+
* @param tagNames - allowed tag names list
|
|
69
|
+
* @returns element is a heading
|
|
72
70
|
*/
|
|
73
71
|
export const isTagName = (element, tagNames) => {
|
|
74
72
|
return tagNames.includes(element === null || element === void 0 ? void 0 : element.tagName.toLowerCase());
|
|
@@ -79,8 +77,8 @@ export const isTagName = (element, tagNames) => {
|
|
|
79
77
|
export const focusableElements = 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"]), [identifier]';
|
|
80
78
|
/**
|
|
81
79
|
* Get windows
|
|
82
|
-
* @param
|
|
83
|
-
* @returns
|
|
80
|
+
* @param localWindow - the window we are lookink for other windows
|
|
81
|
+
* @returns The list of windows found
|
|
84
82
|
*/
|
|
85
83
|
export const getWindows = (localWindow) => {
|
|
86
84
|
const parentWindows = getParentWindows(localWindow);
|
|
@@ -89,9 +87,9 @@ export const getWindows = (localWindow) => {
|
|
|
89
87
|
};
|
|
90
88
|
/**
|
|
91
89
|
* Get parent windows
|
|
92
|
-
* @param
|
|
93
|
-
* @param
|
|
94
|
-
* @returns
|
|
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
|
|
95
93
|
*/
|
|
96
94
|
export const getParentWindows = (localWindow, windows = []) => {
|
|
97
95
|
// Check if is in iframe
|
|
@@ -111,9 +109,9 @@ export const getParentWindows = (localWindow, windows = []) => {
|
|
|
111
109
|
};
|
|
112
110
|
/**
|
|
113
111
|
* Get child windows
|
|
114
|
-
* @param
|
|
115
|
-
* @param
|
|
116
|
-
* @returns
|
|
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
|
|
117
115
|
*/
|
|
118
116
|
const getChildWindows = (localWindow, windows = []) => {
|
|
119
117
|
if (localWindow.frames.length > 0) {
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Format number to the locale currency
|
|
3
|
-
* @param
|
|
4
|
-
* @param
|
|
5
|
-
* @param
|
|
6
|
-
* @returns
|
|
3
|
+
* @param number - number to format
|
|
4
|
+
* @param locale - locale to apply
|
|
5
|
+
* @param currency - currency to apply
|
|
6
|
+
* @returns formatted currency
|
|
7
7
|
*/
|
|
8
8
|
export const localeCurrency = (number, locale, currency) => {
|
|
9
9
|
return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(number);
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* Format number to locale
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @returns
|
|
13
|
+
* @param number - number to format
|
|
14
|
+
* @param locale - locale to apply
|
|
15
|
+
* @returns formatted number
|
|
16
16
|
*/
|
|
17
17
|
export const localeNumber = (number, locale) => {
|
|
18
18
|
return new Intl.NumberFormat(locale).format(number);
|
|
@@ -23,9 +23,9 @@ export const localeNumber = (number, locale) => {
|
|
|
23
23
|
export const dateRegExp = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
|
|
24
24
|
/**
|
|
25
25
|
* Locale date format
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
* @returns
|
|
26
|
+
* @param date - date to format
|
|
27
|
+
* @param locale - locale to apply
|
|
28
|
+
* @returns formatted date
|
|
29
29
|
*/
|
|
30
30
|
export const localeDate = (date, locale) => {
|
|
31
31
|
if (typeof date !== 'string' || date === '' || !dateRegExp.test(date)) {
|
|
@@ -36,10 +36,10 @@ export const localeDate = (date, locale) => {
|
|
|
36
36
|
/**
|
|
37
37
|
* Get locale and messages
|
|
38
38
|
* We load the defined locale but for now we only support the first subtag for messages
|
|
39
|
-
* @param
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
42
|
-
* @returns
|
|
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
|
|
43
43
|
*/
|
|
44
44
|
export const getLocaleMessages = (element, messages, defaultLocale) => {
|
|
45
45
|
// Get local
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MockCustomEvent } from '@stencil/core/mock-doc';
|
|
2
2
|
/**
|
|
3
3
|
* Clone Deep function
|
|
4
|
-
* @param
|
|
5
|
-
* @returns
|
|
4
|
+
* @param obj - object to clone
|
|
5
|
+
* @returns cloned json
|
|
6
6
|
*/
|
|
7
7
|
export const cloneDeep = (obj) => JSON.parse(JSON.stringify(obj));
|
|
8
8
|
export const setupMutationObserverMock = ({ disconnect, observe, takeRecords }) => {
|
|
@@ -42,11 +42,11 @@ export const setupResizeObserverMock = ({ disconnect, observe }) => {
|
|
|
42
42
|
};
|
|
43
43
|
/**
|
|
44
44
|
* Utility function that mocks the `SubmitEvent` API. Recommended to execute inside `beforeEach`.
|
|
45
|
-
* @returns {void}
|
|
46
45
|
* @example
|
|
47
46
|
* ```
|
|
48
47
|
* setupSubmitEventMock();
|
|
49
48
|
* ```
|
|
49
|
+
* @returns custom event mock
|
|
50
50
|
*/
|
|
51
51
|
export const setupSubmitEventMock = () => {
|
|
52
52
|
class SubmitEvent extends MockCustomEvent {
|
|
@@ -65,10 +65,9 @@ export const setupSubmitEventMock = () => {
|
|
|
65
65
|
};
|
|
66
66
|
/**
|
|
67
67
|
* force popover id when component use randomed identifier
|
|
68
|
-
* @param
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
71
|
-
* @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
|
|
72
71
|
*/
|
|
73
72
|
export const forcePopoverId = (component, id, interactiveElement = 'button') => {
|
|
74
73
|
const popover = component.shadowRoot.querySelector('mg-popover');
|
|
@@ -79,11 +78,10 @@ export const forcePopoverId = (component, id, interactiveElement = 'button') =>
|
|
|
79
78
|
};
|
|
80
79
|
/**
|
|
81
80
|
* fix popper console.error in test
|
|
82
|
-
* it is generated in
|
|
81
|
+
* it is generated in `@popperjs/core/dist/cjs/popper.js l.1859`
|
|
83
82
|
* this is due to internal function isHTMLElement(), so we can not mock it directly.
|
|
84
83
|
* this function check if test DOM element mockHTMLElement instance is 'instanceof HTMLElement'
|
|
85
84
|
* so we only override the console.error side effect for this error
|
|
86
|
-
* @returns {void}
|
|
87
85
|
*/
|
|
88
86
|
export const mockConsoleError = () => {
|
|
89
87
|
jest.spyOn(console, 'error').mockImplementation(error => {
|
|
@@ -95,7 +93,6 @@ export const mockConsoleError = () => {
|
|
|
95
93
|
/**
|
|
96
94
|
* Add missing window.frames property to test context
|
|
97
95
|
* usefull for component with iframe listeners, ex: mg-popover
|
|
98
|
-
* @returns {void}
|
|
99
96
|
*/
|
|
100
97
|
export const mockWindowFrames = () => {
|
|
101
98
|
Object.defineProperty(window, 'frames', {
|
|
@@ -1,11 +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
|
-
* @param
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @returns
|
|
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
|
|
9
14
|
*/
|
|
10
15
|
const applyAriadescribedBy = (children, ariaDescribedbyIDs, utils) => utils.map(children, child => {
|
|
11
16
|
if (['input', 'select', 'textarea'].includes(child.vtag)) {
|
|
@@ -18,29 +23,36 @@ const applyAriadescribedBy = (children, ariaDescribedbyIDs, utils) => utils.map(
|
|
|
18
23
|
});
|
|
19
24
|
/**
|
|
20
25
|
* Add classes based on props
|
|
21
|
-
* @param
|
|
26
|
+
* @param props - MgInput Interface Props
|
|
22
27
|
*/
|
|
23
28
|
const manageClasses = (props) => {
|
|
24
|
-
props.
|
|
29
|
+
props.classCollection.add('mg-input');
|
|
25
30
|
if (props.labelOnTop)
|
|
26
|
-
props.
|
|
31
|
+
props.classCollection.add('mg-input--label-on-top');
|
|
32
|
+
else
|
|
33
|
+
props.classCollection.delete('mg-input--label-on-top');
|
|
27
34
|
if (props.readonly)
|
|
28
|
-
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
|
+
});
|
|
29
41
|
if (props.mgWidth !== undefined)
|
|
30
|
-
props.
|
|
42
|
+
props.classCollection.add(`mg-input--width-${props.mgWidth}`);
|
|
31
43
|
};
|
|
32
44
|
/**
|
|
33
45
|
* Get tagname
|
|
34
|
-
* @param
|
|
35
|
-
* @returns
|
|
46
|
+
* @param isFieldset - is fieldset
|
|
47
|
+
* @returns tag name
|
|
36
48
|
*/
|
|
37
49
|
const getTagName = (isFieldset) => (isFieldset ? 'fieldset' : 'div');
|
|
38
50
|
/**
|
|
39
51
|
* Get input template
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
42
|
-
* @param
|
|
43
|
-
* @returns
|
|
52
|
+
* @param props - MgInput Interface Props
|
|
53
|
+
* @param children - Represent scoped elements
|
|
54
|
+
* @param utils - Stencil.js utils
|
|
55
|
+
* @returns input template
|
|
44
56
|
*/
|
|
45
57
|
const MgInput = (props, children, utils) => {
|
|
46
58
|
/**
|
|
@@ -96,17 +108,17 @@ const MgInput = (props, children, utils) => {
|
|
|
96
108
|
const TagName = getTagName(props.isFieldset);
|
|
97
109
|
/**
|
|
98
110
|
* Get tooltip node
|
|
99
|
-
* @returns
|
|
111
|
+
* @returns mg-tooltip
|
|
100
112
|
*/
|
|
101
113
|
const getTooltip = () => (h("mg-tooltip", { identifier: `${props.identifier}-tooltip`, message: props.tooltip },
|
|
102
114
|
h("mg-icon", { icon: "info-circle" })));
|
|
103
115
|
/**
|
|
104
116
|
* Get input title (label) node
|
|
105
117
|
* Display asterisk only if not disabled and not readonly
|
|
106
|
-
* @returns
|
|
118
|
+
* @returns mg-input-title
|
|
107
119
|
*/
|
|
108
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));
|
|
109
|
-
return (h(TagName, { class: props.
|
|
121
|
+
return (h(TagName, { class: props.classCollection.join() },
|
|
110
122
|
props.labelOnTop ? (h("div", { class: "mg-input__title" },
|
|
111
123
|
getInputTitle(),
|
|
112
124
|
!props.readonly && props.tooltip && getTooltip())) : (getInputTitle()),
|