tyrell-components 1.0.0-RC14 → 1.0.0-RC15
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/README.md +9 -1
- package/css/tyrell-theme.css +25 -2
- package/css/tyrell.css +4 -0
- package/dist/tyrell-colors-static.css +1 -316
- package/dist/tyrell-theme.css +1 -1443
- package/dist/tyrell.css +1 -1390
- package/dist/tyrell.js +1 -1
- package/lib/base/ty-component.js +196 -196
- package/lib/components/button.d.ts +1 -1
- package/lib/components/button.js +261 -259
- package/lib/components/calendar-month.d.ts +2 -2
- package/lib/components/calendar-month.js +439 -416
- package/lib/components/calendar-navigation.js +238 -238
- package/lib/components/calendar.d.ts +5 -3
- package/lib/components/calendar.js +611 -602
- package/lib/components/checkbox.d.ts +1 -1
- package/lib/components/checkbox.js +273 -272
- package/lib/components/copy.d.ts +1 -1
- package/lib/components/copy.js +280 -278
- package/lib/components/date-picker.d.ts +8 -1
- package/lib/components/date-picker.js +1128 -1108
- package/lib/components/file-upload.js +404 -404
- package/lib/components/icon.js +141 -141
- package/lib/components/input.d.ts +1 -1
- package/lib/components/input.js +593 -596
- package/lib/components/modal.js +319 -319
- package/lib/components/option.js +167 -167
- package/lib/components/popup.js +233 -233
- package/lib/components/radio.d.ts +2 -2
- package/lib/components/radio.js +407 -406
- package/lib/components/resize-observer.js +67 -67
- package/lib/components/scroll-container.js +292 -294
- package/lib/components/select.d.ts +71 -12
- package/lib/components/select.js +1605 -1529
- package/lib/components/selected-tags.d.ts +1 -1
- package/lib/components/selected-tags.js +188 -182
- package/lib/components/step.js +62 -62
- package/lib/components/switch.d.ts +1 -1
- package/lib/components/switch.js +214 -213
- package/lib/components/tab.js +62 -62
- package/lib/components/tabs.d.ts +1 -0
- package/lib/components/tabs.js +523 -492
- package/lib/components/tag.d.ts +1 -1
- package/lib/components/tag.js +236 -235
- package/lib/components/textarea.d.ts +1 -1
- package/lib/components/textarea.js +457 -456
- package/lib/components/tooltip.js +283 -283
- package/lib/components/wizard.js +384 -384
- package/lib/icons/heroicons/micro.js +392 -392
- package/lib/icons/heroicons/mini.js +382 -382
- package/lib/icons/heroicons/outline.js +337 -337
- package/lib/icons/heroicons/solid.js +407 -407
- package/lib/icons/lucide.js +22843 -22843
- package/lib/icons/material/filled.js +9653 -9653
- package/lib/icons/material/outlined.js +10271 -10271
- package/lib/icons/material/round.js +10495 -10495
- package/lib/icons/material/sharp.js +9905 -9905
- package/lib/icons/material/two-tone.js +12792 -12792
- package/lib/index.js +21 -21
- package/lib/styles/button.js +200 -302
- package/lib/styles/calendar-month.js +123 -183
- package/lib/styles/calendar-navigation.d.ts +1 -1
- package/lib/styles/calendar-navigation.js +64 -79
- package/lib/styles/calendar.d.ts +1 -1
- package/lib/styles/calendar.js +9 -9
- package/lib/styles/checkbox.js +45 -72
- package/lib/styles/copy.js +67 -91
- package/lib/styles/custom-scrollbar.js +80 -100
- package/lib/styles/date-picker.js +261 -331
- package/lib/styles/field-size.d.ts +6 -0
- package/lib/styles/field-size.js +91 -0
- package/lib/styles/file-upload.js +139 -169
- package/lib/styles/icon.js +92 -156
- package/lib/styles/input.js +125 -241
- package/lib/styles/modal.js +67 -102
- package/lib/styles/option.d.ts +1 -1
- package/lib/styles/option.js +47 -67
- package/lib/styles/popup.js +34 -65
- package/lib/styles/radio.js +69 -96
- package/lib/styles/resize-observer.js +2 -5
- package/lib/styles/scroll-container.js +100 -130
- package/lib/styles/select-base.js +596 -773
- package/lib/styles/select.js +140 -228
- package/lib/styles/step.js +22 -29
- package/lib/styles/switch.js +34 -55
- package/lib/styles/tab.d.ts +1 -1
- package/lib/styles/tab.js +22 -29
- package/lib/styles/tabs.d.ts +1 -1
- package/lib/styles/tabs.js +186 -180
- package/lib/styles/tag.js +135 -188
- package/lib/styles/textarea.d.ts +1 -1
- package/lib/styles/textarea.js +205 -271
- package/lib/styles/tooltip.js +3 -3
- package/lib/styles/wizard.js +170 -226
- package/lib/types/common.d.ts +2 -0
- package/lib/types/common.js +6 -5
- package/lib/utils/calendar-utils.js +100 -100
- package/lib/utils/custom-scrollbar.js +272 -272
- package/lib/utils/flavor-sheet.js +14 -14
- package/lib/utils/icon-registry.js +127 -127
- package/lib/utils/loader-registry.js +3 -3
- package/lib/utils/locale.js +34 -34
- package/lib/utils/mobile.js +1 -1
- package/lib/utils/number-format.js +54 -54
- package/lib/utils/positioning.js +212 -212
- package/lib/utils/property-capture.js +36 -36
- package/lib/utils/property-manager.js +125 -125
- package/lib/utils/resize-observer.js +23 -23
- package/lib/utils/scroll-lock.js +57 -57
- package/lib/utils/styles.js +17 -17
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +4 -4
package/lib/components/tabs.js
CHANGED
|
@@ -2,554 +2,585 @@ import { ensureStyles } from '../utils/styles.js';
|
|
|
2
2
|
import { tabsStyles } from '../styles/tabs.js';
|
|
3
3
|
const eventHandlers = new WeakMap();
|
|
4
4
|
const resizeObservers = new WeakMap();
|
|
5
|
+
const pendingInitialSnap = new WeakSet();
|
|
5
6
|
function getTabsAttributes(el) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
return {
|
|
8
|
+
width: el.getAttribute('width') || '100%',
|
|
9
|
+
height: el.getAttribute('height') || '400px',
|
|
10
|
+
active: el.getAttribute('active'),
|
|
11
|
+
placement: (el.getAttribute('placement') || 'top'),
|
|
12
|
+
fixed: el.hasAttribute('fixed'),
|
|
13
|
+
};
|
|
12
14
|
}
|
|
13
15
|
function getChildTabs(el) {
|
|
14
|
-
|
|
16
|
+
return Array.from(el.querySelectorAll('ty-tab'));
|
|
15
17
|
}
|
|
16
18
|
function getTabId(tab) {
|
|
17
|
-
|
|
19
|
+
return tab.getAttribute('id');
|
|
20
|
+
}
|
|
21
|
+
function getSlotLabel(tabsEl, tabId) {
|
|
22
|
+
return tabsEl.querySelector(`:scope > [slot='label-${tabId}']`);
|
|
18
23
|
}
|
|
19
24
|
function hasSlotLabel(tabsEl, tabId) {
|
|
20
|
-
|
|
25
|
+
return getSlotLabel(tabsEl, tabId) !== null;
|
|
21
26
|
}
|
|
22
27
|
function getTabLabelType(tabsEl, tab) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
const tabId = getTabId(tab);
|
|
29
|
+
if (tabId && hasSlotLabel(tabsEl, tabId)) {
|
|
30
|
+
return 'slot';
|
|
31
|
+
}
|
|
32
|
+
return 'text';
|
|
28
33
|
}
|
|
29
34
|
function isTabDisabled(tab) {
|
|
30
|
-
|
|
35
|
+
return tab.hasAttribute('disabled');
|
|
31
36
|
}
|
|
32
37
|
function hasCustomMarker(el) {
|
|
33
|
-
|
|
38
|
+
return el.querySelector('[slot="marker"]') !== null;
|
|
34
39
|
}
|
|
35
40
|
function findTabIndex(tabs, tabId) {
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
const index = tabs.findIndex(tab => getTabId(tab) === tabId);
|
|
42
|
+
return index >= 0 ? index : undefined;
|
|
43
|
+
}
|
|
44
|
+
function currentActive(el) {
|
|
45
|
+
const tabs = getChildTabs(el);
|
|
46
|
+
const id = getActiveTabId(el, tabs);
|
|
47
|
+
return { id, index: (id ? findTabIndex(tabs, id) : undefined) ?? 0 };
|
|
38
48
|
}
|
|
39
49
|
function getActiveTabId(el, tabs) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
const activeAttr = el.getAttribute('active');
|
|
51
|
+
if (activeAttr && findTabIndex(tabs, activeAttr) !== undefined) {
|
|
52
|
+
return activeAttr;
|
|
53
|
+
}
|
|
54
|
+
if (tabs.length > 0) {
|
|
55
|
+
return getTabId(tabs[0]);
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
48
58
|
}
|
|
49
59
|
function setActiveTab(el, tabId) {
|
|
50
|
-
|
|
60
|
+
el.setAttribute('active', tabId);
|
|
51
61
|
}
|
|
52
62
|
function dispatchTabChangeEvent(el, activeId, activeIndex, previousId, previousIndex) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
const event = new CustomEvent('ty-tab-change', {
|
|
64
|
+
detail: {
|
|
65
|
+
activeId,
|
|
66
|
+
activeIndex,
|
|
67
|
+
previousId,
|
|
68
|
+
previousIndex,
|
|
69
|
+
},
|
|
70
|
+
bubbles: true,
|
|
71
|
+
cancelable: false,
|
|
72
|
+
});
|
|
73
|
+
el.dispatchEvent(event);
|
|
64
74
|
}
|
|
65
75
|
function handleTabClick(el, tabId, event) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
event.stopPropagation();
|
|
78
|
+
setActiveTab(el, tabId);
|
|
69
79
|
}
|
|
70
80
|
function cleanupEventListeners(el) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
81
|
+
const handlers = eventHandlers.get(el);
|
|
82
|
+
if (!handlers)
|
|
83
|
+
return;
|
|
84
|
+
const shadowRoot = el.shadowRoot;
|
|
85
|
+
if (!shadowRoot)
|
|
86
|
+
return;
|
|
87
|
+
handlers.tabClickHandlers.forEach((handler, tabId) => {
|
|
88
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
|
|
89
|
+
if (button) {
|
|
90
|
+
button.removeEventListener('pointerdown', handler);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
handlers.tabKeyClickHandlers.forEach((handler, tabId) => {
|
|
94
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
|
|
95
|
+
if (button) {
|
|
96
|
+
button.removeEventListener('click', handler);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
handlers.tabClickHandlers.clear();
|
|
100
|
+
handlers.tabKeyClickHandlers.clear();
|
|
91
101
|
}
|
|
92
102
|
function setupEventListeners(el, shadowRoot, tabs) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
103
|
+
cleanupEventListeners(el);
|
|
104
|
+
const handlers = {
|
|
105
|
+
tabClickHandlers: new Map(),
|
|
106
|
+
tabKeyClickHandlers: new Map(),
|
|
107
|
+
};
|
|
108
|
+
tabs.forEach((tab) => {
|
|
109
|
+
const tabId = getTabId(tab);
|
|
110
|
+
if (!tabId)
|
|
111
|
+
return;
|
|
112
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
|
|
113
|
+
if (button) {
|
|
114
|
+
const handler = (e) => handleTabClick(el, tabId, e);
|
|
115
|
+
const keyClickHandler = (e) => {
|
|
116
|
+
if (e.detail === 0)
|
|
117
|
+
handleTabClick(el, tabId, e);
|
|
118
|
+
};
|
|
119
|
+
button.addEventListener('pointerdown', handler);
|
|
120
|
+
button.addEventListener('click', keyClickHandler);
|
|
121
|
+
handlers.tabClickHandlers.set(tabId, handler);
|
|
122
|
+
handlers.tabKeyClickHandlers.set(tabId, keyClickHandler);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
eventHandlers.set(el, handlers);
|
|
116
126
|
}
|
|
117
127
|
function updateTransform(el, activeIndex) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
const shadowRoot = el.shadowRoot;
|
|
129
|
+
if (!shadowRoot)
|
|
130
|
+
return;
|
|
131
|
+
const panelsWrapper = shadowRoot.querySelector('.panels-wrapper');
|
|
132
|
+
if (!panelsWrapper)
|
|
133
|
+
return;
|
|
134
|
+
const containerWidth = el.offsetWidth;
|
|
135
|
+
const offsetPx = activeIndex * containerWidth;
|
|
136
|
+
panelsWrapper.style.transform = `translateX(-${offsetPx}px)`;
|
|
127
137
|
}
|
|
128
138
|
function updateAriaAttributes(el, shadowRoot, activeId) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
139
|
+
const tabs = getChildTabs(el);
|
|
140
|
+
tabs.forEach((tab, idx) => {
|
|
141
|
+
const tabId = getTabId(tab);
|
|
142
|
+
if (!tabId)
|
|
143
|
+
return;
|
|
144
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
|
|
145
|
+
const isActive = tabId === activeId;
|
|
146
|
+
if (button) {
|
|
147
|
+
button.setAttribute('aria-selected', String(isActive));
|
|
148
|
+
button.setAttribute('tabindex', isActive ? '0' : '-1');
|
|
149
|
+
button.setAttribute('data-active', String(isActive));
|
|
150
|
+
const slottedLabel = getSlotLabel(el, tabId);
|
|
151
|
+
if (slottedLabel) {
|
|
152
|
+
slottedLabel.setAttribute('data-active', String(isActive));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
146
156
|
}
|
|
147
157
|
function updatePanelInteraction(el, activeId) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
158
|
+
const tabs = getChildTabs(el);
|
|
159
|
+
tabs.forEach((tab) => {
|
|
160
|
+
const tabId = getTabId(tab);
|
|
161
|
+
if (!tabId)
|
|
162
|
+
return;
|
|
163
|
+
const isActive = tabId === activeId;
|
|
164
|
+
tab.setAttribute('data-active', String(isActive));
|
|
165
|
+
if (isActive) {
|
|
166
|
+
tab.style.pointerEvents = 'auto';
|
|
167
|
+
tab.style.opacity = '1';
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
tab.style.pointerEvents = 'none';
|
|
171
|
+
tab.style.opacity = '0';
|
|
172
|
+
}
|
|
173
|
+
});
|
|
164
174
|
}
|
|
165
175
|
function calculateMarkerPosition(el, shadowRoot, activeId) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (snap) {
|
|
198
|
-
marker.offsetWidth;
|
|
199
|
-
marker.style.transition = '';
|
|
200
|
-
}
|
|
176
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
|
|
177
|
+
const buttonsContainer = shadowRoot.querySelector('.tab-buttons');
|
|
178
|
+
if (!button || !buttonsContainer)
|
|
179
|
+
return null;
|
|
180
|
+
const left = button.offsetLeft;
|
|
181
|
+
const top = button.offsetTop;
|
|
182
|
+
const width = button.offsetWidth;
|
|
183
|
+
const height = button.offsetHeight;
|
|
184
|
+
return { left, top, width, height };
|
|
185
|
+
}
|
|
186
|
+
function updateMarker(el, activeId, forceSnap = false) {
|
|
187
|
+
const shadowRoot = el.shadowRoot;
|
|
188
|
+
if (!shadowRoot)
|
|
189
|
+
return;
|
|
190
|
+
const marker = shadowRoot.querySelector('.marker-wrapper');
|
|
191
|
+
if (!marker)
|
|
192
|
+
return;
|
|
193
|
+
const position = calculateMarkerPosition(el, shadowRoot, activeId);
|
|
194
|
+
if (!position)
|
|
195
|
+
return;
|
|
196
|
+
const snap = forceSnap || !marker.style.left || marker.offsetWidth === 0;
|
|
197
|
+
if (snap)
|
|
198
|
+
marker.style.transition = 'none';
|
|
199
|
+
marker.style.left = `${position.left}px`;
|
|
200
|
+
marker.style.top = `${position.top}px`;
|
|
201
|
+
marker.style.width = `${position.width}px`;
|
|
202
|
+
marker.style.height = `${position.height}px`;
|
|
203
|
+
if (snap) {
|
|
204
|
+
marker.offsetWidth;
|
|
205
|
+
marker.style.transition = '';
|
|
206
|
+
}
|
|
201
207
|
}
|
|
202
208
|
function updateActiveTabState(el, tabId, previousId) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
209
|
+
const tabs = getChildTabs(el);
|
|
210
|
+
const shadowRoot = el.shadowRoot;
|
|
211
|
+
if (!shadowRoot)
|
|
212
|
+
return;
|
|
213
|
+
const currentIndex = previousId ? findTabIndex(tabs, previousId) : undefined;
|
|
214
|
+
const newIndex = findTabIndex(tabs, tabId);
|
|
215
|
+
if (previousId === tabId || newIndex === undefined)
|
|
216
|
+
return;
|
|
217
|
+
el.style.setProperty('--active-index', String(newIndex));
|
|
218
|
+
updateTransform(el, newIndex);
|
|
219
|
+
updateAriaAttributes(el, shadowRoot, tabId);
|
|
220
|
+
updatePanelInteraction(el, tabId);
|
|
221
|
+
updateMarker(el, tabId, pendingInitialSnap.delete(el));
|
|
222
|
+
shadowRoot.querySelectorAll('.tab-overflow-item').forEach((item) => {
|
|
223
|
+
item.setAttribute('data-active', String(item.dataset.tabId === tabId));
|
|
224
|
+
});
|
|
225
|
+
const newPanel = tabs[newIndex];
|
|
226
|
+
if (newPanel?.resetScroll) {
|
|
227
|
+
newPanel.resetScroll();
|
|
228
|
+
}
|
|
229
|
+
dispatchTabChangeEvent(el, tabId, newIndex, previousId, currentIndex ?? null);
|
|
221
230
|
}
|
|
222
231
|
function setupResizeObserver(el) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
232
|
+
const oldObserver = resizeObservers.get(el);
|
|
233
|
+
if (oldObserver) {
|
|
234
|
+
oldObserver.disconnect();
|
|
235
|
+
}
|
|
236
|
+
const observer = new ResizeObserver((entries) => {
|
|
237
|
+
const entry = entries[0];
|
|
238
|
+
const { width } = getTabsAttributes(el);
|
|
239
|
+
const tabs = getChildTabs(el);
|
|
240
|
+
const activeId = getActiveTabId(el, tabs);
|
|
241
|
+
const activeIndex = activeId ? findTabIndex(tabs, activeId) : 0;
|
|
242
|
+
if (width.includes('%')) {
|
|
243
|
+
el.style.setProperty('--tabs-page-width', `${entry.contentRect.width}px`);
|
|
244
|
+
}
|
|
245
|
+
if (activeIndex !== undefined) {
|
|
246
|
+
updateTransform(el, activeIndex);
|
|
247
|
+
}
|
|
248
|
+
updateOverflow(el);
|
|
249
|
+
if (activeId) {
|
|
250
|
+
updateMarker(el, activeId);
|
|
251
|
+
scrollActiveIntoView(el, activeId, false);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
observer.observe(el);
|
|
255
|
+
resizeObservers.set(el, observer);
|
|
246
256
|
}
|
|
247
257
|
function cleanupResizeObserver(el) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
258
|
+
const observer = resizeObservers.get(el);
|
|
259
|
+
if (observer) {
|
|
260
|
+
observer.disconnect();
|
|
261
|
+
resizeObservers.delete(el);
|
|
262
|
+
}
|
|
253
263
|
}
|
|
254
264
|
function renderTabButtons(tabsEl, tabs, activeId) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
265
|
+
const buttons = tabs.map((tab) => {
|
|
266
|
+
const tabId = getTabId(tab);
|
|
267
|
+
if (!tabId)
|
|
268
|
+
return '';
|
|
269
|
+
const labelType = getTabLabelType(tabsEl, tab);
|
|
270
|
+
const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
|
|
271
|
+
const disabled = isTabDisabled(tab);
|
|
272
|
+
const active = tabId === activeId;
|
|
273
|
+
return `<button
|
|
274
|
+
class="tab-button"
|
|
275
|
+
role="tab"
|
|
276
|
+
data-tab-id="${tabId}"
|
|
277
|
+
id="tab-${tabId}"
|
|
278
|
+
aria-selected="${active}"
|
|
279
|
+
tabindex="${active ? '0' : '-1'}"
|
|
280
|
+
data-active="${active}"
|
|
281
|
+
${disabled ? 'disabled aria-disabled="true"' : ''}
|
|
282
|
+
>
|
|
283
|
+
${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : `<span class="tab-label">${textLabel}</span>`}
|
|
284
|
+
</button>`;
|
|
285
|
+
}).join('');
|
|
286
|
+
return `
|
|
287
|
+
<div class="tab-buttons" role="tablist" part="buttons-container">
|
|
288
|
+
<div class="tab-strip" part="strip">
|
|
289
|
+
<div class="marker-wrapper" part="marker-wrapper">
|
|
290
|
+
${!hasCustomMarker(tabsEl) ? '<div class="default-marker"></div>' : ''}
|
|
291
|
+
<slot name="marker"></slot>
|
|
292
|
+
</div>
|
|
293
|
+
${buttons}
|
|
294
|
+
</div>
|
|
295
|
+
</div>
|
|
296
|
+
`;
|
|
285
297
|
}
|
|
286
298
|
function renderButtonsOnly(tabsEl, tabs, activeId) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
const OVERFLOW_TRIGGER_WIDTH = 40;
|
|
299
|
+
return tabs.map((tab) => {
|
|
300
|
+
const tabId = getTabId(tab);
|
|
301
|
+
if (!tabId)
|
|
302
|
+
return '';
|
|
303
|
+
const labelType = getTabLabelType(tabsEl, tab);
|
|
304
|
+
const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
|
|
305
|
+
const disabled = isTabDisabled(tab);
|
|
306
|
+
const active = tabId === activeId;
|
|
307
|
+
return `<button
|
|
308
|
+
class="tab-button"
|
|
309
|
+
role="tab"
|
|
310
|
+
data-tab-id="${tabId}"
|
|
311
|
+
id="tab-${tabId}"
|
|
312
|
+
aria-selected="${active}"
|
|
313
|
+
tabindex="${active ? '0' : '-1'}"
|
|
314
|
+
data-active="${active}"
|
|
315
|
+
${disabled ? 'disabled aria-disabled="true"' : ''}
|
|
316
|
+
>
|
|
317
|
+
${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : `<span class="tab-label">${textLabel}</span>`}
|
|
318
|
+
</button>`;
|
|
319
|
+
}).join('');
|
|
320
|
+
}
|
|
310
321
|
function getTabMenuLabel(tabsEl, tab) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
322
|
+
const tabId = getTabId(tab);
|
|
323
|
+
if (tabId && getTabLabelType(tabsEl, tab) === 'slot') {
|
|
324
|
+
const slotted = getSlotLabel(tabsEl, tabId);
|
|
325
|
+
return slotted?.textContent?.trim() || tabId;
|
|
326
|
+
}
|
|
327
|
+
return tab.getAttribute('label') || 'Tab';
|
|
317
328
|
}
|
|
318
329
|
function removeOverflowMenu(shadowRoot) {
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
function renderOverflowMenu(el, container,
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
container.appendChild(trigger);
|
|
330
|
+
shadowRoot.querySelector('.tab-overflow-trigger')?.remove();
|
|
331
|
+
}
|
|
332
|
+
function renderOverflowMenu(el, container, allTabs) {
|
|
333
|
+
const activeId = getActiveTabId(el, allTabs);
|
|
334
|
+
const trigger = document.createElement('button');
|
|
335
|
+
trigger.className = 'tab-overflow-trigger';
|
|
336
|
+
trigger.type = 'button';
|
|
337
|
+
trigger.setAttribute('aria-label', `${allTabs.length} tabs`);
|
|
338
|
+
trigger.textContent = '⋯';
|
|
339
|
+
const popup = document.createElement('ty-popup');
|
|
340
|
+
popup.setAttribute('placement', 'bottom');
|
|
341
|
+
const menu = document.createElement('div');
|
|
342
|
+
menu.className = 'tab-overflow-menu';
|
|
343
|
+
menu.setAttribute('role', 'menu');
|
|
344
|
+
allTabs.forEach((tab) => {
|
|
345
|
+
const tabId = getTabId(tab);
|
|
346
|
+
if (!tabId)
|
|
347
|
+
return;
|
|
348
|
+
const item = document.createElement('button');
|
|
349
|
+
item.type = 'button';
|
|
350
|
+
item.className = 'tab-overflow-item';
|
|
351
|
+
item.setAttribute('role', 'menuitem');
|
|
352
|
+
item.setAttribute('data-tab-id', tabId);
|
|
353
|
+
item.setAttribute('data-active', String(tabId === activeId));
|
|
354
|
+
item.textContent = getTabMenuLabel(el, tab);
|
|
355
|
+
if (isTabDisabled(tab)) {
|
|
356
|
+
item.disabled = true;
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
item.addEventListener('click', () => {
|
|
360
|
+
setActiveTab(el, tabId);
|
|
361
|
+
popup.closePopup?.();
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
menu.appendChild(item);
|
|
365
|
+
});
|
|
366
|
+
popup.appendChild(menu);
|
|
367
|
+
trigger.appendChild(popup);
|
|
368
|
+
container.appendChild(trigger);
|
|
359
369
|
}
|
|
360
370
|
function updateOverflow(el) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
371
|
+
const shadowRoot = el.shadowRoot;
|
|
372
|
+
if (!shadowRoot)
|
|
373
|
+
return;
|
|
374
|
+
const container = shadowRoot.querySelector('.tab-buttons');
|
|
375
|
+
const strip = shadowRoot.querySelector('.tab-strip');
|
|
376
|
+
if (!container || !strip)
|
|
377
|
+
return;
|
|
378
|
+
if (getTabsAttributes(el).fixed) {
|
|
379
|
+
removeOverflowMenu(shadowRoot);
|
|
380
|
+
strip.classList.add('unclipped');
|
|
381
|
+
strip.style.removeProperty('--fade-left');
|
|
382
|
+
strip.style.removeProperty('--fade-right');
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
const savedScrollLeft = strip.scrollLeft;
|
|
386
|
+
removeOverflowMenu(shadowRoot);
|
|
387
|
+
if (strip.clientWidth <= 0)
|
|
388
|
+
return;
|
|
389
|
+
const buttons = strip.querySelectorAll('.tab-button');
|
|
390
|
+
const last = buttons[buttons.length - 1];
|
|
391
|
+
const contentWidth = last ? last.offsetLeft + last.offsetWidth : 0;
|
|
392
|
+
const stripWidth = strip.clientWidth;
|
|
393
|
+
const hidden = contentWidth - stripWidth;
|
|
394
|
+
strip.classList.toggle('unclipped', hidden <= 1);
|
|
395
|
+
if (hidden <= 1) {
|
|
396
|
+
strip.scrollLeft = savedScrollLeft;
|
|
397
|
+
updateEdgeFades(strip);
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
renderOverflowMenu(el, container, getChildTabs(el));
|
|
401
|
+
const triggerCost = container.clientWidth - strip.clientWidth;
|
|
402
|
+
if (hidden <= triggerCost) {
|
|
403
|
+
removeOverflowMenu(shadowRoot);
|
|
404
|
+
}
|
|
405
|
+
strip.scrollLeft = savedScrollLeft;
|
|
406
|
+
updateEdgeFades(strip);
|
|
407
|
+
}
|
|
408
|
+
function updateEdgeFades(strip) {
|
|
409
|
+
const maxScroll = strip.scrollWidth - strip.clientWidth;
|
|
410
|
+
const fade = (distance) => `${distance > 1 ? Math.min(28, distance) : 0}px`;
|
|
411
|
+
strip.style.setProperty('--fade-left', fade(strip.scrollLeft));
|
|
412
|
+
strip.style.setProperty('--fade-right', fade(maxScroll - strip.scrollLeft));
|
|
413
|
+
}
|
|
414
|
+
function scrollActiveIntoView(el, activeId, smooth) {
|
|
415
|
+
const shadowRoot = el.shadowRoot;
|
|
416
|
+
if (!shadowRoot)
|
|
417
|
+
return;
|
|
418
|
+
const strip = shadowRoot.querySelector('.tab-strip');
|
|
419
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
|
|
420
|
+
if (!strip || !button || strip.clientWidth <= 0)
|
|
421
|
+
return;
|
|
422
|
+
const centered = button.offsetLeft + button.offsetWidth / 2 - strip.clientWidth / 2;
|
|
423
|
+
const target = Math.max(0, Math.min(centered, strip.scrollWidth - strip.clientWidth));
|
|
424
|
+
if (Math.round(target) !== Math.round(strip.scrollLeft)) {
|
|
425
|
+
const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
426
|
+
strip.scrollTo({ left: target, behavior: smooth && !reduce ? 'smooth' : 'auto' });
|
|
427
|
+
}
|
|
407
428
|
}
|
|
408
429
|
function render(el) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
430
|
+
const shadowRoot = el.shadowRoot;
|
|
431
|
+
if (!shadowRoot)
|
|
432
|
+
return;
|
|
433
|
+
const { width, height, placement, fixed } = getTabsAttributes(el);
|
|
434
|
+
const tabs = getChildTabs(el);
|
|
435
|
+
const activeId = getActiveTabId(el, tabs);
|
|
436
|
+
const activeIndex = activeId ? (findTabIndex(tabs, activeId) ?? 0) : 0;
|
|
437
|
+
tabs.forEach((tab) => {
|
|
438
|
+
const tabId = getTabId(tab);
|
|
439
|
+
if (!tabId)
|
|
440
|
+
return;
|
|
441
|
+
tab.setAttribute('role', 'tabpanel');
|
|
442
|
+
tab.setAttribute('aria-labelledby', `tab-${tabId}`);
|
|
443
|
+
tab.setAttribute('tabindex', '0');
|
|
444
|
+
});
|
|
445
|
+
const existingContainer = shadowRoot.querySelector('.tabs-container');
|
|
446
|
+
const existingButtons = shadowRoot.querySelector('.tab-buttons');
|
|
447
|
+
const existingStrip = shadowRoot.querySelector('.tab-strip');
|
|
448
|
+
const existingViewport = shadowRoot.querySelector('.panels-viewport');
|
|
449
|
+
ensureStyles(shadowRoot, { css: tabsStyles, id: 'ty-tabs' });
|
|
450
|
+
el.style.setProperty('--tabs-width', width.includes('%') ? '100%' : width);
|
|
451
|
+
el.style.setProperty('--tabs-height', height);
|
|
452
|
+
el.style.setProperty('--active-index', String(activeIndex));
|
|
453
|
+
if (existingContainer && existingButtons && existingStrip && existingViewport) {
|
|
454
|
+
existingContainer.setAttribute('data-placement', placement);
|
|
455
|
+
existingContainer.toggleAttribute('data-fixed', fixed);
|
|
456
|
+
const savedScrollLeft = existingStrip.scrollLeft;
|
|
457
|
+
existingButtons.querySelector('.tab-overflow-trigger')?.remove();
|
|
458
|
+
const allButtons = existingStrip.querySelectorAll('.tab-button');
|
|
459
|
+
allButtons.forEach(button => button.remove());
|
|
460
|
+
const buttonsHtml = renderButtonsOnly(el, tabs, activeId);
|
|
461
|
+
const tempDiv = document.createElement('div');
|
|
462
|
+
tempDiv.innerHTML = buttonsHtml;
|
|
463
|
+
Array.from(tempDiv.children).forEach(button => {
|
|
464
|
+
existingStrip.appendChild(button);
|
|
465
|
+
});
|
|
466
|
+
existingStrip.scrollLeft = savedScrollLeft;
|
|
467
|
+
setupEventListeners(el, shadowRoot, tabs);
|
|
468
|
+
updateAriaAttributes(el, shadowRoot, activeId || '');
|
|
469
|
+
requestAnimationFrame(() => {
|
|
470
|
+
const buttons = shadowRoot.querySelector('.tab-buttons');
|
|
471
|
+
if (buttons) {
|
|
472
|
+
const buttonsHeight = buttons.offsetHeight;
|
|
473
|
+
el.style.setProperty('--buttons-height', `${buttonsHeight}px`);
|
|
474
|
+
}
|
|
475
|
+
const current = currentActive(el);
|
|
476
|
+
updateTransform(el, current.index);
|
|
477
|
+
updateOverflow(el);
|
|
478
|
+
if (current.id) {
|
|
479
|
+
updateMarker(el, current.id);
|
|
480
|
+
scrollActiveIntoView(el, current.id, true);
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
if (activeId) {
|
|
484
|
+
updatePanelInteraction(el, activeId);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
pendingInitialSnap.add(el);
|
|
489
|
+
shadowRoot.innerHTML = `
|
|
490
|
+
<div class="tabs-container" data-placement="${placement}"${fixed ? ' data-fixed' : ''}>
|
|
491
|
+
${renderTabButtons(el, tabs, activeId)}
|
|
492
|
+
<div class="panels-viewport" part="panels-container">
|
|
493
|
+
<div class="panels-wrapper">
|
|
494
|
+
<slot></slot>
|
|
495
|
+
</div>
|
|
496
|
+
</div>
|
|
497
|
+
</div>
|
|
498
|
+
`;
|
|
499
|
+
requestAnimationFrame(() => {
|
|
500
|
+
const buttons = shadowRoot.querySelector('.tab-buttons');
|
|
501
|
+
if (buttons) {
|
|
502
|
+
const buttonsHeight = buttons.offsetHeight;
|
|
503
|
+
el.style.setProperty('--buttons-height', `${buttonsHeight}px`);
|
|
504
|
+
}
|
|
505
|
+
const current = currentActive(el);
|
|
506
|
+
updateTransform(el, current.index);
|
|
507
|
+
updateOverflow(el);
|
|
508
|
+
if (current.id) {
|
|
509
|
+
updateMarker(el, current.id);
|
|
510
|
+
scrollActiveIntoView(el, current.id, false);
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
setupEventListeners(el, shadowRoot, tabs);
|
|
514
|
+
updateAriaAttributes(el, shadowRoot, activeId || '');
|
|
515
|
+
setupResizeObserver(el);
|
|
516
|
+
const strip = shadowRoot.querySelector('.tab-strip');
|
|
517
|
+
strip?.addEventListener('scroll', () => updateEdgeFades(strip), { passive: true });
|
|
518
|
+
if (activeId) {
|
|
519
|
+
updatePanelInteraction(el, activeId);
|
|
520
|
+
}
|
|
521
|
+
const markerSlot = shadowRoot.querySelector('slot[name="marker"]');
|
|
522
|
+
if (markerSlot) {
|
|
523
|
+
const updateDefaultMarkerVisibility = () => {
|
|
524
|
+
const defaultMarker = shadowRoot.querySelector('.default-marker');
|
|
525
|
+
if (defaultMarker) {
|
|
526
|
+
const hasCustom = markerSlot.assignedElements().length > 0;
|
|
527
|
+
defaultMarker.style.display = hasCustom ? 'none' : '';
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
markerSlot.addEventListener('slotchange', updateDefaultMarkerVisibility);
|
|
531
|
+
updateDefaultMarkerVisibility();
|
|
532
|
+
}
|
|
533
|
+
}
|
|
507
534
|
}
|
|
508
535
|
function cleanup(el) {
|
|
509
|
-
|
|
510
|
-
|
|
536
|
+
cleanupEventListeners(el);
|
|
537
|
+
cleanupResizeObserver(el);
|
|
511
538
|
}
|
|
512
539
|
export class TyTabs extends HTMLElement {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
540
|
+
static get observedAttributes() {
|
|
541
|
+
return ['width', 'height', 'active', 'placement', 'fixed'];
|
|
542
|
+
}
|
|
543
|
+
constructor() {
|
|
544
|
+
super();
|
|
545
|
+
this._childObserver = null;
|
|
546
|
+
this._childRenderQueued = false;
|
|
547
|
+
this.attachShadow({ mode: 'open' });
|
|
548
|
+
}
|
|
549
|
+
connectedCallback() {
|
|
550
|
+
render(this);
|
|
551
|
+
this._childObserver = new MutationObserver(() => {
|
|
552
|
+
if (this._childRenderQueued)
|
|
553
|
+
return;
|
|
554
|
+
this._childRenderQueued = true;
|
|
555
|
+
queueMicrotask(() => {
|
|
556
|
+
this._childRenderQueued = false;
|
|
557
|
+
if (this.isConnected)
|
|
558
|
+
render(this);
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
this._childObserver.observe(this, { childList: true });
|
|
562
|
+
}
|
|
563
|
+
disconnectedCallback() {
|
|
564
|
+
this._childObserver?.disconnect();
|
|
565
|
+
this._childObserver = null;
|
|
566
|
+
cleanup(this);
|
|
567
|
+
}
|
|
568
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
569
|
+
if (name === 'active') {
|
|
570
|
+
if (!newValue)
|
|
571
|
+
return;
|
|
572
|
+
if (!this.shadowRoot?.querySelector(`[data-tab-id='${newValue}']`)) {
|
|
573
|
+
render(this);
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
updateActiveTabState(this, newValue, oldValue);
|
|
577
|
+
scrollActiveIntoView(this, newValue, true);
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
render(this);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
552
583
|
}
|
|
553
584
|
if (!customElements.get('ty-tabs')) {
|
|
554
|
-
|
|
585
|
+
customElements.define('ty-tabs', TyTabs);
|
|
555
586
|
}
|