@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,223 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createDismiss
|
|
3
|
+
} from "./chunk-a6wp8c32.js";
|
|
4
|
+
import {
|
|
5
|
+
createFloatingPosition,
|
|
6
|
+
virtualElement
|
|
7
|
+
} from "./chunk-0mcr52hc.js";
|
|
8
|
+
import {
|
|
9
|
+
Keys,
|
|
10
|
+
handleListNavigation,
|
|
11
|
+
isKey
|
|
12
|
+
} from "./chunk-7867pr13.js";
|
|
13
|
+
import {
|
|
14
|
+
setDataState,
|
|
15
|
+
setHidden,
|
|
16
|
+
setHiddenAnimated
|
|
17
|
+
} from "./chunk-vevfhpc9.js";
|
|
18
|
+
import {
|
|
19
|
+
uniqueId
|
|
20
|
+
} from "./chunk-8y1jf6xr.js";
|
|
21
|
+
import {
|
|
22
|
+
applyAttrs
|
|
23
|
+
} from "./chunk-2db2dnp3.js";
|
|
24
|
+
|
|
25
|
+
// src/context-menu/context-menu.tsx
|
|
26
|
+
import { __discardMountFrame, __element, __enterChildren, __exitChildren, __flushMountFrame, __insert, __on, __pushMountFrame, __styleStr } from "@vertz/ui/internals";
|
|
27
|
+
import { signal } from "@vertz/ui";
|
|
28
|
+
function ContextMenuRoot(options = {}) {
|
|
29
|
+
const __mfDepth = __pushMountFrame();
|
|
30
|
+
try {
|
|
31
|
+
let handleClickOutside = function(event) {
|
|
32
|
+
const target = event.target;
|
|
33
|
+
if (!trigger.contains(target) && !content.contains(target)) {
|
|
34
|
+
close();
|
|
35
|
+
}
|
|
36
|
+
}, updateActiveItem = function(index) {
|
|
37
|
+
for (let i = 0;i < items.length; i++) {
|
|
38
|
+
items[i]?.setAttribute("tabindex", i === index ? "0" : "-1");
|
|
39
|
+
}
|
|
40
|
+
}, openMenu = function(x, y) {
|
|
41
|
+
state.open.value = true;
|
|
42
|
+
setHidden(content, false);
|
|
43
|
+
setDataState(content, "open");
|
|
44
|
+
if (positioning) {
|
|
45
|
+
const result = createFloatingPosition(virtualElement(x, y), content, {
|
|
46
|
+
strategy: "fixed",
|
|
47
|
+
...positioning
|
|
48
|
+
});
|
|
49
|
+
floatingCleanup = result.cleanup;
|
|
50
|
+
dismissCleanup = createDismiss({
|
|
51
|
+
onDismiss: close,
|
|
52
|
+
insideElements: [trigger, content],
|
|
53
|
+
escapeKey: false
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
content.style.left = `${x}px`;
|
|
57
|
+
content.style.top = `${y}px`;
|
|
58
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
59
|
+
}
|
|
60
|
+
state.activeIndex.value = 0;
|
|
61
|
+
updateActiveItem(0);
|
|
62
|
+
items[0]?.focus();
|
|
63
|
+
}, close = function() {
|
|
64
|
+
state.open.value = false;
|
|
65
|
+
setDataState(content, "closed");
|
|
66
|
+
setHiddenAnimated(content, true);
|
|
67
|
+
if (positioning) {
|
|
68
|
+
floatingCleanup?.();
|
|
69
|
+
floatingCleanup = null;
|
|
70
|
+
dismissCleanup?.();
|
|
71
|
+
dismissCleanup = null;
|
|
72
|
+
} else {
|
|
73
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
74
|
+
}
|
|
75
|
+
}, createItem = function(value, label, parent) {
|
|
76
|
+
const item = (() => {
|
|
77
|
+
const __el2 = __element("div");
|
|
78
|
+
__el2.setAttribute("role", "menuitem");
|
|
79
|
+
{
|
|
80
|
+
const __v = value;
|
|
81
|
+
if (__v != null && __v !== false)
|
|
82
|
+
__el2.setAttribute("data-value", __v === true ? "" : __v);
|
|
83
|
+
}
|
|
84
|
+
__el2.setAttribute("tabindex", "-1");
|
|
85
|
+
__on(__el2, "click", () => {
|
|
86
|
+
onSelect?.(value);
|
|
87
|
+
close();
|
|
88
|
+
});
|
|
89
|
+
__enterChildren(__el2);
|
|
90
|
+
__insert(__el2, label ?? value);
|
|
91
|
+
__exitChildren();
|
|
92
|
+
return __el2;
|
|
93
|
+
})();
|
|
94
|
+
items.push(item);
|
|
95
|
+
(parent ?? content).appendChild(item);
|
|
96
|
+
return item;
|
|
97
|
+
}, Item = function(value, label) {
|
|
98
|
+
return createItem(value, label);
|
|
99
|
+
}, Group = function(label) {
|
|
100
|
+
const el = (() => {
|
|
101
|
+
const __el3 = __element("div");
|
|
102
|
+
__el3.setAttribute("role", "group");
|
|
103
|
+
{
|
|
104
|
+
const __v = label;
|
|
105
|
+
if (__v != null && __v !== false)
|
|
106
|
+
__el3.setAttribute("aria-label", __v === true ? "" : __v);
|
|
107
|
+
}
|
|
108
|
+
return __el3;
|
|
109
|
+
})();
|
|
110
|
+
content.appendChild(el);
|
|
111
|
+
return {
|
|
112
|
+
el,
|
|
113
|
+
Item: (value, itemLabel) => createItem(value, itemLabel, el)
|
|
114
|
+
};
|
|
115
|
+
}, Separator = function() {
|
|
116
|
+
const hr = (() => {
|
|
117
|
+
const __el4 = __element("hr");
|
|
118
|
+
__el4.setAttribute("role", "separator");
|
|
119
|
+
return __el4;
|
|
120
|
+
})();
|
|
121
|
+
content.appendChild(hr);
|
|
122
|
+
return hr;
|
|
123
|
+
}, Label = function(text) {
|
|
124
|
+
const el = (() => {
|
|
125
|
+
const __el5 = __element("div");
|
|
126
|
+
__el5.setAttribute("role", "none");
|
|
127
|
+
__enterChildren(__el5);
|
|
128
|
+
__insert(__el5, text);
|
|
129
|
+
__exitChildren();
|
|
130
|
+
return __el5;
|
|
131
|
+
})();
|
|
132
|
+
content.appendChild(el);
|
|
133
|
+
return el;
|
|
134
|
+
};
|
|
135
|
+
const { onSelect, positioning, ...attrs } = options;
|
|
136
|
+
const state = {
|
|
137
|
+
open: signal(false),
|
|
138
|
+
activeIndex: signal(-1)
|
|
139
|
+
};
|
|
140
|
+
const items = [];
|
|
141
|
+
let floatingCleanup = null;
|
|
142
|
+
let dismissCleanup = null;
|
|
143
|
+
const trigger = (() => {
|
|
144
|
+
const __el0 = __element("div");
|
|
145
|
+
__on(__el0, "contextmenu", (event) => {
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
if (state.open.peek()) {
|
|
148
|
+
close();
|
|
149
|
+
}
|
|
150
|
+
openMenu(event.clientX, event.clientY);
|
|
151
|
+
});
|
|
152
|
+
return __el0;
|
|
153
|
+
})();
|
|
154
|
+
const contentId = uniqueId("ctx-menu");
|
|
155
|
+
const content = (() => {
|
|
156
|
+
const __el1 = __element("div");
|
|
157
|
+
__el1.setAttribute("role", "menu");
|
|
158
|
+
{
|
|
159
|
+
const __v = contentId;
|
|
160
|
+
if (__v != null && __v !== false)
|
|
161
|
+
__el1.setAttribute("id", __v === true ? "" : __v);
|
|
162
|
+
}
|
|
163
|
+
{
|
|
164
|
+
const __v = { position: "fixed", display: "none" };
|
|
165
|
+
if (__v != null && __v !== false)
|
|
166
|
+
__el1.setAttribute("style", typeof __v === "object" ? __styleStr(__v) : __v === true ? "" : String(__v));
|
|
167
|
+
}
|
|
168
|
+
__el1.setAttribute("aria-hidden", "true");
|
|
169
|
+
__el1.setAttribute("data-state", "closed");
|
|
170
|
+
__on(__el1, "keydown", (event) => {
|
|
171
|
+
if (isKey(event, Keys.Escape)) {
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
close();
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (isKey(event, Keys.Enter, Keys.Space)) {
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
const active = items[state.activeIndex.peek()];
|
|
179
|
+
if (active) {
|
|
180
|
+
const val = active.getAttribute("data-value");
|
|
181
|
+
if (val !== null) {
|
|
182
|
+
onSelect?.(val);
|
|
183
|
+
close();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const result = handleListNavigation(event, items, { orientation: "vertical" });
|
|
189
|
+
if (result) {
|
|
190
|
+
const idx = items.indexOf(result);
|
|
191
|
+
if (idx >= 0) {
|
|
192
|
+
state.activeIndex.value = idx;
|
|
193
|
+
updateActiveItem(idx);
|
|
194
|
+
}
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
|
198
|
+
const char = event.key.toLowerCase();
|
|
199
|
+
const match = items.find((item) => item.textContent?.toLowerCase().startsWith(char));
|
|
200
|
+
if (match) {
|
|
201
|
+
const idx = items.indexOf(match);
|
|
202
|
+
state.activeIndex.value = idx;
|
|
203
|
+
updateActiveItem(idx);
|
|
204
|
+
match.focus();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
return __el1;
|
|
209
|
+
})();
|
|
210
|
+
applyAttrs(trigger, attrs);
|
|
211
|
+
const __mfResult0 = { trigger, content, state, Item, Group, Separator, Label };
|
|
212
|
+
__flushMountFrame();
|
|
213
|
+
return __mfResult0;
|
|
214
|
+
} catch (__mfErr) {
|
|
215
|
+
__discardMountFrame(__mfDepth);
|
|
216
|
+
throw __mfErr;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
var ContextMenu = {
|
|
220
|
+
Root: ContextMenuRoot
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export { ContextMenu };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
uniqueId
|
|
3
|
+
} from "./chunk-8y1jf6xr.js";
|
|
4
|
+
import {
|
|
5
|
+
applyAttrs
|
|
6
|
+
} from "./chunk-2db2dnp3.js";
|
|
7
|
+
|
|
8
|
+
// src/badge/badge.tsx
|
|
9
|
+
import { __discardMountFrame, __element, __flushMountFrame, __pushMountFrame } from "@vertz/ui/internals";
|
|
10
|
+
function BadgeRoot(options = {}) {
|
|
11
|
+
const __mfDepth = __pushMountFrame();
|
|
12
|
+
try {
|
|
13
|
+
const { variant = "default", ...attrs } = options;
|
|
14
|
+
const badge = (() => {
|
|
15
|
+
const __el0 = __element("span");
|
|
16
|
+
{
|
|
17
|
+
const __v = uniqueId("badge");
|
|
18
|
+
if (__v != null && __v !== false)
|
|
19
|
+
__el0.setAttribute("id", __v === true ? "" : __v);
|
|
20
|
+
}
|
|
21
|
+
__el0.setAttribute("data-slot", "badge");
|
|
22
|
+
{
|
|
23
|
+
const __v = variant;
|
|
24
|
+
if (__v != null && __v !== false)
|
|
25
|
+
__el0.setAttribute("data-variant", __v === true ? "" : __v);
|
|
26
|
+
}
|
|
27
|
+
return __el0;
|
|
28
|
+
})();
|
|
29
|
+
applyAttrs(badge, attrs);
|
|
30
|
+
const __mfResult0 = { badge };
|
|
31
|
+
__flushMountFrame();
|
|
32
|
+
return __mfResult0;
|
|
33
|
+
} catch (__mfErr) {
|
|
34
|
+
__discardMountFrame(__mfDepth);
|
|
35
|
+
throw __mfErr;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
var Badge = {
|
|
39
|
+
Root: BadgeRoot
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export { Badge };
|
|
@@ -10,46 +10,66 @@ import {
|
|
|
10
10
|
setDescribedBy,
|
|
11
11
|
setHidden,
|
|
12
12
|
setHiddenAnimated
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-vevfhpc9.js";
|
|
14
14
|
import {
|
|
15
15
|
uniqueId
|
|
16
16
|
} from "./chunk-8y1jf6xr.js";
|
|
17
17
|
import {
|
|
18
18
|
applyAttrs
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-2db2dnp3.js";
|
|
20
20
|
|
|
21
21
|
// src/tooltip/tooltip.tsx
|
|
22
|
-
import { __element, __on } from "@vertz/ui/internals";
|
|
22
|
+
import { __discardMountFrame, __element, __flushMountFrame, __on, __pushMountFrame, __styleStr } from "@vertz/ui/internals";
|
|
23
23
|
import { signal } from "@vertz/ui";
|
|
24
24
|
function TooltipTrigger(show, hide) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
const __mfDepth = __pushMountFrame();
|
|
26
|
+
try {
|
|
27
|
+
const __mfResult0 = (() => {
|
|
28
|
+
const __el0 = __element("span");
|
|
29
|
+
__on(__el0, "mouseenter", show);
|
|
30
|
+
__on(__el0, "mouseleave", hide);
|
|
31
|
+
__on(__el0, "focus", show);
|
|
32
|
+
__on(__el0, "blur", hide);
|
|
33
|
+
__on(__el0, "keydown", (event) => {
|
|
34
|
+
if (isKey(event, Keys.Escape)) {
|
|
35
|
+
hide();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return __el0;
|
|
39
|
+
})();
|
|
40
|
+
__flushMountFrame();
|
|
41
|
+
return __mfResult0;
|
|
42
|
+
} catch (__mfErr) {
|
|
43
|
+
__discardMountFrame(__mfDepth);
|
|
44
|
+
throw __mfErr;
|
|
45
|
+
}
|
|
38
46
|
}
|
|
39
47
|
function TooltipContent(contentId) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
const __mfDepth = __pushMountFrame();
|
|
49
|
+
try {
|
|
50
|
+
const __mfResult0 = (() => {
|
|
51
|
+
const __el0 = __element("div");
|
|
52
|
+
__el0.setAttribute("role", "tooltip");
|
|
53
|
+
{
|
|
54
|
+
const __v = contentId;
|
|
55
|
+
if (__v != null && __v !== false)
|
|
56
|
+
__el0.setAttribute("id", __v === true ? "" : __v);
|
|
57
|
+
}
|
|
58
|
+
__el0.setAttribute("aria-hidden", "true");
|
|
59
|
+
__el0.setAttribute("data-state", "closed");
|
|
60
|
+
{
|
|
61
|
+
const __v = { display: "none" };
|
|
62
|
+
if (__v != null && __v !== false)
|
|
63
|
+
__el0.setAttribute("style", typeof __v === "object" ? __styleStr(__v) : __v === true ? "" : String(__v));
|
|
64
|
+
}
|
|
65
|
+
return __el0;
|
|
66
|
+
})();
|
|
67
|
+
__flushMountFrame();
|
|
68
|
+
return __mfResult0;
|
|
69
|
+
} catch (__mfErr) {
|
|
70
|
+
__discardMountFrame(__mfDepth);
|
|
71
|
+
throw __mfErr;
|
|
72
|
+
}
|
|
53
73
|
}
|
|
54
74
|
function TooltipRoot(options = {}) {
|
|
55
75
|
const { delay = 300, onOpenChange, positioning, ...attrs } = options;
|
|
@@ -0,0 +1,68 @@
|
|
|
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/toggle/toggle.tsx
|
|
13
|
+
import { computed, signal } from "@vertz/ui";
|
|
14
|
+
import { __attr, __discardMountFrame, __element, __flushMountFrame, __on, __pushMountFrame } from "@vertz/ui/internals";
|
|
15
|
+
function ToggleRoot(options = {}) {
|
|
16
|
+
const __mfDepth = __pushMountFrame();
|
|
17
|
+
try {
|
|
18
|
+
let toggle = function() {
|
|
19
|
+
if (disabled)
|
|
20
|
+
return;
|
|
21
|
+
pressed.value = !pressed.value;
|
|
22
|
+
onPressedChange?.(pressed.value);
|
|
23
|
+
};
|
|
24
|
+
const { defaultPressed = false, disabled = false, onPressedChange, ...attrs } = options;
|
|
25
|
+
const pressed = signal(defaultPressed, "pressed");
|
|
26
|
+
const el = computed(() => (() => {
|
|
27
|
+
const __el0 = __element("button");
|
|
28
|
+
__el0.setAttribute("type", "button");
|
|
29
|
+
{
|
|
30
|
+
const __v = uniqueId("toggle");
|
|
31
|
+
if (__v != null && __v !== false)
|
|
32
|
+
__el0.setAttribute("id", __v === true ? "" : __v);
|
|
33
|
+
}
|
|
34
|
+
__attr(__el0, "aria-pressed", () => pressed.value ? "true" : "false");
|
|
35
|
+
__attr(__el0, "data-state", () => pressed.value ? "on" : "off");
|
|
36
|
+
{
|
|
37
|
+
const __v = disabled;
|
|
38
|
+
if (__v != null && __v !== false)
|
|
39
|
+
__el0.setAttribute("disabled", __v === true ? "" : __v);
|
|
40
|
+
}
|
|
41
|
+
{
|
|
42
|
+
const __v = disabled ? "true" : undefined;
|
|
43
|
+
if (__v != null && __v !== false)
|
|
44
|
+
__el0.setAttribute("aria-disabled", __v === true ? "" : __v);
|
|
45
|
+
}
|
|
46
|
+
__on(__el0, "click", toggle);
|
|
47
|
+
__on(__el0, "keydown", (e) => {
|
|
48
|
+
if (isKey(e, Keys.Space)) {
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
toggle();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return __el0;
|
|
54
|
+
})());
|
|
55
|
+
applyAttrs(el.value, attrs);
|
|
56
|
+
const __mfResult0 = el.value;
|
|
57
|
+
__flushMountFrame();
|
|
58
|
+
return __mfResult0;
|
|
59
|
+
} catch (__mfErr) {
|
|
60
|
+
__discardMountFrame(__mfDepth);
|
|
61
|
+
throw __mfErr;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
var Toggle = {
|
|
65
|
+
Root: ToggleRoot
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export { Toggle };
|