@mgdis/mg-components 6.14.0 → 6.16.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-DUJwxnoi.js → index-CpENFzEo.js} +2 -2
- package/dist/cjs/{index-DzBkSgSK.js → index-T3-qWqFE.js} +8 -2
- package/dist/cjs/{index-CwjAofQ1.js → index-YM1EJx9X.js} +43 -31
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/mg-action-more_37.cjs.entry.js +136 -150
- package/dist/cjs/mg-alert.cjs.entry.js +4 -4
- package/dist/cjs/mg-components.cjs.js +3 -3
- package/dist/cjs/mg-input-combobox.cjs.entry.js +15 -13
- package/dist/cjs/mg-input-rich-text-editor.cjs.entry.js +1247 -16003
- package/dist/cjs/mg-loader.cjs.entry.js +4 -4
- package/dist/cjs/mg-progress.cjs.entry.js +3 -3
- package/dist/collection/assets/icons/index.js +1 -1
- package/dist/collection/collection-manifest.json +2 -2
- package/dist/collection/components/atoms/mg-icon/mg-icon.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/MgInputCheckboxList.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox-paginated/mg-input-checkbox-paginated.js +49 -106
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +55 -36
- package/dist/collection/components/molecules/inputs/mg-input-combobox/mg-input-combobox.js +11 -9
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +6 -1
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/mg-input-rich-text-editor.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +2 -2
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +1 -1
- package/dist/collection/components/molecules/internals/mg-item-more/mg-item-more.js +1 -1
- package/dist/collection/components/molecules/mg-action-more/mg-action-more.js +2 -2
- package/dist/collection/components/molecules/mg-alert/mg-alert.js +1 -1
- package/dist/collection/components/molecules/mg-details/mg-details.js +1 -1
- package/dist/collection/components/molecules/mg-form/mg-form.js +1 -1
- package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js +1 -1
- package/dist/collection/components/molecules/mg-loader/mg-loader.js +1 -1
- package/dist/collection/components/molecules/mg-message/mg-message.js +2 -2
- package/dist/collection/components/molecules/mg-modal/mg-modal.js +2 -2
- package/dist/collection/components/molecules/mg-panel/mg-panel.js +1 -1
- package/dist/collection/components/molecules/mg-popover/mg-popover-content/mg-popover-content.js +1 -1
- package/dist/collection/components/molecules/mg-popover/mg-popover.js +1 -1
- package/dist/collection/components/molecules/mg-progress/mg-progress.js +1 -1
- package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js +1 -1
- package/dist/collection/components/molecules/mg-table/mg-table.js +2 -2
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +1 -1
- package/dist/collection/locales/en/messages.json +19 -15
- package/dist/collection/locales/fr/messages.json +20 -16
- package/dist/components/index2.js +3 -3
- package/dist/components/index3.js +43 -31
- package/dist/components/mg-action-more.js +2 -2
- package/dist/components/mg-alert.js +2 -2
- package/dist/components/mg-badge2.js +1 -1
- package/dist/components/mg-button2.js +1 -1
- package/dist/components/mg-card2.js +1 -1
- package/dist/components/mg-character-left2.js +1 -1
- package/dist/components/mg-details.js +2 -2
- package/dist/components/mg-divider2.js +1 -1
- package/dist/components/mg-form.js +2 -2
- package/dist/components/mg-icon2.js +1 -1
- package/dist/components/mg-illustrated-message.js +2 -2
- package/dist/components/mg-input-checkbox-paginated2.js +42 -124
- package/dist/components/mg-input-checkbox.js +89 -59
- package/dist/components/mg-input-combobox.js +14 -12
- package/dist/components/mg-input-date.js +2 -2
- package/dist/components/mg-input-numeric.js +7 -2
- package/dist/components/mg-input-password.js +2 -2
- package/dist/components/mg-input-radio.js +2 -2
- package/dist/components/mg-input-rich-text-editor.js +1247 -16003
- package/dist/components/mg-input-select2.js +2 -2
- package/dist/components/mg-input-text2.js +2 -2
- package/dist/components/mg-input-textarea.js +2 -2
- package/dist/components/mg-input-title2.js +1 -1
- package/dist/components/mg-input-toggle.js +2 -2
- package/dist/components/mg-input2.js +1 -1
- package/dist/components/mg-item-more2.js +2 -2
- package/dist/components/mg-loader2.js +2 -2
- package/dist/components/mg-menu-item2.js +1 -1
- package/dist/components/mg-message2.js +3 -3
- package/dist/components/mg-modal.js +3 -3
- package/dist/components/mg-pagination.js +227 -1
- package/dist/components/mg-panel.js +3 -3
- package/dist/components/mg-popover-content2.js +2 -2
- package/dist/components/mg-popover2.js +2 -2
- package/dist/components/mg-progress.js +2 -2
- package/dist/components/mg-skip-links.js +2 -2
- package/dist/components/mg-table.js +3 -3
- package/dist/components/mg-tabs.js +1 -311
- package/dist/components/mg-tabs2.js +313 -0
- package/dist/components/mg-tag.js +1 -1
- package/dist/components/mg-tooltip-content2.js +1 -1
- package/dist/components/mg-tooltip2.js +2 -2
- package/dist/esm/{index-Bv7NHR-W.js → index-Bab8_u8S.js} +43 -31
- package/dist/esm/{index-Degtjvph.js → index-JHj_9FSs.js} +8 -2
- package/dist/esm/{index-Dr7GYvIz.js → index-WtiuOkLj.js} +2 -2
- package/dist/esm/loader.js +3 -3
- package/dist/esm/mg-action-more_37.entry.js +136 -150
- package/dist/esm/mg-alert.entry.js +4 -4
- package/dist/esm/mg-components.js +4 -4
- package/dist/esm/mg-input-combobox.entry.js +15 -13
- package/dist/esm/mg-input-rich-text-editor.entry.js +1248 -16004
- package/dist/esm/mg-loader.entry.js +4 -4
- package/dist/esm/mg-progress.entry.js +3 -3
- package/dist/mg-components/locales/en/messages.json +19 -15
- package/dist/mg-components/locales/fr/messages.json +20 -16
- package/dist/mg-components/mg-components.esm.js +1 -1
- package/dist/mg-components/{p-056ba467.entry.js → p-42a90251.entry.js} +1 -1
- package/dist/mg-components/p-54156253.entry.js +1 -0
- package/dist/mg-components/{p-d13a6fdc.entry.js → p-658f828c.entry.js} +1 -1
- package/dist/mg-components/{p-c522f3c1.entry.js → p-82455ac7.entry.js} +1 -1
- package/dist/mg-components/p-Bab8_u8S.js +1 -0
- package/dist/mg-components/p-JHj_9FSs.js +2 -0
- package/dist/mg-components/p-WtiuOkLj.js +1 -0
- package/dist/mg-components/p-abbd151c.entry.js +1 -0
- package/dist/mg-components/p-c85b5d10.entry.js +1 -0
- package/dist/types/assets/icons/index.d.ts +6 -0
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox-paginated/mg-input-checkbox-paginated.d.ts +17 -40
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.conf.d.ts +1 -2
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +15 -6
- package/dist/types/components/molecules/inputs/mg-input-combobox/mg-input-combobox.d.ts +1 -1
- package/dist/types/components.d.ts +6 -33
- package/ide/intellij/web-types.json +13 -13
- package/ide/vscode/html-custom-data.json +39 -3
- package/package.json +23 -23
- package/dist/components/mg-pagination2.js +0 -229
- package/dist/mg-components/p-625c463c.entry.js +0 -1
- package/dist/mg-components/p-Bv7NHR-W.js +0 -1
- package/dist/mg-components/p-Degtjvph.js +0 -2
- package/dist/mg-components/p-Dr7GYvIz.js +0 -1
- package/dist/mg-components/p-cac23bd7.entry.js +0 -1
- package/dist/mg-components/p-e75f5383.entry.js +0 -10
|
@@ -1,314 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as createID, C as ClassList, n as nextTick, a as isValideID, t as toString, i as isValidString, d as allItemsAreString } from './index2.js';
|
|
3
|
-
import { K as Keys } from './events.utils.js';
|
|
4
|
-
import { d as defineCustomElement$3 } from './mg-badge2.js';
|
|
5
|
-
import { d as defineCustomElement$2 } from './mg-icon2.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Available tabs items status
|
|
9
|
-
*/
|
|
10
|
-
const Status = {
|
|
11
|
-
VISIBLE: 'visible',
|
|
12
|
-
HIDDEN: 'hidden',
|
|
13
|
-
DISABLED: 'disabled',
|
|
14
|
-
ACTIVE: 'active',
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* List of all possibles sizes
|
|
18
|
-
*/
|
|
19
|
-
const sizes = ['medium', 'large'];
|
|
20
|
-
|
|
21
|
-
const mgTabsCss = "/*!\n * @prop --mg-c-tabs-color: Defines tabs global color, used for bottom line and active tabs. Default value: `--mg-b-color-app`.\n * @prop --mg-c-tabs-color-text: Defines tabs text color. Unset by default, fallback on `--mg-b-color-dark`.\n */.mg-c-tabs.mg-c-tabs--size-medium .mg-c-tabs__navigation-button,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-medium{padding:var(--mg-b-size-12) var(--mg-b-size-16)}.mg-c-tabs.mg-c-tabs--size-medium .mg-c-tabs__navigation-button,.mg-c-tabs.mg-c-tabs--size-medium .mg-c-tabs__navigation-button ::slotted([slot=label]),.mg-c-tabs.mg-c-tabs--size-medium .mg-c-tabs__navigation-button ::slotted([slot=metadata]),.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-medium,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-medium ::slotted([slot=label]),.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-medium ::slotted([slot=metadata]){font-size:var(--mg-b-font-size)}.mg-c-tabs.mg-c-tabs--size-medium .mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--horizontal,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-medium.mg-c-tabs__navigation-button--horizontal{padding-bottom:var(--mg-b-size-12)}.mg-c-tabs.mg-c-tabs--size-medium .mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--vertical,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-medium.mg-c-tabs__navigation-button--vertical{padding-left:var(--mg-b-size-16)}.mg-c-tabs.mg-c-tabs--size-large .mg-c-tabs__navigation-button,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-large{padding:var(--mg-b-size-16) var(--mg-b-size-32)}.mg-c-tabs.mg-c-tabs--size-large .mg-c-tabs__navigation-button,.mg-c-tabs.mg-c-tabs--size-large .mg-c-tabs__navigation-button ::slotted([slot=label]),.mg-c-tabs.mg-c-tabs--size-large .mg-c-tabs__navigation-button ::slotted([slot=metadata]),.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-large,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-large ::slotted([slot=label]),.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-large ::slotted([slot=metadata]){font-size:var(--mg-b-font-size-h4)}.mg-c-tabs.mg-c-tabs--size-large .mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--horizontal,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-large.mg-c-tabs__navigation-button--horizontal{padding-bottom:var(--mg-b-size-16)}.mg-c-tabs.mg-c-tabs--size-large .mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--vertical,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-large.mg-c-tabs__navigation-button--vertical{padding-left:var(--mg-b-size-32)}.mg-c-tabs__navigation-button{display:flex;box-sizing:border-box;align-items:center;border:none;background-color:unset;color:var(--mg-c-tabs-color-text, var(--mg-b-color-dark));column-gap:var(--mg-c-tabs-navigation-button-column-gap, var(--mg-b-size-8));cursor:pointer;font-family:var(--mg-b-font-family);font-weight:400;line-height:var(--mg-b-line-height);text-decoration:none;white-space:nowrap}.mg-c-tabs__navigation-button:disabled,.mg-c-tabs__navigation-button--disabled{cursor:default;opacity:var(--mg-b-opacity-element-disabled)}.mg-c-tabs__navigation-button:focus-visible{z-index:10}.mg-c-tabs__navigation-button:hover:not(.mg-c-tabs__navigation-button--disabled),.mg-c-tabs__navigation-button:focus-visible:not(.mg-c-tabs__navigation-button--disabled){background-color:color-mix(in srgb, var(--mg-c-tabs-color), transparent 90%)}.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--active{color:var(--mg-c-tabs-color);font-weight:600}.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--active.mg-c-tabs__navigation-button--horizontal{box-shadow:inset 0 calc(-1*var(--mg-b-size-4)) var(--mg-c-tabs-color)}.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--active.mg-c-tabs__navigation-button--vertical{box-shadow:inset var(--mg-b-size-4) 0 var(--mg-c-tabs-color)}.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--hidden{display:none}.mg-c-tabs__header{display:flex;flex-flow:row wrap;border-bottom:var(--mg-b-size-border) solid color-mix(in srgb, var(--mg-c-tabs-color), transparent 90%)}.mg-c-tabs__content-container:focus-visible{outline:none}.mg-c-tabs__navigation-button-text{flex:0 0 content}";
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* type TabItem validation function
|
|
25
|
-
* @param tab - tab item
|
|
26
|
-
* @returns tab item type is valid
|
|
27
|
-
*/
|
|
28
|
-
const isTabItem = (tab) => typeof tab === 'object' && typeof tab.label === 'string';
|
|
29
|
-
const MgTabs$1 = /*@__PURE__*/ proxyCustomElement(class MgTabs extends HTMLElement {
|
|
30
|
-
constructor() {
|
|
31
|
-
super();
|
|
32
|
-
this.__registerHost();
|
|
33
|
-
this.__attachShadow();
|
|
34
|
-
this.activeTabChange = createEvent(this, "active-tab-change", 7);
|
|
35
|
-
/************
|
|
36
|
-
* Internal *
|
|
37
|
-
************/
|
|
38
|
-
// classes
|
|
39
|
-
this.tabPanel = 'panel';
|
|
40
|
-
this.buttonTabBaseClass = 'mg-c-tabs__navigation-button';
|
|
41
|
-
this.startIndex = 1;
|
|
42
|
-
/**
|
|
43
|
-
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
44
|
-
* If not set, it will be created.
|
|
45
|
-
*/
|
|
46
|
-
this.identifier = createID('mg-tabs');
|
|
47
|
-
/**
|
|
48
|
-
* Define tabs size
|
|
49
|
-
*/
|
|
50
|
-
this.size = 'medium';
|
|
51
|
-
/**
|
|
52
|
-
* Component tabs
|
|
53
|
-
*/
|
|
54
|
-
this.tabs = [];
|
|
55
|
-
/**
|
|
56
|
-
* Component classes
|
|
57
|
-
*/
|
|
58
|
-
this.classCollection = new ClassList(['mg-c-tabs']);
|
|
59
|
-
/**
|
|
60
|
-
* Validate that new tab status can be `Status.ACTIVE`
|
|
61
|
-
* @param tab - tab item
|
|
62
|
-
* @returns true when tab match condition to get a `Status.ACTIVE`
|
|
63
|
-
*/
|
|
64
|
-
this.isActivableTab = (tab) => [undefined, Status.ACTIVE, Status.VISIBLE].includes(tab.status);
|
|
65
|
-
/**
|
|
66
|
-
* Method to know if given tab has the given status
|
|
67
|
-
* @param tab - item tab key to set to ACTIVE status
|
|
68
|
-
* @param status - status to valide
|
|
69
|
-
* @returns status comparaison
|
|
70
|
-
*/
|
|
71
|
-
this.tabHasStatus = (tab, status) => tab.status === status;
|
|
72
|
-
/**
|
|
73
|
-
* Method to get element id from index
|
|
74
|
-
* @param element - to get id
|
|
75
|
-
* @param index - to generate id
|
|
76
|
-
* @returns generated element id
|
|
77
|
-
*/
|
|
78
|
-
this.getElementId = (element, index) => `${element}-${this.getTabItemIndex(index)}`;
|
|
79
|
-
/**
|
|
80
|
-
* Method to get tab item index
|
|
81
|
-
* @param index - to get
|
|
82
|
-
* @returns index
|
|
83
|
-
*/
|
|
84
|
-
this.getTabItemIndex = (index) => index + this.startIndex;
|
|
85
|
-
/**
|
|
86
|
-
* Handle click events on tabs
|
|
87
|
-
* @param event - mouse event
|
|
88
|
-
*/
|
|
89
|
-
this.handleClick = (event) => {
|
|
90
|
-
const tabId = event.currentTarget.dataset.index;
|
|
91
|
-
if (!this.isActivableTab(this.tabs[Number(tabId) - this.startIndex])) {
|
|
92
|
-
event.preventDefault();
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
this.activeTab = Number(tabId);
|
|
96
|
-
this.tabFocus = undefined;
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* get navigation button class from given status
|
|
101
|
-
* @param status - button tab status
|
|
102
|
-
* @returns button class/selector variant
|
|
103
|
-
*/
|
|
104
|
-
this.getNavigationButtonClass = (status) => `${this.buttonTabBaseClass}--${status}`;
|
|
105
|
-
/**
|
|
106
|
-
* Handle keyboard event on tabs
|
|
107
|
-
* @param event - mouse event
|
|
108
|
-
*/
|
|
109
|
-
this.handleKeydown = (event) => {
|
|
110
|
-
const parent = event.target.parentElement;
|
|
111
|
-
if ([Keys.ARROWLEFT, Keys.ARROWRIGHT].includes(event.key)) {
|
|
112
|
-
this.tabFocus = Number(event.target.dataset.index);
|
|
113
|
-
parent.querySelector(`[data-index="${this.tabFocus}"]`).setAttribute('tabindex', '-1');
|
|
114
|
-
// Move right
|
|
115
|
-
if (event.key === Keys.ARROWRIGHT) {
|
|
116
|
-
this.tabFocus++;
|
|
117
|
-
// If we're at the end, go to the start
|
|
118
|
-
if (this.tabFocus > this.tabs.length)
|
|
119
|
-
this.tabFocus = this.startIndex;
|
|
120
|
-
// Move left
|
|
121
|
-
}
|
|
122
|
-
else if (event.key === Keys.ARROWLEFT) {
|
|
123
|
-
this.tabFocus--;
|
|
124
|
-
// If we're at the start, move to the end
|
|
125
|
-
if (this.tabFocus < this.startIndex)
|
|
126
|
-
this.tabFocus = this.tabs.length;
|
|
127
|
-
}
|
|
128
|
-
const parentButtonElement = parent.querySelector(`[data-index="${this.tabFocus}"]`);
|
|
129
|
-
// if focus item is ['hidden'] we recursively repeat action
|
|
130
|
-
if (this.tabHasStatus(this.tabs[this.tabFocus - 1], Status.HIDDEN)) {
|
|
131
|
-
parentButtonElement.dispatchEvent(new KeyboardEvent('keydown', { key: event.key, bubbles: true }));
|
|
132
|
-
// else run focus methods on tabFocus element
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
parentButtonElement.setAttribute('tabindex', '0');
|
|
136
|
-
parentButtonElement.focus();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
else if (event.key === Keys.TAB) {
|
|
140
|
-
this.resetFocus();
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
/**
|
|
144
|
-
* Reset focus on document click
|
|
145
|
-
* @param event - mouse event
|
|
146
|
-
*/
|
|
147
|
-
this.handleDocumentClick = (event) => {
|
|
148
|
-
if (event.target.closest('mg-tabs') !== this.element)
|
|
149
|
-
this.resetFocus();
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* Method to reset focus behavior
|
|
153
|
-
*/
|
|
154
|
-
this.resetFocus = () => {
|
|
155
|
-
// update asynchronously tabindex to prevent get focus on new tabindex at then end of event process
|
|
156
|
-
nextTick(() => {
|
|
157
|
-
this.tabFocus = undefined;
|
|
158
|
-
Array.from(this.element.shadowRoot.querySelectorAll('[data-index]')).forEach((tab, index) => {
|
|
159
|
-
tab.setAttribute('tabindex', this.activeTab - this.startIndex !== index ? '-1' : '0');
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
};
|
|
163
|
-
/**
|
|
164
|
-
* Validate slots setting
|
|
165
|
-
*/
|
|
166
|
-
this.validateSlots = () => {
|
|
167
|
-
const slots = Array.from(this.element.children).filter(slot => { var _a; return (_a = slot.getAttribute('slot')) === null || _a === void 0 ? void 0 : _a.includes('tab_content-'); });
|
|
168
|
-
if (slots.length !== this.tabs.length)
|
|
169
|
-
throw new Error('<mg-tabs> Must have slots counts equal to tabs count.');
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
watchIdentifier(newValue) {
|
|
173
|
-
if (!isValideID(newValue)) {
|
|
174
|
-
console.error(`<mg-tabs> prop "identifier" value is invalid. Passed value: ${toString(newValue)}.`);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
validateLabel(newValue) {
|
|
178
|
-
if (!isValidString(newValue)) {
|
|
179
|
-
throw new Error(`<mg-tabs> prop "label" is required and must be a string. Passed value: ${toString(newValue)}.`);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
validateSize(newValue) {
|
|
183
|
-
if (!sizes.includes(newValue)) {
|
|
184
|
-
throw new Error(`<mg-tabs> prop "size" must be one of: ${sizes.join(', ')}. Passed value: ${toString(newValue)}.`);
|
|
185
|
-
}
|
|
186
|
-
this.classCollection.add(`mg-c-tabs--size-${this.size}`);
|
|
187
|
-
}
|
|
188
|
-
validateItems(newValue) {
|
|
189
|
-
// String array
|
|
190
|
-
if (allItemsAreString(newValue))
|
|
191
|
-
this.tabs = newValue.map(item => ({ label: item, status: Status.VISIBLE }));
|
|
192
|
-
// Object array
|
|
193
|
-
else if (Array.isArray(newValue) && newValue.length > 0 && newValue.every(isTabItem))
|
|
194
|
-
this.tabs = newValue;
|
|
195
|
-
else
|
|
196
|
-
throw new Error(`<mg-tabs> prop "items" is required and all items must be the same type: TabItem. Passed value: ${toString(newValue)}.`);
|
|
197
|
-
}
|
|
198
|
-
validateActiveTab(newValue) {
|
|
199
|
-
// when `active-tab` is undefined we set default value by searching an item with `Status.ACTIVE` or we use the `startIndex` has fallback value
|
|
200
|
-
// after setting new value to `active-tab` the validate will be triggered again with the updated value and process the tab update
|
|
201
|
-
if (newValue === undefined) {
|
|
202
|
-
this.activeTab = this.tabs.some(tab => this.tabHasStatus(tab, Status.ACTIVE))
|
|
203
|
-
? this.getTabItemIndex(this.tabs.findIndex(tab => this.tabHasStatus(tab, Status.ACTIVE)))
|
|
204
|
-
: this.startIndex;
|
|
205
|
-
}
|
|
206
|
-
else if (typeof newValue === 'number' && newValue >= this.startIndex && newValue <= this.tabs.length && this.isActivableTab(this.tabs[newValue - this.startIndex])) {
|
|
207
|
-
// if new 'active-tab' is activable we update tab status to ACTIVE and toggle past ACTIVE to VISIBLE
|
|
208
|
-
this.tabs.forEach((tab, index) => {
|
|
209
|
-
const isNewActiveTab = index === newValue - this.startIndex;
|
|
210
|
-
// reset active tabs
|
|
211
|
-
if (this.tabHasStatus(tab, Status.ACTIVE) && !isNewActiveTab)
|
|
212
|
-
tab.status = Status.VISIBLE;
|
|
213
|
-
// set active tab from given tab key
|
|
214
|
-
else if (this.isActivableTab(tab) && isNewActiveTab)
|
|
215
|
-
tab.status = Status.ACTIVE;
|
|
216
|
-
});
|
|
217
|
-
// emit change active tab key event
|
|
218
|
-
this.activeTabChange.emit(newValue);
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
throw new Error(`<mg-tabs> prop "activeTab" must be a number between ${this.startIndex} and ${this.tabs.length} and new value must be "activable". Passed value: ${toString(newValue)}.`);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
/*************
|
|
225
|
-
* Lifecycle *
|
|
226
|
-
*************/
|
|
227
|
-
/**
|
|
228
|
-
* Check if component props are well configured on init
|
|
229
|
-
*/
|
|
230
|
-
componentWillLoad() {
|
|
231
|
-
// Check tabs format
|
|
232
|
-
this.watchIdentifier(this.identifier);
|
|
233
|
-
this.validateLabel(this.label);
|
|
234
|
-
this.validateItems(this.items);
|
|
235
|
-
this.validateActiveTab(this.activeTab);
|
|
236
|
-
this.validateSize(this.size);
|
|
237
|
-
this.validateSlots();
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* add listners
|
|
241
|
-
*/
|
|
242
|
-
componentDidLoad() {
|
|
243
|
-
document.addEventListener('click', this.handleDocumentClick, false);
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* remove listeners
|
|
247
|
-
*/
|
|
248
|
-
disconnectedCallback() {
|
|
249
|
-
document.removeEventListener('keydown', this.handleDocumentClick);
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Render
|
|
253
|
-
* @returns HTML Element
|
|
254
|
-
*/
|
|
255
|
-
render() {
|
|
256
|
-
return (h("div", { key: '06dd97d9d4e77f606dee3c4a8960b51265345666', class: this.classCollection.join() }, h("header", { key: 'ea3771bdfe8576bb8b443823a2c338a51ed3ba69', role: "tablist", "aria-label": this.label, class: "mg-c-tabs__header" }, this.tabs.map((tab, index) => (h("button", { key: tab.label, role: "tab", id: this.getElementId(this.identifier, index), class: {
|
|
257
|
-
[`${this.buttonTabBaseClass}`]: true,
|
|
258
|
-
[`${this.buttonTabBaseClass}--horizontal`]: true,
|
|
259
|
-
[`${this.getNavigationButtonClass(Status.ACTIVE)}`]: this.tabHasStatus(tab, Status.ACTIVE),
|
|
260
|
-
[`${this.getNavigationButtonClass(Status.DISABLED)}`]: this.tabHasStatus(tab, Status.DISABLED),
|
|
261
|
-
[`${this.getNavigationButtonClass(Status.HIDDEN)}`]: this.tabHasStatus(tab, Status.HIDDEN),
|
|
262
|
-
}, tabindex: this.tabHasStatus(tab, Status.ACTIVE) ? 0 : -1, "aria-selected": this.tabHasStatus(tab, Status.ACTIVE).toString(), "aria-controls": this.getElementId(this.tabPanel, index), "aria-disabled": this.tabHasStatus(tab, Status.DISABLED), onClick: this.handleClick, onKeyDown: this.handleKeydown, "data-index": this.getTabItemIndex(index) }, tab.icon !== undefined && h("mg-icon", { icon: tab.icon }), tab.label, tab.badge !== undefined && h("mg-badge", { variant: "text-color", value: tab.badge.value, label: tab.badge.label, outline: tab.badge.role === 'information' }))))), this.tabs.map((tab, index) => (h("article", { key: tab.label, role: "tabpanel", id: this.getElementId(this.tabPanel, index), hidden: !this.tabHasStatus(tab, Status.ACTIVE), "aria-labelledby": this.getElementId(this.identifier, index), tabindex: this.tabHasStatus(tab, Status.ACTIVE) ? 0 : -1, class: "mg-c-tabs__content-container" }, h("slot", { name: this.getElementId('tab_content', index) }))))));
|
|
263
|
-
}
|
|
264
|
-
get element() { return this; }
|
|
265
|
-
static get watchers() { return {
|
|
266
|
-
"identifier": ["watchIdentifier"],
|
|
267
|
-
"label": ["validateLabel"],
|
|
268
|
-
"size": ["validateSize"],
|
|
269
|
-
"items": ["validateItems"],
|
|
270
|
-
"activeTab": ["validateActiveTab"]
|
|
271
|
-
}; }
|
|
272
|
-
static get style() { return mgTabsCss; }
|
|
273
|
-
}, [1, "mg-tabs", {
|
|
274
|
-
"identifier": [1],
|
|
275
|
-
"label": [1],
|
|
276
|
-
"size": [1],
|
|
277
|
-
"items": [16],
|
|
278
|
-
"activeTab": [1538, "active-tab"],
|
|
279
|
-
"tabs": [32],
|
|
280
|
-
"classCollection": [32]
|
|
281
|
-
}, undefined, {
|
|
282
|
-
"identifier": ["watchIdentifier"],
|
|
283
|
-
"label": ["validateLabel"],
|
|
284
|
-
"size": ["validateSize"],
|
|
285
|
-
"items": ["validateItems"],
|
|
286
|
-
"activeTab": ["validateActiveTab"]
|
|
287
|
-
}]);
|
|
288
|
-
function defineCustomElement$1() {
|
|
289
|
-
if (typeof customElements === "undefined") {
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
const components = ["mg-tabs", "mg-badge", "mg-icon"];
|
|
293
|
-
components.forEach(tagName => { switch (tagName) {
|
|
294
|
-
case "mg-tabs":
|
|
295
|
-
if (!customElements.get(tagName)) {
|
|
296
|
-
customElements.define(tagName, MgTabs$1);
|
|
297
|
-
}
|
|
298
|
-
break;
|
|
299
|
-
case "mg-badge":
|
|
300
|
-
if (!customElements.get(tagName)) {
|
|
301
|
-
defineCustomElement$3();
|
|
302
|
-
}
|
|
303
|
-
break;
|
|
304
|
-
case "mg-icon":
|
|
305
|
-
if (!customElements.get(tagName)) {
|
|
306
|
-
defineCustomElement$2();
|
|
307
|
-
}
|
|
308
|
-
break;
|
|
309
|
-
} });
|
|
310
|
-
}
|
|
311
|
-
defineCustomElement$1();
|
|
1
|
+
import { M as MgTabs$1, d as defineCustomElement$1 } from './mg-tabs2.js';
|
|
312
2
|
|
|
313
3
|
const MgTabs = MgTabs$1;
|
|
314
4
|
const defineCustomElement = defineCustomElement$1;
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
|
|
2
|
+
import { c as createID, C as ClassList, n as nextTick, a as isValideID, t as toString, i as isValidString, d as allItemsAreString } from './index2.js';
|
|
3
|
+
import { K as Keys } from './events.utils.js';
|
|
4
|
+
import { d as defineCustomElement$2 } from './mg-badge2.js';
|
|
5
|
+
import { d as defineCustomElement$1 } from './mg-icon2.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Available tabs items status
|
|
9
|
+
*/
|
|
10
|
+
const Status = {
|
|
11
|
+
VISIBLE: 'visible',
|
|
12
|
+
HIDDEN: 'hidden',
|
|
13
|
+
DISABLED: 'disabled',
|
|
14
|
+
ACTIVE: 'active',
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* List of all possibles sizes
|
|
18
|
+
*/
|
|
19
|
+
const sizes = ['medium', 'large'];
|
|
20
|
+
|
|
21
|
+
const mgTabsCss = "/*!\n * @prop --mg-c-tabs-color: Defines tabs global color, used for bottom line and active tabs. Default value: `--mg-b-color-app`.\n * @prop --mg-c-tabs-color-text: Defines tabs text color. Unset by default, fallback on `--mg-b-color-dark`.\n */.mg-c-tabs.mg-c-tabs--size-medium .mg-c-tabs__navigation-button,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-medium{padding:var(--mg-b-size-12) var(--mg-b-size-16)}.mg-c-tabs.mg-c-tabs--size-medium .mg-c-tabs__navigation-button,.mg-c-tabs.mg-c-tabs--size-medium .mg-c-tabs__navigation-button ::slotted([slot=label]),.mg-c-tabs.mg-c-tabs--size-medium .mg-c-tabs__navigation-button ::slotted([slot=metadata]),.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-medium,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-medium ::slotted([slot=label]),.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-medium ::slotted([slot=metadata]){font-size:var(--mg-b-font-size)}.mg-c-tabs.mg-c-tabs--size-medium .mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--horizontal,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-medium.mg-c-tabs__navigation-button--horizontal{padding-bottom:var(--mg-b-size-12)}.mg-c-tabs.mg-c-tabs--size-medium .mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--vertical,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-medium.mg-c-tabs__navigation-button--vertical{padding-left:var(--mg-b-size-16)}.mg-c-tabs.mg-c-tabs--size-large .mg-c-tabs__navigation-button,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-large{padding:var(--mg-b-size-16) var(--mg-b-size-32)}.mg-c-tabs.mg-c-tabs--size-large .mg-c-tabs__navigation-button,.mg-c-tabs.mg-c-tabs--size-large .mg-c-tabs__navigation-button ::slotted([slot=label]),.mg-c-tabs.mg-c-tabs--size-large .mg-c-tabs__navigation-button ::slotted([slot=metadata]),.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-large,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-large ::slotted([slot=label]),.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-large ::slotted([slot=metadata]){font-size:var(--mg-b-font-size-h4)}.mg-c-tabs.mg-c-tabs--size-large .mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--horizontal,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-large.mg-c-tabs__navigation-button--horizontal{padding-bottom:var(--mg-b-size-16)}.mg-c-tabs.mg-c-tabs--size-large .mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--vertical,.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--size-large.mg-c-tabs__navigation-button--vertical{padding-left:var(--mg-b-size-32)}.mg-c-tabs__navigation-button{display:flex;box-sizing:border-box;align-items:center;border:none;background-color:unset;color:var(--mg-c-tabs-color-text, var(--mg-b-color-dark));column-gap:var(--mg-c-tabs-navigation-button-column-gap, var(--mg-b-size-8));cursor:pointer;font-family:var(--mg-b-font-family);font-weight:400;line-height:var(--mg-b-line-height);text-decoration:none;white-space:nowrap}.mg-c-tabs__navigation-button:disabled,.mg-c-tabs__navigation-button--disabled{cursor:default;opacity:var(--mg-b-opacity-element-disabled)}.mg-c-tabs__navigation-button:focus-visible{z-index:10}.mg-c-tabs__navigation-button:hover:not(.mg-c-tabs__navigation-button--disabled),.mg-c-tabs__navigation-button:focus-visible:not(.mg-c-tabs__navigation-button--disabled){background-color:color-mix(in srgb, var(--mg-c-tabs-color), transparent 90%)}.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--active{color:var(--mg-c-tabs-color);font-weight:600}.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--active.mg-c-tabs__navigation-button--horizontal{box-shadow:inset 0 calc(-1*var(--mg-b-size-4)) var(--mg-c-tabs-color)}.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--active.mg-c-tabs__navigation-button--vertical{box-shadow:inset var(--mg-b-size-4) 0 var(--mg-c-tabs-color)}.mg-c-tabs__navigation-button.mg-c-tabs__navigation-button--hidden{display:none}.mg-c-tabs__header{display:flex;flex-flow:row wrap;border-bottom:var(--mg-b-size-border) solid color-mix(in srgb, var(--mg-c-tabs-color), transparent 90%)}.mg-c-tabs__content-container:focus-visible{outline:none}.mg-c-tabs__navigation-button-text{flex:0 0 content}";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* type TabItem validation function
|
|
25
|
+
* @param tab - tab item
|
|
26
|
+
* @returns tab item type is valid
|
|
27
|
+
*/
|
|
28
|
+
const isTabItem = (tab) => typeof tab === 'object' && typeof tab.label === 'string';
|
|
29
|
+
const MgTabs = /*@__PURE__*/ proxyCustomElement(class MgTabs extends HTMLElement {
|
|
30
|
+
constructor() {
|
|
31
|
+
super();
|
|
32
|
+
this.__registerHost();
|
|
33
|
+
this.__attachShadow();
|
|
34
|
+
this.activeTabChange = createEvent(this, "active-tab-change", 7);
|
|
35
|
+
/************
|
|
36
|
+
* Internal *
|
|
37
|
+
************/
|
|
38
|
+
// classes
|
|
39
|
+
this.tabPanel = 'panel';
|
|
40
|
+
this.buttonTabBaseClass = 'mg-c-tabs__navigation-button';
|
|
41
|
+
this.startIndex = 1;
|
|
42
|
+
/**
|
|
43
|
+
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
44
|
+
* If not set, it will be created.
|
|
45
|
+
*/
|
|
46
|
+
this.identifier = createID('mg-tabs');
|
|
47
|
+
/**
|
|
48
|
+
* Define tabs size
|
|
49
|
+
*/
|
|
50
|
+
this.size = 'medium';
|
|
51
|
+
/**
|
|
52
|
+
* Component tabs
|
|
53
|
+
*/
|
|
54
|
+
this.tabs = [];
|
|
55
|
+
/**
|
|
56
|
+
* Component classes
|
|
57
|
+
*/
|
|
58
|
+
this.classCollection = new ClassList(['mg-c-tabs']);
|
|
59
|
+
/**
|
|
60
|
+
* Validate that new tab status can be `Status.ACTIVE`
|
|
61
|
+
* @param tab - tab item
|
|
62
|
+
* @returns true when tab match condition to get a `Status.ACTIVE`
|
|
63
|
+
*/
|
|
64
|
+
this.isActivableTab = (tab) => [undefined, Status.ACTIVE, Status.VISIBLE].includes(tab.status);
|
|
65
|
+
/**
|
|
66
|
+
* Method to know if given tab has the given status
|
|
67
|
+
* @param tab - item tab key to set to ACTIVE status
|
|
68
|
+
* @param status - status to valide
|
|
69
|
+
* @returns status comparaison
|
|
70
|
+
*/
|
|
71
|
+
this.tabHasStatus = (tab, status) => tab.status === status;
|
|
72
|
+
/**
|
|
73
|
+
* Method to get element id from index
|
|
74
|
+
* @param element - to get id
|
|
75
|
+
* @param index - to generate id
|
|
76
|
+
* @returns generated element id
|
|
77
|
+
*/
|
|
78
|
+
this.getElementId = (element, index) => `${element}-${this.getTabItemIndex(index)}`;
|
|
79
|
+
/**
|
|
80
|
+
* Method to get tab item index
|
|
81
|
+
* @param index - to get
|
|
82
|
+
* @returns index
|
|
83
|
+
*/
|
|
84
|
+
this.getTabItemIndex = (index) => index + this.startIndex;
|
|
85
|
+
/**
|
|
86
|
+
* Handle click events on tabs
|
|
87
|
+
* @param event - mouse event
|
|
88
|
+
*/
|
|
89
|
+
this.handleClick = (event) => {
|
|
90
|
+
const tabId = event.currentTarget.dataset.index;
|
|
91
|
+
if (!this.isActivableTab(this.tabs[Number(tabId) - this.startIndex])) {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
this.activeTab = Number(tabId);
|
|
96
|
+
this.tabFocus = undefined;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* get navigation button class from given status
|
|
101
|
+
* @param status - button tab status
|
|
102
|
+
* @returns button class/selector variant
|
|
103
|
+
*/
|
|
104
|
+
this.getNavigationButtonClass = (status) => `${this.buttonTabBaseClass}--${status}`;
|
|
105
|
+
/**
|
|
106
|
+
* Handle keyboard event on tabs
|
|
107
|
+
* @param event - mouse event
|
|
108
|
+
*/
|
|
109
|
+
this.handleKeydown = (event) => {
|
|
110
|
+
const parent = event.target.parentElement;
|
|
111
|
+
if ([Keys.ARROWLEFT, Keys.ARROWRIGHT].includes(event.key)) {
|
|
112
|
+
this.tabFocus = Number(event.target.dataset.index);
|
|
113
|
+
parent.querySelector(`[data-index="${this.tabFocus}"]`).setAttribute('tabindex', '-1');
|
|
114
|
+
// Move right
|
|
115
|
+
if (event.key === Keys.ARROWRIGHT) {
|
|
116
|
+
this.tabFocus++;
|
|
117
|
+
// If we're at the end, go to the start
|
|
118
|
+
if (this.tabFocus > this.tabs.length)
|
|
119
|
+
this.tabFocus = this.startIndex;
|
|
120
|
+
// Move left
|
|
121
|
+
}
|
|
122
|
+
else if (event.key === Keys.ARROWLEFT) {
|
|
123
|
+
this.tabFocus--;
|
|
124
|
+
// If we're at the start, move to the end
|
|
125
|
+
if (this.tabFocus < this.startIndex)
|
|
126
|
+
this.tabFocus = this.tabs.length;
|
|
127
|
+
}
|
|
128
|
+
const parentButtonElement = parent.querySelector(`[data-index="${this.tabFocus}"]`);
|
|
129
|
+
// if focus item is ['hidden'] we recursively repeat action
|
|
130
|
+
if (this.tabHasStatus(this.tabs[this.tabFocus - 1], Status.HIDDEN)) {
|
|
131
|
+
parentButtonElement.dispatchEvent(new KeyboardEvent('keydown', { key: event.key, bubbles: true }));
|
|
132
|
+
// else run focus methods on tabFocus element
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
parentButtonElement.setAttribute('tabindex', '0');
|
|
136
|
+
parentButtonElement.focus();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else if (event.key === Keys.TAB) {
|
|
140
|
+
this.resetFocus();
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Reset focus on document click
|
|
145
|
+
* @param event - mouse event
|
|
146
|
+
*/
|
|
147
|
+
this.handleDocumentClick = (event) => {
|
|
148
|
+
if (event.target.closest('mg-tabs') !== this.element)
|
|
149
|
+
this.resetFocus();
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Method to reset focus behavior
|
|
153
|
+
*/
|
|
154
|
+
this.resetFocus = () => {
|
|
155
|
+
// update asynchronously tabindex to prevent get focus on new tabindex at then end of event process
|
|
156
|
+
nextTick(() => {
|
|
157
|
+
this.tabFocus = undefined;
|
|
158
|
+
Array.from(this.element.shadowRoot.querySelectorAll('[data-index]')).forEach((tab, index) => {
|
|
159
|
+
tab.setAttribute('tabindex', this.activeTab - this.startIndex !== index ? '-1' : '0');
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Validate slots setting
|
|
165
|
+
*/
|
|
166
|
+
this.validateSlots = () => {
|
|
167
|
+
const slots = Array.from(this.element.children).filter(slot => { var _a; return (_a = slot.getAttribute('slot')) === null || _a === void 0 ? void 0 : _a.includes('tab_content-'); });
|
|
168
|
+
if (slots.length !== this.tabs.length)
|
|
169
|
+
throw new Error('<mg-tabs> Must have slots counts equal to tabs count.');
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
watchIdentifier(newValue) {
|
|
173
|
+
if (!isValideID(newValue)) {
|
|
174
|
+
console.error(`<mg-tabs> prop "identifier" value is invalid. Passed value: ${toString(newValue)}.`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
validateLabel(newValue) {
|
|
178
|
+
if (!isValidString(newValue)) {
|
|
179
|
+
throw new Error(`<mg-tabs> prop "label" is required and must be a string. Passed value: ${toString(newValue)}.`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
validateSize(newValue) {
|
|
183
|
+
if (!sizes.includes(newValue)) {
|
|
184
|
+
throw new Error(`<mg-tabs> prop "size" must be one of: ${sizes.join(', ')}. Passed value: ${toString(newValue)}.`);
|
|
185
|
+
}
|
|
186
|
+
this.classCollection.add(`mg-c-tabs--size-${this.size}`);
|
|
187
|
+
}
|
|
188
|
+
validateItems(newValue) {
|
|
189
|
+
// String array
|
|
190
|
+
if (allItemsAreString(newValue))
|
|
191
|
+
this.tabs = newValue.map(item => ({ label: item, status: Status.VISIBLE }));
|
|
192
|
+
// Object array
|
|
193
|
+
else if (Array.isArray(newValue) && newValue.length > 0 && newValue.every(isTabItem))
|
|
194
|
+
this.tabs = newValue;
|
|
195
|
+
else
|
|
196
|
+
throw new Error(`<mg-tabs> prop "items" is required and all items must be the same type: TabItem. Passed value: ${toString(newValue)}.`);
|
|
197
|
+
}
|
|
198
|
+
validateActiveTab(newValue) {
|
|
199
|
+
// when `active-tab` is undefined we set default value by searching an item with `Status.ACTIVE` or we use the `startIndex` has fallback value
|
|
200
|
+
// after setting new value to `active-tab` the validate will be triggered again with the updated value and process the tab update
|
|
201
|
+
if (newValue === undefined) {
|
|
202
|
+
this.activeTab = this.tabs.some(tab => this.tabHasStatus(tab, Status.ACTIVE))
|
|
203
|
+
? this.getTabItemIndex(this.tabs.findIndex(tab => this.tabHasStatus(tab, Status.ACTIVE)))
|
|
204
|
+
: this.startIndex;
|
|
205
|
+
}
|
|
206
|
+
else if (typeof newValue === 'number' && newValue >= this.startIndex && newValue <= this.tabs.length && this.isActivableTab(this.tabs[newValue - this.startIndex])) {
|
|
207
|
+
// if new 'active-tab' is activable we update tab status to ACTIVE and toggle past ACTIVE to VISIBLE
|
|
208
|
+
this.tabs.forEach((tab, index) => {
|
|
209
|
+
const isNewActiveTab = index === newValue - this.startIndex;
|
|
210
|
+
// reset active tabs
|
|
211
|
+
if (this.tabHasStatus(tab, Status.ACTIVE) && !isNewActiveTab)
|
|
212
|
+
tab.status = Status.VISIBLE;
|
|
213
|
+
// set active tab from given tab key
|
|
214
|
+
else if (this.isActivableTab(tab) && isNewActiveTab)
|
|
215
|
+
tab.status = Status.ACTIVE;
|
|
216
|
+
});
|
|
217
|
+
// emit change active tab key event
|
|
218
|
+
this.activeTabChange.emit(newValue);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
throw new Error(`<mg-tabs> prop "activeTab" must be a number between ${this.startIndex} and ${this.tabs.length} and new value must be "activable". Passed value: ${toString(newValue)}.`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/*************
|
|
225
|
+
* Lifecycle *
|
|
226
|
+
*************/
|
|
227
|
+
/**
|
|
228
|
+
* Check if component props are well configured on init
|
|
229
|
+
*/
|
|
230
|
+
componentWillLoad() {
|
|
231
|
+
// Check tabs format
|
|
232
|
+
this.watchIdentifier(this.identifier);
|
|
233
|
+
this.validateLabel(this.label);
|
|
234
|
+
this.validateItems(this.items);
|
|
235
|
+
this.validateActiveTab(this.activeTab);
|
|
236
|
+
this.validateSize(this.size);
|
|
237
|
+
this.validateSlots();
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* add listners
|
|
241
|
+
*/
|
|
242
|
+
componentDidLoad() {
|
|
243
|
+
document.addEventListener('click', this.handleDocumentClick, false);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* remove listeners
|
|
247
|
+
*/
|
|
248
|
+
disconnectedCallback() {
|
|
249
|
+
document.removeEventListener('keydown', this.handleDocumentClick);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Render
|
|
253
|
+
* @returns HTML Element
|
|
254
|
+
*/
|
|
255
|
+
render() {
|
|
256
|
+
return (h("div", { key: '97f18baca4ae45b85401fd38570fe16d8df46c2b', class: this.classCollection.join() }, h("header", { key: '46cffaf2e14dde2a4994e894358caee7553b3bd6', role: "tablist", "aria-label": this.label, class: "mg-c-tabs__header" }, this.tabs.map((tab, index) => (h("button", { key: tab.label, role: "tab", id: this.getElementId(this.identifier, index), class: {
|
|
257
|
+
[`${this.buttonTabBaseClass}`]: true,
|
|
258
|
+
[`${this.buttonTabBaseClass}--horizontal`]: true,
|
|
259
|
+
[`${this.getNavigationButtonClass(Status.ACTIVE)}`]: this.tabHasStatus(tab, Status.ACTIVE),
|
|
260
|
+
[`${this.getNavigationButtonClass(Status.DISABLED)}`]: this.tabHasStatus(tab, Status.DISABLED),
|
|
261
|
+
[`${this.getNavigationButtonClass(Status.HIDDEN)}`]: this.tabHasStatus(tab, Status.HIDDEN),
|
|
262
|
+
}, tabindex: this.tabHasStatus(tab, Status.ACTIVE) ? 0 : -1, "aria-selected": this.tabHasStatus(tab, Status.ACTIVE).toString(), "aria-controls": this.getElementId(this.tabPanel, index), "aria-disabled": this.tabHasStatus(tab, Status.DISABLED), onClick: this.handleClick, onKeyDown: this.handleKeydown, "data-index": this.getTabItemIndex(index) }, tab.icon !== undefined && h("mg-icon", { icon: tab.icon }), tab.label, tab.badge !== undefined && h("mg-badge", { variant: "text-color", value: tab.badge.value, label: tab.badge.label, outline: tab.badge.role === 'information' }))))), this.tabs.map((tab, index) => (h("article", { key: tab.label, role: "tabpanel", id: this.getElementId(this.tabPanel, index), hidden: !this.tabHasStatus(tab, Status.ACTIVE), "aria-labelledby": this.getElementId(this.identifier, index), tabindex: this.tabHasStatus(tab, Status.ACTIVE) ? 0 : -1, class: "mg-c-tabs__content-container" }, h("slot", { name: this.getElementId('tab_content', index) }))))));
|
|
263
|
+
}
|
|
264
|
+
get element() { return this; }
|
|
265
|
+
static get watchers() { return {
|
|
266
|
+
"identifier": ["watchIdentifier"],
|
|
267
|
+
"label": ["validateLabel"],
|
|
268
|
+
"size": ["validateSize"],
|
|
269
|
+
"items": ["validateItems"],
|
|
270
|
+
"activeTab": ["validateActiveTab"]
|
|
271
|
+
}; }
|
|
272
|
+
static get style() { return mgTabsCss; }
|
|
273
|
+
}, [257, "mg-tabs", {
|
|
274
|
+
"identifier": [1],
|
|
275
|
+
"label": [1],
|
|
276
|
+
"size": [1],
|
|
277
|
+
"items": [16],
|
|
278
|
+
"activeTab": [1538, "active-tab"],
|
|
279
|
+
"tabs": [32],
|
|
280
|
+
"classCollection": [32]
|
|
281
|
+
}, undefined, {
|
|
282
|
+
"identifier": ["watchIdentifier"],
|
|
283
|
+
"label": ["validateLabel"],
|
|
284
|
+
"size": ["validateSize"],
|
|
285
|
+
"items": ["validateItems"],
|
|
286
|
+
"activeTab": ["validateActiveTab"]
|
|
287
|
+
}]);
|
|
288
|
+
function defineCustomElement() {
|
|
289
|
+
if (typeof customElements === "undefined") {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
const components = ["mg-tabs", "mg-badge", "mg-icon"];
|
|
293
|
+
components.forEach(tagName => { switch (tagName) {
|
|
294
|
+
case "mg-tabs":
|
|
295
|
+
if (!customElements.get(tagName)) {
|
|
296
|
+
customElements.define(tagName, MgTabs);
|
|
297
|
+
}
|
|
298
|
+
break;
|
|
299
|
+
case "mg-badge":
|
|
300
|
+
if (!customElements.get(tagName)) {
|
|
301
|
+
defineCustomElement$2();
|
|
302
|
+
}
|
|
303
|
+
break;
|
|
304
|
+
case "mg-icon":
|
|
305
|
+
if (!customElements.get(tagName)) {
|
|
306
|
+
defineCustomElement$1();
|
|
307
|
+
}
|
|
308
|
+
break;
|
|
309
|
+
} });
|
|
310
|
+
}
|
|
311
|
+
defineCustomElement();
|
|
312
|
+
|
|
313
|
+
export { MgTabs as M, Status as S, defineCustomElement as d };
|
|
@@ -100,7 +100,7 @@ const MgTag$1 = /*@__PURE__*/ proxyCustomElement(class MgTag extends HTMLElement
|
|
|
100
100
|
"soft": ["validateSoft"]
|
|
101
101
|
}; }
|
|
102
102
|
static get style() { return mgTagCss; }
|
|
103
|
-
}, [
|
|
103
|
+
}, [257, "mg-tag", {
|
|
104
104
|
"variant": [1],
|
|
105
105
|
"outline": [4],
|
|
106
106
|
"soft": [4],
|
|
@@ -19,7 +19,7 @@ const MgTooltipContent = /*@__PURE__*/ proxyCustomElement(class MgTooltipContent
|
|
|
19
19
|
return (h(Host, { key: '2221de3ca0ef7c9d6e46e24b19c69007fababf81', role: "tooltip" }, h("span", { key: '9e14f7f5b3f5e5060ed9f42e8d7259b17575168e', innerHTML: this.message, class: "mg-tooltip-content__message" }), h("slot", { key: 'bc083567d77e8f4ffccee98b96036ba8ac494fb6', name: "arrow" })));
|
|
20
20
|
}
|
|
21
21
|
static get style() { return mgTooltipContentCss; }
|
|
22
|
-
}, [
|
|
22
|
+
}, [257, "mg-tooltip-content", {
|
|
23
23
|
"message": [1]
|
|
24
24
|
}]);
|
|
25
25
|
function defineCustomElement() {
|