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