@vertz/ui-primitives 0.2.21 → 0.2.23
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/shared/{chunk-q8dm19a5.js → chunk-2db2dnp3.js} +0 -1
- package/dist/shared/chunk-3h1mxp95.js +148 -0
- package/dist/shared/chunk-3kwh27dv.js +135 -0
- package/dist/shared/chunk-4894pmy6.js +184 -0
- package/dist/shared/{chunk-v9qddmh9.js → chunk-56reyd5r.js} +20 -29
- package/dist/shared/chunk-67sn29eh.js +125 -0
- package/dist/shared/chunk-7cb3z0s8.js +287 -0
- package/dist/shared/chunk-8c01c8mb.js +217 -0
- package/dist/shared/chunk-99tk72t3.js +69 -0
- package/dist/shared/chunk-9gfp3ffv.js +204 -0
- package/dist/shared/chunk-b25npqer.js +149 -0
- package/dist/shared/chunk-cgb2j94g.js +141 -0
- package/dist/shared/chunk-e1jcf22s.js +79 -0
- package/dist/shared/chunk-e3h0ddmx.js +168 -0
- package/dist/shared/chunk-f2vx4tpw.js +168 -0
- package/dist/shared/chunk-h3v10x04.js +271 -0
- package/dist/shared/chunk-hdvdfd1c.js +96 -0
- package/dist/shared/{chunk-zf0rhm9e.js → chunk-j902w020.js} +1 -1
- package/dist/shared/chunk-jdygp28a.js +260 -0
- package/dist/shared/chunk-jqre4qtw.js +180 -0
- package/dist/shared/{chunk-pvy0tcd7.js → chunk-mgr904ap.js} +75 -35
- package/dist/shared/chunk-mr1tb0dp.js +167 -0
- package/dist/shared/chunk-nj420k31.js +54 -0
- package/dist/shared/chunk-p0x7hgv6.js +181 -0
- package/dist/shared/{chunk-gzgyfhz6.js → chunk-pn6shbcs.js} +134 -82
- package/dist/shared/chunk-pzx0vpq1.js +223 -0
- package/dist/shared/chunk-tn0m98j8.js +42 -0
- package/dist/shared/{chunk-g67tnd19.js → chunk-ttb2tt03.js} +49 -29
- package/dist/shared/{chunk-vvjyx7fe.js → chunk-vevfhpc9.js} +1 -1
- package/dist/shared/chunk-vy874zxe.js +68 -0
- package/dist/shared/chunk-ww7k2azn.js +297 -0
- package/dist/shared/{chunk-f501vw7e.js → chunk-xa1b96mb.js} +2 -2
- package/dist/shared/chunk-xs6gp369.js +245 -0
- package/dist/shared/chunk-y4mmmayp.js +206 -0
- package/dist/src/accordion/accordion.js +1 -1
- package/dist/src/alert-dialog/alert-dialog.js +1 -1
- package/dist/src/badge/badge.js +1 -1
- package/dist/src/button/button.js +1 -1
- package/dist/src/calendar/calendar.js +1 -1
- package/dist/src/carousel/carousel.js +1 -1
- package/dist/src/checkbox/checkbox.js +1 -1
- package/dist/src/collapsible/collapsible.js +1 -1
- package/dist/src/combobox/combobox.js +1 -1
- package/dist/src/command/command.js +1 -1
- package/dist/src/context-menu/context-menu.js +1 -1
- package/dist/src/date-picker/date-picker.js +1 -1
- package/dist/src/dialog/dialog.js +1 -1
- package/dist/src/dropdown-menu/dropdown-menu.js +1 -1
- package/dist/src/hover-card/hover-card.js +1 -1
- package/dist/src/index.d.ts +281 -106
- package/dist/src/index.js +5779 -4266
- package/dist/src/menu/menu.js +1 -1
- package/dist/src/menubar/menubar.js +1 -1
- package/dist/src/navigation-menu/navigation-menu.js +1 -1
- package/dist/src/popover/popover.js +1 -1
- package/dist/src/progress/progress.js +1 -1
- package/dist/src/radio/radio.js +1 -1
- package/dist/src/resizable-panel/resizable-panel.js +1 -1
- package/dist/src/scroll-area/scroll-area.js +1 -1
- package/dist/src/select/select.js +1 -1
- package/dist/src/sheet/sheet.js +1 -1
- package/dist/src/slider/slider.js +1 -1
- package/dist/src/switch/switch.js +1 -1
- package/dist/src/tabs/tabs.js +1 -1
- package/dist/src/toast/toast.js +1 -1
- package/dist/src/toggle/toggle.js +1 -1
- package/dist/src/toggle-group/toggle-group.js +1 -1
- package/dist/src/tooltip/tooltip.js +1 -1
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.js +3 -3
- package/package.json +3 -3
- package/dist/shared/chunk-0gn67thm.js +0 -88
- package/dist/shared/chunk-1dzcjmfq.js +0 -46
- package/dist/shared/chunk-1hv9yd28.js +0 -178
- package/dist/shared/chunk-2d05qxdw.js +0 -282
- package/dist/shared/chunk-4jnweh3m.js +0 -165
- package/dist/shared/chunk-90hmpm0w.js +0 -34
- package/dist/shared/chunk-ac86qw7a.js +0 -71
- package/dist/shared/chunk-b02fkvts.js +0 -128
- package/dist/shared/chunk-bsx59bv9.js +0 -61
- package/dist/shared/chunk-cm2akzrm.js +0 -161
- package/dist/shared/chunk-cvms20w3.js +0 -132
- package/dist/shared/chunk-d8n8mggh.js +0 -239
- package/dist/shared/chunk-er9625ar.js +0 -204
- package/dist/shared/chunk-ewxzhtej.js +0 -117
- package/dist/shared/chunk-ey4485fh.js +0 -196
- package/dist/shared/chunk-gbxbkmte.js +0 -175
- package/dist/shared/chunk-je7tqf67.js +0 -133
- package/dist/shared/chunk-kr5qg80z.js +0 -288
- package/dist/shared/chunk-kytkmdpc.js +0 -199
- package/dist/shared/chunk-q2q20y9a.js +0 -60
- package/dist/shared/chunk-q9fgfgh9.js +0 -267
- package/dist/shared/chunk-qfk1ycfw.js +0 -142
- package/dist/shared/chunk-te4pdqnh.js +0 -219
- package/dist/shared/chunk-vm37m55w.js +0 -175
- package/dist/shared/chunk-y5vdb6br.js +0 -151
- package/dist/shared/chunk-ztvj60xp.js +0 -185
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createDismiss
|
|
3
|
+
} from "./chunk-a6wp8c32.js";
|
|
4
|
+
import {
|
|
5
|
+
createFloatingPosition
|
|
6
|
+
} from "./chunk-0mcr52hc.js";
|
|
7
|
+
import {
|
|
8
|
+
Keys,
|
|
9
|
+
handleListNavigation,
|
|
10
|
+
isKey
|
|
11
|
+
} from "./chunk-7867pr13.js";
|
|
12
|
+
import {
|
|
13
|
+
setDataState,
|
|
14
|
+
setExpanded,
|
|
15
|
+
setHidden,
|
|
16
|
+
setHiddenAnimated,
|
|
17
|
+
setSelected
|
|
18
|
+
} from "./chunk-vevfhpc9.js";
|
|
19
|
+
import {
|
|
20
|
+
linkedIds
|
|
21
|
+
} from "./chunk-8y1jf6xr.js";
|
|
22
|
+
import {
|
|
23
|
+
applyAttrs
|
|
24
|
+
} from "./chunk-2db2dnp3.js";
|
|
25
|
+
|
|
26
|
+
// src/select/select.tsx
|
|
27
|
+
import { __discardMountFrame, __element, __enterChildren, __exitChildren, __flushMountFrame, __insert, __on, __pushMountFrame, __styleStr } from "@vertz/ui/internals";
|
|
28
|
+
import { signal } from "@vertz/ui";
|
|
29
|
+
function SelectRoot(options = {}) {
|
|
30
|
+
const __mfDepth = __pushMountFrame();
|
|
31
|
+
try {
|
|
32
|
+
let updateActiveItem = function(index) {
|
|
33
|
+
for (let i = 0;i < items.length; i++) {
|
|
34
|
+
items[i]?.setAttribute("tabindex", i === index ? "0" : "-1");
|
|
35
|
+
}
|
|
36
|
+
}, selectItem = function(value) {
|
|
37
|
+
state.value.value = value;
|
|
38
|
+
for (const item of items) {
|
|
39
|
+
const isActive = item.getAttribute("data-value") === value;
|
|
40
|
+
setSelected(item, isActive);
|
|
41
|
+
setDataState(item, isActive ? "active" : "inactive");
|
|
42
|
+
if (isActive) {
|
|
43
|
+
triggerText.textContent = item.textContent ?? value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
onValueChange?.(value);
|
|
47
|
+
close();
|
|
48
|
+
}, open = function() {
|
|
49
|
+
state.open.value = true;
|
|
50
|
+
setExpanded(trigger, true);
|
|
51
|
+
setHidden(content, false);
|
|
52
|
+
setDataState(trigger, "open");
|
|
53
|
+
setDataState(content, "open");
|
|
54
|
+
if (positioning) {
|
|
55
|
+
const result = createFloatingPosition(trigger, content, positioning);
|
|
56
|
+
floatingCleanup = result.cleanup;
|
|
57
|
+
dismissCleanup = createDismiss({
|
|
58
|
+
onDismiss: close,
|
|
59
|
+
insideElements: [trigger, content],
|
|
60
|
+
escapeKey: false
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
const rect = trigger.getBoundingClientRect();
|
|
64
|
+
const side = window.innerHeight - rect.bottom >= rect.top ? "bottom" : "top";
|
|
65
|
+
content.setAttribute("data-side", side);
|
|
66
|
+
}
|
|
67
|
+
const selectedIdx = items.findIndex((item) => item.getAttribute("data-value") === state.value.peek());
|
|
68
|
+
if (selectedIdx >= 0) {
|
|
69
|
+
state.activeIndex.value = selectedIdx;
|
|
70
|
+
updateActiveItem(selectedIdx);
|
|
71
|
+
items[selectedIdx]?.focus();
|
|
72
|
+
} else {
|
|
73
|
+
state.activeIndex.value = -1;
|
|
74
|
+
updateActiveItem(-1);
|
|
75
|
+
content.focus();
|
|
76
|
+
}
|
|
77
|
+
}, close = function() {
|
|
78
|
+
state.open.value = false;
|
|
79
|
+
setExpanded(trigger, false);
|
|
80
|
+
setDataState(trigger, "closed");
|
|
81
|
+
setDataState(content, "closed");
|
|
82
|
+
setHiddenAnimated(content, true);
|
|
83
|
+
floatingCleanup?.();
|
|
84
|
+
floatingCleanup = null;
|
|
85
|
+
dismissCleanup?.();
|
|
86
|
+
dismissCleanup = null;
|
|
87
|
+
trigger.focus();
|
|
88
|
+
}, createItem = function(value, label, parent) {
|
|
89
|
+
const isSelectedItem = value === defaultValue;
|
|
90
|
+
const item = (() => {
|
|
91
|
+
const __el3 = __element("div");
|
|
92
|
+
__el3.setAttribute("role", "option");
|
|
93
|
+
{
|
|
94
|
+
const __v = value;
|
|
95
|
+
if (__v != null && __v !== false)
|
|
96
|
+
__el3.setAttribute("data-value", __v === true ? "" : __v);
|
|
97
|
+
}
|
|
98
|
+
__el3.setAttribute("tabindex", "-1");
|
|
99
|
+
{
|
|
100
|
+
const __v = isSelectedItem ? "true" : "false";
|
|
101
|
+
if (__v != null && __v !== false)
|
|
102
|
+
__el3.setAttribute("aria-selected", __v === true ? "" : __v);
|
|
103
|
+
}
|
|
104
|
+
{
|
|
105
|
+
const __v = isSelectedItem ? "active" : "inactive";
|
|
106
|
+
if (__v != null && __v !== false)
|
|
107
|
+
__el3.setAttribute("data-state", __v === true ? "" : __v);
|
|
108
|
+
}
|
|
109
|
+
__on(__el3, "click", () => selectItem(value));
|
|
110
|
+
__enterChildren(__el3);
|
|
111
|
+
__insert(__el3, label ?? value);
|
|
112
|
+
__exitChildren();
|
|
113
|
+
return __el3;
|
|
114
|
+
})();
|
|
115
|
+
if (isSelectedItem) {
|
|
116
|
+
triggerText.textContent = item.textContent ?? value;
|
|
117
|
+
}
|
|
118
|
+
items.push(item);
|
|
119
|
+
(parent ?? content).appendChild(item);
|
|
120
|
+
return item;
|
|
121
|
+
}, Item = function(value, label) {
|
|
122
|
+
return createItem(value, label);
|
|
123
|
+
}, Group = function(label) {
|
|
124
|
+
const el = (() => {
|
|
125
|
+
const __el4 = __element("div");
|
|
126
|
+
__el4.setAttribute("role", "group");
|
|
127
|
+
{
|
|
128
|
+
const __v = label;
|
|
129
|
+
if (__v != null && __v !== false)
|
|
130
|
+
__el4.setAttribute("aria-label", __v === true ? "" : __v);
|
|
131
|
+
}
|
|
132
|
+
return __el4;
|
|
133
|
+
})();
|
|
134
|
+
content.appendChild(el);
|
|
135
|
+
return {
|
|
136
|
+
el,
|
|
137
|
+
Item: (value, itemLabel) => createItem(value, itemLabel, el)
|
|
138
|
+
};
|
|
139
|
+
}, Separator = function() {
|
|
140
|
+
const hr = (() => {
|
|
141
|
+
const __el5 = __element("hr");
|
|
142
|
+
__el5.setAttribute("role", "separator");
|
|
143
|
+
return __el5;
|
|
144
|
+
})();
|
|
145
|
+
content.appendChild(hr);
|
|
146
|
+
return hr;
|
|
147
|
+
};
|
|
148
|
+
const { defaultValue = "", placeholder = "", onValueChange, positioning, ...attrs } = options;
|
|
149
|
+
const ids = linkedIds("select");
|
|
150
|
+
const state = {
|
|
151
|
+
open: signal(false),
|
|
152
|
+
value: signal(defaultValue),
|
|
153
|
+
activeIndex: signal(-1)
|
|
154
|
+
};
|
|
155
|
+
const items = [];
|
|
156
|
+
let floatingCleanup = null;
|
|
157
|
+
let dismissCleanup = null;
|
|
158
|
+
const triggerText = (() => {
|
|
159
|
+
const __el0 = __element("span");
|
|
160
|
+
__el0.setAttribute("data-part", "value");
|
|
161
|
+
__enterChildren(__el0);
|
|
162
|
+
__insert(__el0, defaultValue || placeholder);
|
|
163
|
+
__exitChildren();
|
|
164
|
+
return __el0;
|
|
165
|
+
})();
|
|
166
|
+
const trigger = (() => {
|
|
167
|
+
const __el1 = __element("button");
|
|
168
|
+
__el1.setAttribute("type", "button");
|
|
169
|
+
__el1.setAttribute("role", "combobox");
|
|
170
|
+
{
|
|
171
|
+
const __v = ids.triggerId;
|
|
172
|
+
if (__v != null && __v !== false)
|
|
173
|
+
__el1.setAttribute("id", __v === true ? "" : __v);
|
|
174
|
+
}
|
|
175
|
+
{
|
|
176
|
+
const __v = ids.contentId;
|
|
177
|
+
if (__v != null && __v !== false)
|
|
178
|
+
__el1.setAttribute("aria-controls", __v === true ? "" : __v);
|
|
179
|
+
}
|
|
180
|
+
__el1.setAttribute("aria-haspopup", "listbox");
|
|
181
|
+
__el1.setAttribute("aria-expanded", "false");
|
|
182
|
+
__el1.setAttribute("data-state", "closed");
|
|
183
|
+
__on(__el1, "click", () => {
|
|
184
|
+
if (state.open.peek()) {
|
|
185
|
+
close();
|
|
186
|
+
} else {
|
|
187
|
+
open();
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
__on(__el1, "keydown", (event) => {
|
|
191
|
+
if (isKey(event, Keys.ArrowDown, Keys.ArrowUp, Keys.Enter, Keys.Space)) {
|
|
192
|
+
event.preventDefault();
|
|
193
|
+
if (!state.open.peek()) {
|
|
194
|
+
open();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
__enterChildren(__el1);
|
|
199
|
+
__insert(__el1, triggerText);
|
|
200
|
+
__exitChildren();
|
|
201
|
+
return __el1;
|
|
202
|
+
})();
|
|
203
|
+
const content = (() => {
|
|
204
|
+
const __el2 = __element("div");
|
|
205
|
+
__el2.setAttribute("role", "listbox");
|
|
206
|
+
__el2.setAttribute("tabindex", "-1");
|
|
207
|
+
{
|
|
208
|
+
const __v = ids.contentId;
|
|
209
|
+
if (__v != null && __v !== false)
|
|
210
|
+
__el2.setAttribute("id", __v === true ? "" : __v);
|
|
211
|
+
}
|
|
212
|
+
__el2.setAttribute("aria-hidden", "true");
|
|
213
|
+
__el2.setAttribute("data-state", "closed");
|
|
214
|
+
{
|
|
215
|
+
const __v = { display: "none" };
|
|
216
|
+
if (__v != null && __v !== false)
|
|
217
|
+
__el2.setAttribute("style", typeof __v === "object" ? __styleStr(__v) : __v === true ? "" : String(__v));
|
|
218
|
+
}
|
|
219
|
+
__on(__el2, "keydown", (event) => {
|
|
220
|
+
if (isKey(event, Keys.Escape)) {
|
|
221
|
+
event.preventDefault();
|
|
222
|
+
close();
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (isKey(event, Keys.Enter, Keys.Space)) {
|
|
226
|
+
event.preventDefault();
|
|
227
|
+
const active = items[state.activeIndex.peek()];
|
|
228
|
+
if (active) {
|
|
229
|
+
const val = active.getAttribute("data-value");
|
|
230
|
+
if (val !== null)
|
|
231
|
+
selectItem(val);
|
|
232
|
+
}
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (state.activeIndex.peek() === -1) {
|
|
236
|
+
if (isKey(event, Keys.ArrowDown)) {
|
|
237
|
+
event.preventDefault();
|
|
238
|
+
state.activeIndex.value = 0;
|
|
239
|
+
updateActiveItem(0);
|
|
240
|
+
items[0]?.focus();
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (isKey(event, Keys.ArrowUp)) {
|
|
244
|
+
event.preventDefault();
|
|
245
|
+
const last = items.length - 1;
|
|
246
|
+
state.activeIndex.value = last;
|
|
247
|
+
updateActiveItem(last);
|
|
248
|
+
items[last]?.focus();
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const result = handleListNavigation(event, items, { orientation: "vertical" });
|
|
253
|
+
if (result) {
|
|
254
|
+
const idx = items.indexOf(result);
|
|
255
|
+
if (idx >= 0) {
|
|
256
|
+
state.activeIndex.value = idx;
|
|
257
|
+
updateActiveItem(idx);
|
|
258
|
+
}
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
|
262
|
+
const char = event.key.toLowerCase();
|
|
263
|
+
const match = items.find((item) => item.textContent?.toLowerCase().startsWith(char));
|
|
264
|
+
if (match) {
|
|
265
|
+
const idx = items.indexOf(match);
|
|
266
|
+
state.activeIndex.value = idx;
|
|
267
|
+
updateActiveItem(idx);
|
|
268
|
+
match.focus();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
return __el2;
|
|
273
|
+
})();
|
|
274
|
+
applyAttrs(trigger, attrs);
|
|
275
|
+
const __mfResult0 = { trigger, content, state, Item, Group, Separator };
|
|
276
|
+
__flushMountFrame();
|
|
277
|
+
return __mfResult0;
|
|
278
|
+
} catch (__mfErr) {
|
|
279
|
+
__discardMountFrame(__mfDepth);
|
|
280
|
+
throw __mfErr;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
var Select = {
|
|
284
|
+
Root: SelectRoot
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
export { Select };
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import {
|
|
2
|
+
setRovingTabindex
|
|
3
|
+
} from "./chunk-e2v1c9ex.js";
|
|
4
|
+
import {
|
|
5
|
+
handleListNavigation
|
|
6
|
+
} from "./chunk-7867pr13.js";
|
|
7
|
+
import {
|
|
8
|
+
setDataState,
|
|
9
|
+
setHidden,
|
|
10
|
+
setSelected
|
|
11
|
+
} from "./chunk-vevfhpc9.js";
|
|
12
|
+
import {
|
|
13
|
+
uniqueId
|
|
14
|
+
} from "./chunk-8y1jf6xr.js";
|
|
15
|
+
import {
|
|
16
|
+
applyAttrs
|
|
17
|
+
} from "./chunk-2db2dnp3.js";
|
|
18
|
+
|
|
19
|
+
// src/tabs/tabs.tsx
|
|
20
|
+
import { __discardMountFrame, __element, __enterChildren, __exitChildren, __flushMountFrame, __insert, __on, __pushMountFrame, __styleStr } from "@vertz/ui/internals";
|
|
21
|
+
import { signal } from "@vertz/ui";
|
|
22
|
+
function TabList(orientation, triggers, tabValues, selectTab) {
|
|
23
|
+
const __mfDepth = __pushMountFrame();
|
|
24
|
+
try {
|
|
25
|
+
const __mfResult0 = (() => {
|
|
26
|
+
const __el0 = __element("div");
|
|
27
|
+
__el0.setAttribute("role", "tablist");
|
|
28
|
+
{
|
|
29
|
+
const __v = orientation === "vertical" ? "vertical" : undefined;
|
|
30
|
+
if (__v != null && __v !== false)
|
|
31
|
+
__el0.setAttribute("aria-orientation", __v === true ? "" : __v);
|
|
32
|
+
}
|
|
33
|
+
__on(__el0, "keydown", (event) => {
|
|
34
|
+
const result = handleListNavigation(event, triggers, {
|
|
35
|
+
orientation
|
|
36
|
+
});
|
|
37
|
+
if (result) {
|
|
38
|
+
const idx = triggers.indexOf(result);
|
|
39
|
+
if (idx >= 0) {
|
|
40
|
+
const val = tabValues[idx];
|
|
41
|
+
if (val !== undefined)
|
|
42
|
+
selectTab(val);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return __el0;
|
|
47
|
+
})();
|
|
48
|
+
__flushMountFrame();
|
|
49
|
+
return __mfResult0;
|
|
50
|
+
} catch (__mfErr) {
|
|
51
|
+
__discardMountFrame(__mfDepth);
|
|
52
|
+
throw __mfErr;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function TabTrigger(triggerId, panelId, value, label, isActive, selectTab) {
|
|
56
|
+
const __mfDepth = __pushMountFrame();
|
|
57
|
+
try {
|
|
58
|
+
const __mfResult0 = (() => {
|
|
59
|
+
const __el0 = __element("button");
|
|
60
|
+
__el0.setAttribute("type", "button");
|
|
61
|
+
__el0.setAttribute("role", "tab");
|
|
62
|
+
{
|
|
63
|
+
const __v = triggerId;
|
|
64
|
+
if (__v != null && __v !== false)
|
|
65
|
+
__el0.setAttribute("id", __v === true ? "" : __v);
|
|
66
|
+
}
|
|
67
|
+
{
|
|
68
|
+
const __v = panelId;
|
|
69
|
+
if (__v != null && __v !== false)
|
|
70
|
+
__el0.setAttribute("aria-controls", __v === true ? "" : __v);
|
|
71
|
+
}
|
|
72
|
+
{
|
|
73
|
+
const __v = value;
|
|
74
|
+
if (__v != null && __v !== false)
|
|
75
|
+
__el0.setAttribute("data-value", __v === true ? "" : __v);
|
|
76
|
+
}
|
|
77
|
+
{
|
|
78
|
+
const __v = isActive ? "true" : "false";
|
|
79
|
+
if (__v != null && __v !== false)
|
|
80
|
+
__el0.setAttribute("aria-selected", __v === true ? "" : __v);
|
|
81
|
+
}
|
|
82
|
+
{
|
|
83
|
+
const __v = isActive ? "active" : "inactive";
|
|
84
|
+
if (__v != null && __v !== false)
|
|
85
|
+
__el0.setAttribute("data-state", __v === true ? "" : __v);
|
|
86
|
+
}
|
|
87
|
+
__on(__el0, "click", () => {
|
|
88
|
+
selectTab(value);
|
|
89
|
+
});
|
|
90
|
+
__enterChildren(__el0);
|
|
91
|
+
__insert(__el0, label ?? value);
|
|
92
|
+
__exitChildren();
|
|
93
|
+
return __el0;
|
|
94
|
+
})();
|
|
95
|
+
__flushMountFrame();
|
|
96
|
+
return __mfResult0;
|
|
97
|
+
} catch (__mfErr) {
|
|
98
|
+
__discardMountFrame(__mfDepth);
|
|
99
|
+
throw __mfErr;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function TabsContainer(list) {
|
|
103
|
+
const __mfDepth = __pushMountFrame();
|
|
104
|
+
try {
|
|
105
|
+
const __mfResult0 = (() => {
|
|
106
|
+
const __el0 = __element("div");
|
|
107
|
+
__enterChildren(__el0);
|
|
108
|
+
__insert(__el0, list);
|
|
109
|
+
__exitChildren();
|
|
110
|
+
return __el0;
|
|
111
|
+
})();
|
|
112
|
+
__flushMountFrame();
|
|
113
|
+
return __mfResult0;
|
|
114
|
+
} catch (__mfErr) {
|
|
115
|
+
__discardMountFrame(__mfDepth);
|
|
116
|
+
throw __mfErr;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function TabPanel(panelId, triggerId, isActive) {
|
|
120
|
+
const __mfDepth = __pushMountFrame();
|
|
121
|
+
try {
|
|
122
|
+
const __mfResult0 = (() => {
|
|
123
|
+
const __el0 = __element("div");
|
|
124
|
+
__el0.setAttribute("role", "tabpanel");
|
|
125
|
+
{
|
|
126
|
+
const __v = panelId;
|
|
127
|
+
if (__v != null && __v !== false)
|
|
128
|
+
__el0.setAttribute("id", __v === true ? "" : __v);
|
|
129
|
+
}
|
|
130
|
+
{
|
|
131
|
+
const __v = triggerId;
|
|
132
|
+
if (__v != null && __v !== false)
|
|
133
|
+
__el0.setAttribute("aria-labelledby", __v === true ? "" : __v);
|
|
134
|
+
}
|
|
135
|
+
__el0.setAttribute("tabindex", "0");
|
|
136
|
+
{
|
|
137
|
+
const __v = isActive ? "false" : "true";
|
|
138
|
+
if (__v != null && __v !== false)
|
|
139
|
+
__el0.setAttribute("aria-hidden", __v === true ? "" : __v);
|
|
140
|
+
}
|
|
141
|
+
{
|
|
142
|
+
const __v = isActive ? "active" : "inactive";
|
|
143
|
+
if (__v != null && __v !== false)
|
|
144
|
+
__el0.setAttribute("data-state", __v === true ? "" : __v);
|
|
145
|
+
}
|
|
146
|
+
{
|
|
147
|
+
const __v = { display: isActive ? "" : "none" };
|
|
148
|
+
if (__v != null && __v !== false)
|
|
149
|
+
__el0.setAttribute("style", typeof __v === "object" ? __styleStr(__v) : __v === true ? "" : String(__v));
|
|
150
|
+
}
|
|
151
|
+
return __el0;
|
|
152
|
+
})();
|
|
153
|
+
__flushMountFrame();
|
|
154
|
+
return __mfResult0;
|
|
155
|
+
} catch (__mfErr) {
|
|
156
|
+
__discardMountFrame(__mfDepth);
|
|
157
|
+
throw __mfErr;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function TabsRoot(options = {}) {
|
|
161
|
+
const { defaultValue = "", orientation = "horizontal", onValueChange, ...attrs } = options;
|
|
162
|
+
const state = { value: signal(defaultValue) };
|
|
163
|
+
const triggers = [];
|
|
164
|
+
const panels = [];
|
|
165
|
+
const tabValues = [];
|
|
166
|
+
function selectTab(value) {
|
|
167
|
+
state.value.value = value;
|
|
168
|
+
for (let i = 0;i < tabValues.length; i++) {
|
|
169
|
+
const isActive = tabValues[i] === value;
|
|
170
|
+
const trig = triggers[i];
|
|
171
|
+
const panel = panels[i];
|
|
172
|
+
if (!trig || !panel)
|
|
173
|
+
continue;
|
|
174
|
+
setSelected(trig, isActive);
|
|
175
|
+
setDataState(trig, isActive ? "active" : "inactive");
|
|
176
|
+
trig.setAttribute("tabindex", isActive ? "0" : "-1");
|
|
177
|
+
setHidden(panel, !isActive);
|
|
178
|
+
setDataState(panel, isActive ? "active" : "inactive");
|
|
179
|
+
}
|
|
180
|
+
onValueChange?.(value);
|
|
181
|
+
}
|
|
182
|
+
const list = TabList(orientation, triggers, tabValues, selectTab);
|
|
183
|
+
const root = TabsContainer(list);
|
|
184
|
+
const cleanups = [];
|
|
185
|
+
function Tab(value, label) {
|
|
186
|
+
const baseId = uniqueId("tab");
|
|
187
|
+
const triggerId = `${baseId}-trigger`;
|
|
188
|
+
const panelId = `${baseId}-panel`;
|
|
189
|
+
const isActive = value === state.value.peek();
|
|
190
|
+
const trig = TabTrigger(triggerId, panelId, value, label, isActive, selectTab);
|
|
191
|
+
const handleClick = () => {
|
|
192
|
+
trig.focus();
|
|
193
|
+
};
|
|
194
|
+
trig.addEventListener("click", handleClick);
|
|
195
|
+
cleanups.push(() => trig.removeEventListener("click", handleClick));
|
|
196
|
+
const panel = TabPanel(panelId, triggerId, isActive);
|
|
197
|
+
triggers.push(trig);
|
|
198
|
+
panels.push(panel);
|
|
199
|
+
tabValues.push(value);
|
|
200
|
+
list.appendChild(trig);
|
|
201
|
+
root.appendChild(panel);
|
|
202
|
+
setRovingTabindex(triggers, triggers.findIndex((t) => tabValues[triggers.indexOf(t)] === state.value.peek()));
|
|
203
|
+
return { trigger: trig, panel };
|
|
204
|
+
}
|
|
205
|
+
function destroy() {
|
|
206
|
+
for (const cleanup of cleanups)
|
|
207
|
+
cleanup();
|
|
208
|
+
cleanups.length = 0;
|
|
209
|
+
}
|
|
210
|
+
applyAttrs(root, attrs);
|
|
211
|
+
return { root, list, state, Tab, destroy };
|
|
212
|
+
}
|
|
213
|
+
var Tabs = {
|
|
214
|
+
Root: TabsRoot
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export { Tabs };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Keys,
|
|
3
|
+
isKey
|
|
4
|
+
} from "./chunk-7867pr13.js";
|
|
5
|
+
import {
|
|
6
|
+
uniqueId
|
|
7
|
+
} from "./chunk-8y1jf6xr.js";
|
|
8
|
+
import {
|
|
9
|
+
applyAttrs
|
|
10
|
+
} from "./chunk-2db2dnp3.js";
|
|
11
|
+
|
|
12
|
+
// src/switch/switch.tsx
|
|
13
|
+
import { computed, signal } from "@vertz/ui";
|
|
14
|
+
import { __attr, __discardMountFrame, __element, __flushMountFrame, __on, __pushMountFrame } from "@vertz/ui/internals";
|
|
15
|
+
function SwitchRoot(options = {}) {
|
|
16
|
+
const __mfDepth = __pushMountFrame();
|
|
17
|
+
try {
|
|
18
|
+
let toggle = function() {
|
|
19
|
+
if (disabled)
|
|
20
|
+
return;
|
|
21
|
+
checked.value = !checked.value;
|
|
22
|
+
onCheckedChange?.(checked.value);
|
|
23
|
+
};
|
|
24
|
+
const { defaultChecked = false, disabled = false, onCheckedChange, ...attrs } = options;
|
|
25
|
+
const checked = signal(defaultChecked, "checked");
|
|
26
|
+
const el = computed(() => (() => {
|
|
27
|
+
const __el0 = __element("button");
|
|
28
|
+
__el0.setAttribute("type", "button");
|
|
29
|
+
__el0.setAttribute("role", "switch");
|
|
30
|
+
{
|
|
31
|
+
const __v = uniqueId("switch");
|
|
32
|
+
if (__v != null && __v !== false)
|
|
33
|
+
__el0.setAttribute("id", __v === true ? "" : __v);
|
|
34
|
+
}
|
|
35
|
+
__attr(__el0, "aria-checked", () => checked.value ? "true" : "false");
|
|
36
|
+
__attr(__el0, "data-state", () => checked.value ? "checked" : "unchecked");
|
|
37
|
+
{
|
|
38
|
+
const __v = disabled;
|
|
39
|
+
if (__v != null && __v !== false)
|
|
40
|
+
__el0.setAttribute("disabled", __v === true ? "" : __v);
|
|
41
|
+
}
|
|
42
|
+
{
|
|
43
|
+
const __v = disabled ? "true" : undefined;
|
|
44
|
+
if (__v != null && __v !== false)
|
|
45
|
+
__el0.setAttribute("aria-disabled", __v === true ? "" : __v);
|
|
46
|
+
}
|
|
47
|
+
__on(__el0, "click", toggle);
|
|
48
|
+
__on(__el0, "keydown", (e) => {
|
|
49
|
+
if (isKey(e, Keys.Space)) {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
toggle();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return __el0;
|
|
55
|
+
})());
|
|
56
|
+
applyAttrs(el.value, attrs);
|
|
57
|
+
const __mfResult0 = el.value;
|
|
58
|
+
__flushMountFrame();
|
|
59
|
+
return __mfResult0;
|
|
60
|
+
} catch (__mfErr) {
|
|
61
|
+
__discardMountFrame(__mfDepth);
|
|
62
|
+
throw __mfErr;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
var Switch = {
|
|
66
|
+
Root: SwitchRoot
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { Switch };
|