tyrell-components 1.0.0-RC15 → 1.0.0-RC17
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 +44 -52
- package/css/tyrell-colors-static.css +14 -0
- package/css/tyrell-theme.css +13 -7
- package/css/tyrell.css +15 -22
- package/dist/tyrell-colors-static.css +1 -1
- package/dist/tyrell-theme.css +1 -1
- package/dist/tyrell.css +1 -1
- package/dist/tyrell.js +1 -1
- package/lib/base/ty-component.d.ts +37 -15
- package/lib/base/ty-component.js +90 -26
- package/lib/components/button.d.ts +14 -0
- package/lib/components/button.js +61 -7
- package/lib/components/calendar-month.d.ts +7 -1
- package/lib/components/calendar-month.js +38 -30
- package/lib/components/calendar-navigation.d.ts +11 -0
- package/lib/components/calendar-navigation.js +68 -44
- package/lib/components/calendar.d.ts +52 -3
- package/lib/components/calendar.js +274 -61
- package/lib/components/checkbox.d.ts +8 -1
- package/lib/components/checkbox.js +29 -8
- package/lib/components/copy.d.ts +2 -0
- package/lib/components/copy.js +24 -33
- package/lib/components/date-picker.d.ts +68 -34
- package/lib/components/date-picker.js +386 -389
- package/lib/components/file-upload.d.ts +7 -0
- package/lib/components/file-upload.js +36 -4
- package/lib/components/input.d.ts +73 -3
- package/lib/components/input.js +159 -24
- package/lib/components/modal.d.ts +4 -8
- package/lib/components/modal.js +103 -33
- package/lib/components/option.js +7 -5
- package/lib/components/popup.js +117 -14
- package/lib/components/radio.d.ts +24 -0
- package/lib/components/radio.js +55 -32
- package/lib/components/resize-observer.js +2 -0
- package/lib/components/scroll-container.d.ts +3 -2
- package/lib/components/scroll-container.js +7 -8
- package/lib/components/select.d.ts +68 -11
- package/lib/components/select.js +196 -44
- package/lib/components/selected-tags.d.ts +7 -1
- package/lib/components/selected-tags.js +10 -1
- package/lib/components/switch.d.ts +9 -1
- package/lib/components/switch.js +29 -8
- package/lib/components/tab.d.ts +49 -1
- package/lib/components/tab.js +151 -10
- package/lib/components/tabs.d.ts +14 -2
- package/lib/components/tabs.js +185 -136
- package/lib/components/tag.d.ts +4 -7
- package/lib/components/tag.js +6 -7
- package/lib/components/textarea.d.ts +51 -5
- package/lib/components/textarea.js +95 -30
- package/lib/components/tooltip.d.ts +4 -3
- package/lib/components/tooltip.js +34 -24
- package/lib/components/wizard.d.ts +5 -4
- package/lib/components/wizard.js +120 -156
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -0
- package/lib/styles/button.js +21 -19
- package/lib/styles/calendar-month.d.ts +3 -0
- package/lib/styles/calendar-month.js +43 -27
- package/lib/styles/calendar-navigation.d.ts +1 -1
- package/lib/styles/calendar-navigation.js +55 -26
- package/lib/styles/calendar.d.ts +3 -2
- package/lib/styles/calendar.js +77 -0
- package/lib/styles/checkbox.js +31 -13
- package/lib/styles/copy.js +5 -1
- package/lib/styles/date-picker.js +68 -26
- package/lib/styles/file-upload.d.ts +1 -1
- package/lib/styles/file-upload.js +3 -3
- package/lib/styles/icon.d.ts +1 -1
- package/lib/styles/icon.js +2 -2
- package/lib/styles/input.js +6 -10
- package/lib/styles/option.d.ts +1 -1
- package/lib/styles/option.js +7 -3
- package/lib/styles/popup.d.ts +1 -1
- package/lib/styles/popup.js +10 -5
- package/lib/styles/radio.js +18 -6
- package/lib/styles/scroll-container.d.ts +1 -1
- package/lib/styles/scroll-container.js +1 -1
- package/lib/styles/select-base.js +24 -3
- package/lib/styles/select.d.ts +1 -1
- package/lib/styles/select.js +10 -0
- package/lib/styles/step.d.ts +1 -1
- package/lib/styles/step.js +1 -9
- package/lib/styles/switch.js +14 -6
- package/lib/styles/tab.d.ts +1 -1
- package/lib/styles/tab.js +67 -3
- package/lib/styles/tabs.d.ts +1 -1
- package/lib/styles/tabs.js +7 -3
- package/lib/styles/tag.js +3 -3
- package/lib/styles/textarea.d.ts +1 -1
- package/lib/styles/textarea.js +7 -0
- package/lib/styles/wizard.d.ts +9 -5
- package/lib/styles/wizard.js +211 -99
- package/lib/types/common.d.ts +2 -2
- package/lib/utils/calendar-utils.d.ts +49 -0
- package/lib/utils/calendar-utils.js +63 -6
- package/lib/utils/property-manager.d.ts +7 -1
- package/lib/utils/property-manager.js +16 -4
- package/lib/utils/scroll-lock.d.ts +10 -4
- package/lib/utils/scroll-lock.js +102 -2
- package/lib/utils/upgrade-properties.d.ts +21 -0
- package/lib/utils/upgrade-properties.js +47 -0
- package/lib/utils/validity.d.ts +122 -0
- package/lib/utils/validity.js +289 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +27 -5
package/lib/components/tabs.js
CHANGED
|
@@ -2,18 +2,23 @@ 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
|
|
5
|
+
const shownTabs = new WeakMap();
|
|
6
|
+
const instanceSheets = new WeakMap();
|
|
7
|
+
const pendingInitialSnap = new WeakMap();
|
|
8
|
+
let userInputs = 0;
|
|
9
|
+
const countInput = () => { userInputs++; };
|
|
10
|
+
addEventListener('pointerdown', countInput, { capture: true, passive: true });
|
|
11
|
+
addEventListener('keydown', countInput, { capture: true, passive: true });
|
|
12
|
+
const awaitedTabs = new WeakMap();
|
|
13
|
+
let snapCount = 0;
|
|
6
14
|
function getTabsAttributes(el) {
|
|
7
15
|
return {
|
|
8
|
-
width: el.getAttribute('width') || '100%',
|
|
9
|
-
height: el.getAttribute('height') || '400px',
|
|
10
|
-
active: el.getAttribute('active'),
|
|
11
16
|
placement: (el.getAttribute('placement') || 'top'),
|
|
12
17
|
fixed: el.hasAttribute('fixed'),
|
|
13
18
|
};
|
|
14
19
|
}
|
|
15
20
|
function getChildTabs(el) {
|
|
16
|
-
return Array.from(el.querySelectorAll('ty-tab'));
|
|
21
|
+
return Array.from(el.querySelectorAll(':scope > ty-tab'));
|
|
17
22
|
}
|
|
18
23
|
function getTabId(tab) {
|
|
19
24
|
return tab.getAttribute('id');
|
|
@@ -35,29 +40,28 @@ function isTabDisabled(tab) {
|
|
|
35
40
|
return tab.hasAttribute('disabled');
|
|
36
41
|
}
|
|
37
42
|
function hasCustomMarker(el) {
|
|
38
|
-
return el.querySelector('[slot="marker"]') !== null;
|
|
43
|
+
return el.querySelector(':scope > [slot="marker"]') !== null;
|
|
39
44
|
}
|
|
40
45
|
function findTabIndex(tabs, tabId) {
|
|
41
46
|
const index = tabs.findIndex(tab => getTabId(tab) === tabId);
|
|
42
47
|
return index >= 0 ? index : undefined;
|
|
43
48
|
}
|
|
44
49
|
function currentActive(el) {
|
|
45
|
-
|
|
46
|
-
const id = getActiveTabId(el, tabs);
|
|
47
|
-
return { id, index: (id ? findTabIndex(tabs, id) : undefined) ?? 0 };
|
|
50
|
+
return shownTabs.get(el) ?? null;
|
|
48
51
|
}
|
|
49
52
|
function getActiveTabId(el, tabs) {
|
|
53
|
+
const ids = tabs.map(getTabId).filter((id) => !!id);
|
|
50
54
|
const activeAttr = el.getAttribute('active');
|
|
51
|
-
if (activeAttr &&
|
|
55
|
+
if (activeAttr && ids.includes(activeAttr))
|
|
52
56
|
return activeAttr;
|
|
57
|
+
const shown = shownTabs.get(el);
|
|
58
|
+
if (shown && ids.includes(shown))
|
|
59
|
+
return shown;
|
|
60
|
+
return ids[0] ?? null;
|
|
53
61
|
}
|
|
54
|
-
|
|
55
|
-
return getTabId(tabs[0]);
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
function setActiveTab(el, tabId) {
|
|
62
|
+
function activateTab(el, tabId) {
|
|
60
63
|
el.setAttribute('active', tabId);
|
|
64
|
+
syncShownTab(el, true);
|
|
61
65
|
}
|
|
62
66
|
function dispatchTabChangeEvent(el, activeId, activeIndex, previousId, previousIndex) {
|
|
63
67
|
const event = new CustomEvent('ty-tab-change', {
|
|
@@ -75,7 +79,7 @@ el.dispatchEvent(event);
|
|
|
75
79
|
function handleTabClick(el, tabId, event) {
|
|
76
80
|
event.preventDefault();
|
|
77
81
|
event.stopPropagation();
|
|
78
|
-
|
|
82
|
+
activateTab(el, tabId);
|
|
79
83
|
}
|
|
80
84
|
function cleanupEventListeners(el) {
|
|
81
85
|
const handlers = eventHandlers.get(el);
|
|
@@ -87,23 +91,42 @@ return;
|
|
|
87
91
|
handlers.tabClickHandlers.forEach((handler, tabId) => {
|
|
88
92
|
const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
|
|
89
93
|
if (button) {
|
|
90
|
-
button.removeEventListener('
|
|
94
|
+
button.removeEventListener('click', handler);
|
|
91
95
|
}
|
|
92
96
|
});
|
|
93
|
-
handlers.
|
|
97
|
+
handlers.tabKeydownHandlers.forEach((handler, tabId) => {
|
|
94
98
|
const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
|
|
95
99
|
if (button) {
|
|
96
|
-
button.removeEventListener('
|
|
100
|
+
button.removeEventListener('keydown', handler);
|
|
97
101
|
}
|
|
98
102
|
});
|
|
99
103
|
handlers.tabClickHandlers.clear();
|
|
100
|
-
handlers.
|
|
104
|
+
handlers.tabKeydownHandlers.clear();
|
|
105
|
+
}
|
|
106
|
+
function handleTabKeydown(el, shadowRoot, tabId, e) {
|
|
107
|
+
if (!['ArrowRight', 'ArrowLeft', 'Home', 'End'].includes(e.key))
|
|
108
|
+
return;
|
|
109
|
+
const ids = Array.from(shadowRoot.querySelectorAll('.tab-buttons [data-tab-id]:not([disabled])')).map((b) => b.getAttribute('data-tab-id'));
|
|
110
|
+
const i = ids.indexOf(tabId);
|
|
111
|
+
if (i < 0 || ids.length === 0)
|
|
112
|
+
return;
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
const next = e.key === 'Home' ? ids[0]
|
|
115
|
+
: e.key === 'End' ? ids[ids.length - 1]
|
|
116
|
+
: e.key === 'ArrowRight' ? ids[(i + 1) % ids.length]
|
|
117
|
+
: ids[(i - 1 + ids.length) % ids.length];
|
|
118
|
+
if (next === tabId)
|
|
119
|
+
return;
|
|
120
|
+
handleTabClick(el, next, e);
|
|
121
|
+
requestAnimationFrame(() => {
|
|
122
|
+
shadowRoot.querySelector(`.tab-buttons [data-tab-id='${next}']`)?.focus();
|
|
123
|
+
});
|
|
101
124
|
}
|
|
102
125
|
function setupEventListeners(el, shadowRoot, tabs) {
|
|
103
126
|
cleanupEventListeners(el);
|
|
104
127
|
const handlers = {
|
|
105
128
|
tabClickHandlers: new Map(),
|
|
106
|
-
|
|
129
|
+
tabKeydownHandlers: new Map(),
|
|
107
130
|
};
|
|
108
131
|
tabs.forEach((tab) => {
|
|
109
132
|
const tabId = getTabId(tab);
|
|
@@ -112,28 +135,63 @@ return;
|
|
|
112
135
|
const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
|
|
113
136
|
if (button) {
|
|
114
137
|
const handler = (e) => handleTabClick(el, tabId, e);
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
};
|
|
119
|
-
button.addEventListener('pointerdown', handler);
|
|
120
|
-
button.addEventListener('click', keyClickHandler);
|
|
138
|
+
const keydownHandler = (e) => handleTabKeydown(el, shadowRoot, tabId, e);
|
|
139
|
+
button.addEventListener('click', handler);
|
|
140
|
+
button.addEventListener('keydown', keydownHandler);
|
|
121
141
|
handlers.tabClickHandlers.set(tabId, handler);
|
|
122
|
-
handlers.
|
|
142
|
+
handlers.tabKeydownHandlers.set(tabId, keydownHandler);
|
|
123
143
|
}
|
|
124
144
|
});
|
|
125
145
|
eventHandlers.set(el, handlers);
|
|
126
146
|
}
|
|
147
|
+
function carouselTransform(activeIndex) {
|
|
148
|
+
return `translateX(${activeIndex * -100}%)`;
|
|
149
|
+
}
|
|
150
|
+
function snapNextChange(container) {
|
|
151
|
+
if (!container)
|
|
152
|
+
return;
|
|
153
|
+
const token = String(++snapCount);
|
|
154
|
+
container.setAttribute('data-snap', token);
|
|
155
|
+
requestAnimationFrame(() => requestAnimationFrame(() => {
|
|
156
|
+
if (container.getAttribute('data-snap') === token)
|
|
157
|
+
container.removeAttribute('data-snap');
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
127
160
|
function updateTransform(el, activeIndex) {
|
|
161
|
+
const panelsWrapper = el.shadowRoot?.querySelector('.panels-wrapper');
|
|
162
|
+
if (panelsWrapper)
|
|
163
|
+
panelsWrapper.style.transform = carouselTransform(activeIndex);
|
|
164
|
+
}
|
|
165
|
+
function setAttr(node, name, value) {
|
|
166
|
+
if (node.getAttribute(name) !== value)
|
|
167
|
+
node.setAttribute(name, value);
|
|
168
|
+
}
|
|
169
|
+
function syncInstanceSheet(el, shownId) {
|
|
128
170
|
const shadowRoot = el.shadowRoot;
|
|
129
171
|
if (!shadowRoot)
|
|
130
172
|
return;
|
|
131
|
-
|
|
132
|
-
if (!
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
173
|
+
let sheet = instanceSheets.get(el);
|
|
174
|
+
if (!sheet) {
|
|
175
|
+
sheet = new CSSStyleSheet();
|
|
176
|
+
sheet.replaceSync(':host {} ::slotted(ty-tab) {}');
|
|
177
|
+
const hide = sheet.cssRules[1].style;
|
|
178
|
+
hide.setProperty('opacity', '0', 'important');
|
|
179
|
+
hide.setProperty('visibility', 'hidden', 'important');
|
|
180
|
+
hide.setProperty('pointer-events', 'none', 'important');
|
|
181
|
+
shadowRoot.adoptedStyleSheets = [...shadowRoot.adoptedStyleSheets, sheet];
|
|
182
|
+
instanceSheets.set(el, sheet);
|
|
183
|
+
}
|
|
184
|
+
const host = sheet.cssRules[0].style;
|
|
185
|
+
for (const prop of ['width', 'height']) {
|
|
186
|
+
const value = el.getAttribute(prop);
|
|
187
|
+
if (value)
|
|
188
|
+
host.setProperty(prop, value, 'important');
|
|
189
|
+
else
|
|
190
|
+
host.removeProperty(prop);
|
|
191
|
+
}
|
|
192
|
+
sheet.cssRules[1].selectorText = shownId
|
|
193
|
+
? `::slotted(ty-tab:not(#${CSS.escape(shownId)}))`
|
|
194
|
+
: '::slotted(ty-tab)';
|
|
137
195
|
}
|
|
138
196
|
function updateAriaAttributes(el, shadowRoot, activeId) {
|
|
139
197
|
const tabs = getChildTabs(el);
|
|
@@ -149,27 +207,19 @@ button.setAttribute('tabindex', isActive ? '0' : '-1');
|
|
|
149
207
|
button.setAttribute('data-active', String(isActive));
|
|
150
208
|
const slottedLabel = getSlotLabel(el, tabId);
|
|
151
209
|
if (slottedLabel) {
|
|
152
|
-
slottedLabel
|
|
210
|
+
setAttr(slottedLabel, 'data-active', String(isActive));
|
|
153
211
|
}
|
|
154
212
|
}
|
|
155
213
|
});
|
|
156
214
|
}
|
|
157
215
|
function updatePanelInteraction(el, activeId) {
|
|
158
|
-
|
|
159
|
-
|
|
216
|
+
syncInstanceSheet(el, activeId);
|
|
217
|
+
getChildTabs(el).forEach((tab) => {
|
|
160
218
|
const tabId = getTabId(tab);
|
|
219
|
+
tab.setShown?.(!!tabId && tabId === activeId);
|
|
161
220
|
if (!tabId)
|
|
162
221
|
return;
|
|
163
|
-
|
|
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
|
-
}
|
|
222
|
+
setAttr(tab, 'data-active', String(tabId === activeId));
|
|
173
223
|
});
|
|
174
224
|
}
|
|
175
225
|
function calculateMarkerPosition(el, shadowRoot, activeId) {
|
|
@@ -201,50 +251,65 @@ marker.style.top = `${position.top}px`;
|
|
|
201
251
|
marker.style.width = `${position.width}px`;
|
|
202
252
|
marker.style.height = `${position.height}px`;
|
|
203
253
|
if (snap) {
|
|
204
|
-
marker.
|
|
254
|
+
marker.getBoundingClientRect();
|
|
205
255
|
marker.style.transition = '';
|
|
206
256
|
}
|
|
207
257
|
}
|
|
208
|
-
function
|
|
209
|
-
const tabs = getChildTabs(el);
|
|
258
|
+
function syncShownTab(el, user = false) {
|
|
210
259
|
const shadowRoot = el.shadowRoot;
|
|
211
260
|
if (!shadowRoot)
|
|
212
261
|
return;
|
|
213
|
-
const
|
|
214
|
-
const
|
|
215
|
-
|
|
262
|
+
const tabs = getChildTabs(el);
|
|
263
|
+
const previousId = shownTabs.get(el) ?? null;
|
|
264
|
+
const tabId = getActiveTabId(el, tabs);
|
|
265
|
+
const newIndex = (tabId ? findTabIndex(tabs, tabId) : undefined) ?? 0;
|
|
266
|
+
const container = shadowRoot.querySelector('.tabs-container');
|
|
267
|
+
if (tabId === previousId) {
|
|
268
|
+
const wrapper = shadowRoot.querySelector('.panels-wrapper');
|
|
269
|
+
if (wrapper && wrapper.style.transform !== carouselTransform(newIndex)) {
|
|
270
|
+
snapNextChange(container);
|
|
271
|
+
wrapper.style.transform = carouselTransform(newIndex);
|
|
272
|
+
}
|
|
216
273
|
return;
|
|
217
|
-
|
|
274
|
+
}
|
|
275
|
+
shownTabs.set(el, tabId);
|
|
276
|
+
const initial = previousId === null;
|
|
277
|
+
const arrived = !user && tabId !== null && awaitedTabs.get(el) === tabId;
|
|
278
|
+
awaitedTabs.delete(el);
|
|
279
|
+
const requested = el.getAttribute('active');
|
|
280
|
+
if (initial && requested && requested !== tabId)
|
|
281
|
+
awaitedTabs.set(el, requested);
|
|
282
|
+
const snap = !user && (initial || arrived || pendingInitialSnap.get(el) === userInputs);
|
|
283
|
+
if (initial)
|
|
284
|
+
pendingInitialSnap.set(el, userInputs);
|
|
285
|
+
else if (!arrived)
|
|
286
|
+
pendingInitialSnap.delete(el);
|
|
287
|
+
if (snap)
|
|
288
|
+
snapNextChange(container);
|
|
218
289
|
updateTransform(el, newIndex);
|
|
219
|
-
updateAriaAttributes(el, shadowRoot, tabId);
|
|
290
|
+
updateAriaAttributes(el, shadowRoot, tabId || '');
|
|
220
291
|
updatePanelInteraction(el, tabId);
|
|
221
|
-
|
|
292
|
+
if (!tabId || initial)
|
|
293
|
+
return;
|
|
294
|
+
updateMarker(el, tabId, snap);
|
|
295
|
+
scrollActiveIntoView(el, tabId, !snap);
|
|
222
296
|
shadowRoot.querySelectorAll('.tab-overflow-item').forEach((item) => {
|
|
223
297
|
item.setAttribute('data-active', String(item.dataset.tabId === tabId));
|
|
224
298
|
});
|
|
225
|
-
|
|
226
|
-
if (
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
dispatchTabChangeEvent(el, tabId, newIndex, previousId,
|
|
299
|
+
tabs[newIndex]?.resetScroll?.();
|
|
300
|
+
if (arrived)
|
|
301
|
+
return;
|
|
302
|
+
const previousIndex = findTabIndex(tabs, previousId);
|
|
303
|
+
dispatchTabChangeEvent(el, tabId, newIndex, previousIndex === undefined ? null : previousId, previousIndex ?? null);
|
|
304
|
+
tabs[newIndex]?._requestLoad?.(newIndex);
|
|
230
305
|
}
|
|
231
306
|
function setupResizeObserver(el) {
|
|
232
307
|
const oldObserver = resizeObservers.get(el);
|
|
233
308
|
if (oldObserver) {
|
|
234
309
|
oldObserver.disconnect();
|
|
235
310
|
}
|
|
236
|
-
const observer = new ResizeObserver((
|
|
237
|
-
const
|
|
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
|
-
}
|
|
311
|
+
const observer = new ResizeObserver(() => {
|
|
312
|
+
const activeId = currentActive(el);
|
|
248
313
|
updateOverflow(el);
|
|
249
314
|
if (activeId) {
|
|
250
315
|
updateMarker(el, activeId);
|
|
@@ -284,8 +349,8 @@ ${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : `<span class="t
|
|
|
284
349
|
</button>`;
|
|
285
350
|
}).join('');
|
|
286
351
|
return `
|
|
287
|
-
<div class="tab-buttons"
|
|
288
|
-
<div class="tab-strip" part="strip">
|
|
352
|
+
<div class="tab-buttons" part="buttons-container">
|
|
353
|
+
<div class="tab-strip" role="tablist" part="strip">
|
|
289
354
|
<div class="marker-wrapper" part="marker-wrapper">
|
|
290
355
|
${!hasCustomMarker(tabsEl) ? '<div class="default-marker"></div>' : ''}
|
|
291
356
|
<slot name="marker"></slot>
|
|
@@ -357,7 +422,7 @@ item.disabled = true;
|
|
|
357
422
|
}
|
|
358
423
|
else {
|
|
359
424
|
item.addEventListener('click', () => {
|
|
360
|
-
|
|
425
|
+
activateTab(el, tabId);
|
|
361
426
|
popup.closePopup?.();
|
|
362
427
|
});
|
|
363
428
|
}
|
|
@@ -430,26 +495,16 @@ function render(el) {
|
|
|
430
495
|
const shadowRoot = el.shadowRoot;
|
|
431
496
|
if (!shadowRoot)
|
|
432
497
|
return;
|
|
433
|
-
const {
|
|
498
|
+
const { placement, fixed } = getTabsAttributes(el);
|
|
434
499
|
const tabs = getChildTabs(el);
|
|
435
500
|
const activeId = getActiveTabId(el, tabs);
|
|
436
501
|
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
|
-
});
|
|
502
|
+
tabs.forEach((tab) => tab.setPanelLabel?.(getTabMenuLabel(el, tab)));
|
|
445
503
|
const existingContainer = shadowRoot.querySelector('.tabs-container');
|
|
446
504
|
const existingButtons = shadowRoot.querySelector('.tab-buttons');
|
|
447
505
|
const existingStrip = shadowRoot.querySelector('.tab-strip');
|
|
448
506
|
const existingViewport = shadowRoot.querySelector('.panels-viewport');
|
|
449
507
|
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
508
|
if (existingContainer && existingButtons && existingStrip && existingViewport) {
|
|
454
509
|
existingContainer.setAttribute('data-placement', placement);
|
|
455
510
|
existingContainer.toggleAttribute('data-fixed', fixed);
|
|
@@ -466,58 +521,41 @@ existingStrip.appendChild(button);
|
|
|
466
521
|
existingStrip.scrollLeft = savedScrollLeft;
|
|
467
522
|
setupEventListeners(el, shadowRoot, tabs);
|
|
468
523
|
updateAriaAttributes(el, shadowRoot, activeId || '');
|
|
524
|
+
const firstShow = !shownTabs.get(el);
|
|
469
525
|
requestAnimationFrame(() => {
|
|
470
|
-
const
|
|
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);
|
|
526
|
+
const currentId = currentActive(el);
|
|
477
527
|
updateOverflow(el);
|
|
478
|
-
if (
|
|
479
|
-
updateMarker(el,
|
|
480
|
-
scrollActiveIntoView(el,
|
|
528
|
+
if (currentId) {
|
|
529
|
+
updateMarker(el, currentId, firstShow);
|
|
530
|
+
scrollActiveIntoView(el, currentId, !firstShow);
|
|
481
531
|
}
|
|
482
532
|
});
|
|
483
|
-
if (activeId) {
|
|
484
533
|
updatePanelInteraction(el, activeId);
|
|
485
534
|
}
|
|
486
|
-
}
|
|
487
535
|
else {
|
|
488
|
-
pendingInitialSnap.add(el);
|
|
489
536
|
shadowRoot.innerHTML = `
|
|
490
537
|
<div class="tabs-container" data-placement="${placement}"${fixed ? ' data-fixed' : ''}>
|
|
491
538
|
${renderTabButtons(el, tabs, activeId)}
|
|
492
539
|
<div class="panels-viewport" part="panels-container">
|
|
493
|
-
<div class="panels-wrapper">
|
|
540
|
+
<div class="panels-wrapper" style="transform: ${carouselTransform(activeIndex)}">
|
|
494
541
|
<slot></slot>
|
|
495
542
|
</div>
|
|
496
543
|
</div>
|
|
497
544
|
</div>
|
|
498
545
|
`;
|
|
499
546
|
requestAnimationFrame(() => {
|
|
500
|
-
const
|
|
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);
|
|
547
|
+
const currentId = currentActive(el);
|
|
507
548
|
updateOverflow(el);
|
|
508
|
-
if (
|
|
509
|
-
updateMarker(el,
|
|
510
|
-
scrollActiveIntoView(el,
|
|
549
|
+
if (currentId) {
|
|
550
|
+
updateMarker(el, currentId);
|
|
551
|
+
scrollActiveIntoView(el, currentId, false);
|
|
511
552
|
}
|
|
512
553
|
});
|
|
513
554
|
setupEventListeners(el, shadowRoot, tabs);
|
|
514
555
|
updateAriaAttributes(el, shadowRoot, activeId || '');
|
|
515
|
-
setupResizeObserver(el);
|
|
516
556
|
const strip = shadowRoot.querySelector('.tab-strip');
|
|
517
557
|
strip?.addEventListener('scroll', () => updateEdgeFades(strip), { passive: true });
|
|
518
|
-
if (activeId) {
|
|
519
558
|
updatePanelInteraction(el, activeId);
|
|
520
|
-
}
|
|
521
559
|
const markerSlot = shadowRoot.querySelector('slot[name="marker"]');
|
|
522
560
|
if (markerSlot) {
|
|
523
561
|
const updateDefaultMarkerVisibility = () => {
|
|
@@ -543,21 +581,18 @@ return ['width', 'height', 'active', 'placement', 'fixed'];
|
|
|
543
581
|
constructor() {
|
|
544
582
|
super();
|
|
545
583
|
this._childObserver = null;
|
|
546
|
-
this.
|
|
584
|
+
this._updateQueued = false;
|
|
585
|
+
this._structureDirty = false;
|
|
547
586
|
this.attachShadow({ mode: 'open' });
|
|
548
587
|
}
|
|
588
|
+
get activeTab() {
|
|
589
|
+
return shownTabs.get(this) ?? null;
|
|
590
|
+
}
|
|
549
591
|
connectedCallback() {
|
|
550
592
|
render(this);
|
|
551
|
-
this
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
this._childRenderQueued = true;
|
|
555
|
-
queueMicrotask(() => {
|
|
556
|
-
this._childRenderQueued = false;
|
|
557
|
-
if (this.isConnected)
|
|
558
|
-
render(this);
|
|
559
|
-
});
|
|
560
|
-
});
|
|
593
|
+
syncShownTab(this);
|
|
594
|
+
setupResizeObserver(this);
|
|
595
|
+
this._childObserver = new MutationObserver(() => this._queueUpdate(true));
|
|
561
596
|
this._childObserver.observe(this, { childList: true });
|
|
562
597
|
}
|
|
563
598
|
disconnectedCallback() {
|
|
@@ -565,20 +600,34 @@ this._childObserver?.disconnect();
|
|
|
565
600
|
this._childObserver = null;
|
|
566
601
|
cleanup(this);
|
|
567
602
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
if (
|
|
603
|
+
_queueUpdate(structure) {
|
|
604
|
+
this._structureDirty || (this._structureDirty = structure);
|
|
605
|
+
if (this._updateQueued)
|
|
571
606
|
return;
|
|
572
|
-
|
|
573
|
-
|
|
607
|
+
this._updateQueued = true;
|
|
608
|
+
queueMicrotask(() => {
|
|
609
|
+
this._updateQueued = false;
|
|
610
|
+
if (!this.isConnected)
|
|
574
611
|
return;
|
|
612
|
+
if (this._childObserver?.takeRecords().length)
|
|
613
|
+
this._structureDirty = true;
|
|
614
|
+
if (this._structureDirty) {
|
|
615
|
+
this._structureDirty = false;
|
|
616
|
+
render(this);
|
|
575
617
|
}
|
|
576
|
-
|
|
577
|
-
|
|
618
|
+
syncShownTab(this);
|
|
619
|
+
});
|
|
578
620
|
}
|
|
579
|
-
|
|
580
|
-
|
|
621
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
622
|
+
if (!this.isConnected)
|
|
623
|
+
return;
|
|
624
|
+
if (name === 'active') {
|
|
625
|
+
if (oldValue !== newValue)
|
|
626
|
+
awaitedTabs.delete(this);
|
|
627
|
+
this._queueUpdate(false);
|
|
581
628
|
}
|
|
629
|
+
else
|
|
630
|
+
render(this);
|
|
582
631
|
}
|
|
583
632
|
}
|
|
584
633
|
if (!customElements.get('ty-tabs')) {
|
package/lib/components/tag.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ interface TagState {
|
|
|
9
9
|
size: Size;
|
|
10
10
|
value: string;
|
|
11
11
|
selected: boolean;
|
|
12
|
-
|
|
12
|
+
noPill: boolean;
|
|
13
13
|
clickable: boolean;
|
|
14
14
|
dismissible: boolean;
|
|
15
15
|
disabled: boolean;
|
|
@@ -50,13 +50,10 @@ export declare class TyTag extends TyComponent<TagState> implements TyTagElement
|
|
|
50
50
|
visual: boolean;
|
|
51
51
|
default: boolean;
|
|
52
52
|
};
|
|
53
|
-
|
|
53
|
+
noPill: {
|
|
54
54
|
type: "boolean";
|
|
55
55
|
visual: boolean;
|
|
56
56
|
default: boolean;
|
|
57
|
-
aliases: {
|
|
58
|
-
"not-pill": boolean;
|
|
59
|
-
};
|
|
60
57
|
};
|
|
61
58
|
clickable: {
|
|
62
59
|
type: "boolean";
|
|
@@ -106,8 +103,8 @@ export declare class TyTag extends TyComponent<TagState> implements TyTagElement
|
|
|
106
103
|
set value(val: string);
|
|
107
104
|
get selected(): boolean;
|
|
108
105
|
set selected(value: boolean);
|
|
109
|
-
get
|
|
110
|
-
set
|
|
106
|
+
get noPill(): boolean;
|
|
107
|
+
set noPill(value: boolean);
|
|
111
108
|
get clickable(): boolean;
|
|
112
109
|
set clickable(value: boolean);
|
|
113
110
|
get dismissible(): boolean;
|
package/lib/components/tag.js
CHANGED
|
@@ -171,11 +171,11 @@ return this.getProperty("selected");
|
|
|
171
171
|
set selected(value) {
|
|
172
172
|
this.setProperty("selected", value);
|
|
173
173
|
}
|
|
174
|
-
get
|
|
175
|
-
return this.getProperty("
|
|
174
|
+
get noPill() {
|
|
175
|
+
return this.getProperty("noPill");
|
|
176
176
|
}
|
|
177
|
-
set
|
|
178
|
-
this.setProperty("
|
|
177
|
+
set noPill(value) {
|
|
178
|
+
this.setProperty("noPill", value);
|
|
179
179
|
}
|
|
180
180
|
get clickable() {
|
|
181
181
|
return this.getProperty("clickable");
|
|
@@ -226,11 +226,10 @@ type: "boolean",
|
|
|
226
226
|
visual: true,
|
|
227
227
|
default: false,
|
|
228
228
|
},
|
|
229
|
-
|
|
229
|
+
noPill: {
|
|
230
230
|
type: "boolean",
|
|
231
231
|
visual: true,
|
|
232
|
-
default:
|
|
233
|
-
aliases: { "not-pill": false },
|
|
232
|
+
default: false,
|
|
234
233
|
},
|
|
235
234
|
clickable: {
|
|
236
235
|
type: "boolean",
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* ty-textarea — form-associated textarea that auto-resizes to its content,
|
|
3
3
|
* within optional min-height/max-height constraints.
|
|
4
4
|
*
|
|
5
|
-
* @fires {CustomEvent<{value: string, originalEvent: Event}>} input - Emitted on
|
|
6
|
-
* @fires {CustomEvent<{value: string, originalEvent: Event}>} change - Emitted on
|
|
5
|
+
* @fires {CustomEvent<{value: string, originalEvent: Event}>} input - Emitted on every edit
|
|
6
|
+
* @fires {CustomEvent<{value: string, originalEvent: Event}>} change - Emitted on blur, if the value changed (like a native textarea)
|
|
7
7
|
*/
|
|
8
8
|
import { TyComponent } from '../base/ty-component.js';
|
|
9
9
|
import type { PropertyChange } from '../utils/property-manager.js';
|
|
@@ -21,6 +21,10 @@ export interface TyTextareaElement extends HTMLElement {
|
|
|
21
21
|
label?: string;
|
|
22
22
|
disabled?: boolean;
|
|
23
23
|
required?: boolean;
|
|
24
|
+
minLength?: number;
|
|
25
|
+
maxLength?: number;
|
|
26
|
+
tooShortMessage?: string;
|
|
27
|
+
tooLongMessage?: string;
|
|
24
28
|
error?: string;
|
|
25
29
|
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
26
30
|
rows?: string | number;
|
|
@@ -63,6 +67,26 @@ export declare class TyTextarea extends TyComponent<TextareaState> implements Ty
|
|
|
63
67
|
visual: boolean;
|
|
64
68
|
default: boolean;
|
|
65
69
|
};
|
|
70
|
+
minlength: {
|
|
71
|
+
type: "string";
|
|
72
|
+
visual: boolean;
|
|
73
|
+
default: string;
|
|
74
|
+
};
|
|
75
|
+
maxlength: {
|
|
76
|
+
type: "string";
|
|
77
|
+
visual: boolean;
|
|
78
|
+
default: string;
|
|
79
|
+
};
|
|
80
|
+
tooShortMessage: {
|
|
81
|
+
type: "string";
|
|
82
|
+
visual: boolean;
|
|
83
|
+
default: string;
|
|
84
|
+
};
|
|
85
|
+
tooLongMessage: {
|
|
86
|
+
type: "string";
|
|
87
|
+
visual: boolean;
|
|
88
|
+
default: string;
|
|
89
|
+
};
|
|
66
90
|
error: {
|
|
67
91
|
type: "string";
|
|
68
92
|
visual: boolean;
|
|
@@ -125,8 +149,18 @@ export declare class TyTextarea extends TyComponent<TextareaState> implements Ty
|
|
|
125
149
|
set label(v: string);
|
|
126
150
|
get disabled(): boolean;
|
|
127
151
|
set disabled(v: boolean);
|
|
152
|
+
/** Focus the inner <textarea>: the host itself isn't focusable. */
|
|
153
|
+
focus(options?: FocusOptions): void;
|
|
128
154
|
get required(): boolean;
|
|
129
155
|
set required(v: boolean);
|
|
156
|
+
get minLength(): number;
|
|
157
|
+
set minLength(v: number);
|
|
158
|
+
get maxLength(): number;
|
|
159
|
+
set maxLength(v: number);
|
|
160
|
+
get tooShortMessage(): string;
|
|
161
|
+
set tooShortMessage(v: string);
|
|
162
|
+
get tooLongMessage(): string;
|
|
163
|
+
set tooLongMessage(v: string);
|
|
130
164
|
get error(): string;
|
|
131
165
|
set error(v: string);
|
|
132
166
|
get size(): 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
@@ -149,16 +183,28 @@ export declare class TyTextarea extends TyComponent<TextareaState> implements Ty
|
|
|
149
183
|
private resizeTextarea;
|
|
150
184
|
private _setupScrollbar;
|
|
151
185
|
private _destroyScrollbar;
|
|
152
|
-
private
|
|
186
|
+
private emitValueEvent;
|
|
153
187
|
private handleInputEvent;
|
|
188
|
+
private _valueAtFocus;
|
|
154
189
|
private handleFocusEvent;
|
|
155
190
|
private handleBlurEvent;
|
|
156
191
|
private buildClassList;
|
|
157
192
|
private applyHeightConstraints;
|
|
158
193
|
private setupTextareaEvents;
|
|
194
|
+
private removeTextareaEvents;
|
|
159
195
|
protected render(): void;
|
|
160
|
-
/**
|
|
161
|
-
*
|
|
196
|
+
/**
|
|
197
|
+
* minlength goes on the inner <textarea> for the browser's own too-short
|
|
198
|
+
* message after the user types, maxlength so typing stops at the limit
|
|
199
|
+
* (like ty-input).
|
|
200
|
+
*/
|
|
201
|
+
private syncConstraintAttributes;
|
|
202
|
+
/**
|
|
203
|
+
* required + empty => valueMissing (the browser's own message); otherwise
|
|
204
|
+
* minlength / maxlength, worded like ty-input's (lengthValidity). Empty
|
|
205
|
+
* values only fail `required`, like native. Disabled fields are barred
|
|
206
|
+
* from constraint validation.
|
|
207
|
+
*/
|
|
162
208
|
private updateValidity;
|
|
163
209
|
}
|
|
164
210
|
export {};
|