@vertz/ui-primitives 0.2.16 → 0.2.17

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 (117) hide show
  1. package/dist/shared/chunk-18y8gfk0.js +308 -0
  2. package/dist/shared/chunk-4085nbdq.js +196 -0
  3. package/dist/shared/chunk-4da5zksy.js +46 -0
  4. package/dist/shared/chunk-7ffg0caj.js +265 -0
  5. package/dist/shared/{chunk-w06tst6x.js → chunk-7kpsyjd7.js} +9 -5
  6. package/dist/shared/chunk-7krvqrwq.js +177 -0
  7. package/dist/shared/chunk-8ak7vdk1.js +151 -0
  8. package/dist/shared/chunk-8nk0ya7a.js +163 -0
  9. package/dist/shared/chunk-8tvzqry6.js +218 -0
  10. package/dist/shared/{chunk-qpfqyrc5.js → chunk-96d9nr7y.js} +1 -1
  11. package/dist/shared/chunk-9hj9p7s2.js +95 -0
  12. package/dist/shared/chunk-avxcmmk6.js +178 -0
  13. package/dist/shared/chunk-bew4bjgf.js +165 -0
  14. package/dist/shared/chunk-dpsgb1xw.js +18 -0
  15. package/dist/shared/chunk-g9qvd20g.js +133 -0
  16. package/dist/shared/chunk-gkddsbmh.js +73 -0
  17. package/dist/shared/chunk-gt0wth9h.js +128 -0
  18. package/dist/shared/chunk-hr9hx58m.js +71 -0
  19. package/dist/shared/{chunk-n92bvn5d.js → chunk-j4cm8avr.js} +85 -59
  20. package/dist/shared/chunk-jz0s6srh.js +161 -0
  21. package/dist/shared/chunk-kg27s15c.js +282 -0
  22. package/dist/shared/chunk-m1ptgp1s.js +142 -0
  23. package/dist/shared/{chunk-9cqe2q6e.js → chunk-n9nwx58j.js} +9 -5
  24. package/dist/shared/chunk-ppcv3ehd.js +85 -0
  25. package/dist/shared/{chunk-vq9tfzh8.js → chunk-rnjm61t0.js} +5 -1
  26. package/dist/shared/chunk-sqs8kyb2.js +288 -0
  27. package/dist/shared/chunk-tfyg0qrp.js +117 -0
  28. package/dist/shared/chunk-ttsyf6ma.js +239 -0
  29. package/dist/shared/chunk-x0we8gcy.js +219 -0
  30. package/dist/shared/{chunk-6pnjrst7.js → chunk-x2hz98qn.js} +2 -2
  31. package/dist/shared/chunk-yr9yzpvq.js +107 -0
  32. package/dist/src/accordion/accordion.d.ts +14 -2
  33. package/dist/src/accordion/accordion.js +2 -1
  34. package/dist/src/badge/badge.d.ts +13 -1
  35. package/dist/src/badge/badge.js +2 -1
  36. package/dist/src/button/button.d.ts +16 -14
  37. package/dist/src/button/button.js +2 -2
  38. package/dist/src/calendar/calendar.d.ts +14 -2
  39. package/dist/src/calendar/calendar.js +2 -1
  40. package/dist/src/carousel/carousel.d.ts +14 -2
  41. package/dist/src/carousel/carousel.js +2 -1
  42. package/dist/src/checkbox/checkbox.d.ts +15 -13
  43. package/dist/src/checkbox/checkbox.js +2 -2
  44. package/dist/src/collapsible/collapsible.d.ts +14 -2
  45. package/dist/src/collapsible/collapsible.js +2 -1
  46. package/dist/src/combobox/combobox.d.ts +14 -2
  47. package/dist/src/combobox/combobox.js +2 -1
  48. package/dist/src/command/command.d.ts +14 -2
  49. package/dist/src/command/command.js +2 -1
  50. package/dist/src/context-menu/context-menu.d.ts +14 -2
  51. package/dist/src/context-menu/context-menu.js +2 -1
  52. package/dist/src/date-picker/date-picker.js +4 -3
  53. package/dist/src/dialog/dialog.d.ts +14 -2
  54. package/dist/src/dialog/dialog.js +2 -1
  55. package/dist/src/dropdown-menu/dropdown-menu.d.ts +13 -1
  56. package/dist/src/dropdown-menu/dropdown-menu.js +3 -2
  57. package/dist/src/hover-card/hover-card.d.ts +14 -2
  58. package/dist/src/hover-card/hover-card.js +2 -1
  59. package/dist/src/index.d.ts +132 -140
  60. package/dist/src/index.js +31 -30
  61. package/dist/src/menu/menu.d.ts +14 -2
  62. package/dist/src/menu/menu.js +2 -1
  63. package/dist/src/menubar/menubar.d.ts +14 -2
  64. package/dist/src/menubar/menubar.js +2 -1
  65. package/dist/src/navigation-menu/navigation-menu.d.ts +14 -2
  66. package/dist/src/navigation-menu/navigation-menu.js +2 -1
  67. package/dist/src/popover/popover.d.ts +14 -2
  68. package/dist/src/popover/popover.js +2 -1
  69. package/dist/src/progress/progress.d.ts +14 -2
  70. package/dist/src/progress/progress.js +2 -1
  71. package/dist/src/radio/radio.d.ts +14 -2
  72. package/dist/src/radio/radio.js +2 -1
  73. package/dist/src/resizable-panel/resizable-panel.d.ts +14 -2
  74. package/dist/src/resizable-panel/resizable-panel.js +2 -1
  75. package/dist/src/scroll-area/scroll-area.d.ts +14 -2
  76. package/dist/src/scroll-area/scroll-area.js +2 -1
  77. package/dist/src/select/select.d.ts +14 -2
  78. package/dist/src/select/select.js +2 -1
  79. package/dist/src/slider/slider.d.ts +14 -2
  80. package/dist/src/slider/slider.js +2 -1
  81. package/dist/src/switch/switch.d.ts +13 -1
  82. package/dist/src/switch/switch.js +2 -1
  83. package/dist/src/tabs/tabs.d.ts +14 -2
  84. package/dist/src/tabs/tabs.js +2 -1
  85. package/dist/src/toast/toast.d.ts +14 -2
  86. package/dist/src/toast/toast.js +2 -1
  87. package/dist/src/toggle/toggle.d.ts +13 -1
  88. package/dist/src/toggle/toggle.js +2 -1
  89. package/dist/src/toggle-group/toggle-group.d.ts +14 -2
  90. package/dist/src/toggle-group/toggle-group.js +2 -1
  91. package/dist/src/tooltip/tooltip.d.ts +14 -2
  92. package/dist/src/tooltip/tooltip.js +2 -1
  93. package/package.json +3 -3
  94. package/dist/shared/chunk-2h5qpc00.js +0 -98
  95. package/dist/shared/chunk-31yptvbf.js +0 -151
  96. package/dist/shared/chunk-3pantb0p.js +0 -108
  97. package/dist/shared/chunk-3s6s6f06.js +0 -61
  98. package/dist/shared/chunk-48v8j0vh.js +0 -267
  99. package/dist/shared/chunk-6dmt4513.js +0 -78
  100. package/dist/shared/chunk-6sqwjfg8.js +0 -169
  101. package/dist/shared/chunk-8qfeqrrz.js +0 -179
  102. package/dist/shared/chunk-bcfzteh0.js +0 -148
  103. package/dist/shared/chunk-cr9sbwns.js +0 -235
  104. package/dist/shared/chunk-cvbf1js1.js +0 -52
  105. package/dist/shared/chunk-dkhst4wv.js +0 -97
  106. package/dist/shared/chunk-e3aj5yw4.js +0 -115
  107. package/dist/shared/chunk-fv1y77tn.js +0 -225
  108. package/dist/shared/chunk-h42bk324.js +0 -58
  109. package/dist/shared/chunk-h9m9x5my.js +0 -119
  110. package/dist/shared/chunk-qq0e0gym.js +0 -73
  111. package/dist/shared/chunk-tk1k1bet.js +0 -93
  112. package/dist/shared/chunk-tvpgeswh.js +0 -216
  113. package/dist/shared/chunk-vcp10kne.js +0 -175
  114. package/dist/shared/chunk-ve006hmy.js +0 -51
  115. package/dist/shared/chunk-vx1ajy2z.js +0 -115
  116. package/dist/shared/chunk-wnttq0gv.js +0 -49
  117. package/dist/shared/chunk-x6qzr3g6.js +0 -100
@@ -1,225 +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-jctqs9m4.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
-
23
- // src/select/select.ts
24
- import { signal } from "@vertz/ui";
25
- var Select = {
26
- Root(options = {}) {
27
- const { defaultValue = "", placeholder = "", onValueChange, positioning } = options;
28
- const ids = linkedIds("select");
29
- const state = {
30
- open: signal(false),
31
- value: signal(defaultValue),
32
- activeIndex: signal(-1)
33
- };
34
- const items = [];
35
- let floatingCleanup = null;
36
- let dismissCleanup = null;
37
- const trigger = document.createElement("button");
38
- trigger.setAttribute("type", "button");
39
- trigger.setAttribute("role", "combobox");
40
- trigger.id = ids.triggerId;
41
- trigger.setAttribute("aria-controls", ids.contentId);
42
- trigger.setAttribute("aria-haspopup", "listbox");
43
- setExpanded(trigger, false);
44
- setDataState(trigger, "closed");
45
- const triggerText = document.createElement("span");
46
- triggerText.setAttribute("data-part", "value");
47
- triggerText.textContent = defaultValue || placeholder;
48
- trigger.appendChild(triggerText);
49
- const content = document.createElement("div");
50
- content.setAttribute("role", "listbox");
51
- content.setAttribute("tabindex", "-1");
52
- content.id = ids.contentId;
53
- setHidden(content, true);
54
- setDataState(content, "closed");
55
- function open() {
56
- state.open.value = true;
57
- setExpanded(trigger, true);
58
- setHidden(content, false);
59
- setDataState(trigger, "open");
60
- setDataState(content, "open");
61
- if (positioning) {
62
- const result = createFloatingPosition(trigger, content, positioning);
63
- floatingCleanup = result.cleanup;
64
- dismissCleanup = createDismiss({
65
- onDismiss: close,
66
- insideElements: [trigger, content],
67
- escapeKey: false
68
- });
69
- } else {
70
- const rect = trigger.getBoundingClientRect();
71
- const side = window.innerHeight - rect.bottom >= rect.top ? "bottom" : "top";
72
- content.setAttribute("data-side", side);
73
- }
74
- const selectedIdx = items.findIndex((item) => item.getAttribute("data-value") === state.value.peek());
75
- if (selectedIdx >= 0) {
76
- state.activeIndex.value = selectedIdx;
77
- updateActiveItem(selectedIdx);
78
- items[selectedIdx]?.focus();
79
- } else {
80
- state.activeIndex.value = -1;
81
- updateActiveItem(-1);
82
- content.focus();
83
- }
84
- }
85
- function close() {
86
- state.open.value = false;
87
- setExpanded(trigger, false);
88
- setDataState(trigger, "closed");
89
- setDataState(content, "closed");
90
- setHiddenAnimated(content, true);
91
- floatingCleanup?.();
92
- floatingCleanup = null;
93
- dismissCleanup?.();
94
- dismissCleanup = null;
95
- trigger.focus();
96
- }
97
- function selectItem(value) {
98
- state.value.value = value;
99
- for (const item of items) {
100
- const isActive = item.getAttribute("data-value") === value;
101
- setSelected(item, isActive);
102
- setDataState(item, isActive ? "active" : "inactive");
103
- if (isActive) {
104
- triggerText.textContent = item.textContent ?? value;
105
- }
106
- }
107
- onValueChange?.(value);
108
- close();
109
- }
110
- function updateActiveItem(index) {
111
- for (let i = 0;i < items.length; i++) {
112
- items[i]?.setAttribute("tabindex", i === index ? "0" : "-1");
113
- }
114
- }
115
- trigger.addEventListener("click", () => {
116
- if (state.open.peek()) {
117
- close();
118
- } else {
119
- open();
120
- }
121
- });
122
- trigger.addEventListener("keydown", (event) => {
123
- if (isKey(event, Keys.ArrowDown, Keys.ArrowUp, Keys.Enter, Keys.Space)) {
124
- event.preventDefault();
125
- if (!state.open.peek()) {
126
- open();
127
- }
128
- }
129
- });
130
- content.addEventListener("keydown", (event) => {
131
- if (isKey(event, Keys.Escape)) {
132
- event.preventDefault();
133
- close();
134
- return;
135
- }
136
- if (isKey(event, Keys.Enter, Keys.Space)) {
137
- event.preventDefault();
138
- const active = items[state.activeIndex.peek()];
139
- if (active) {
140
- const val = active.getAttribute("data-value");
141
- if (val !== null)
142
- selectItem(val);
143
- }
144
- return;
145
- }
146
- if (state.activeIndex.peek() === -1) {
147
- if (isKey(event, Keys.ArrowDown)) {
148
- event.preventDefault();
149
- state.activeIndex.value = 0;
150
- updateActiveItem(0);
151
- items[0]?.focus();
152
- return;
153
- }
154
- if (isKey(event, Keys.ArrowUp)) {
155
- event.preventDefault();
156
- const last = items.length - 1;
157
- state.activeIndex.value = last;
158
- updateActiveItem(last);
159
- items[last]?.focus();
160
- return;
161
- }
162
- }
163
- const result = handleListNavigation(event, items, { orientation: "vertical" });
164
- if (result) {
165
- const idx = items.indexOf(result);
166
- if (idx >= 0) {
167
- state.activeIndex.value = idx;
168
- updateActiveItem(idx);
169
- }
170
- return;
171
- }
172
- if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
173
- const char = event.key.toLowerCase();
174
- const match = items.find((item) => item.textContent?.toLowerCase().startsWith(char));
175
- if (match) {
176
- const idx = items.indexOf(match);
177
- state.activeIndex.value = idx;
178
- updateActiveItem(idx);
179
- match.focus();
180
- }
181
- }
182
- });
183
- function createItem(value, label, parent) {
184
- const item = document.createElement("div");
185
- item.setAttribute("role", "option");
186
- item.setAttribute("data-value", value);
187
- item.setAttribute("tabindex", "-1");
188
- item.textContent = label ?? value;
189
- const isSelected = value === defaultValue;
190
- setSelected(item, isSelected);
191
- setDataState(item, isSelected ? "active" : "inactive");
192
- if (isSelected) {
193
- triggerText.textContent = item.textContent ?? value;
194
- }
195
- item.addEventListener("click", () => {
196
- selectItem(value);
197
- });
198
- items.push(item);
199
- (parent ?? content).appendChild(item);
200
- return item;
201
- }
202
- function Item(value, label) {
203
- return createItem(value, label);
204
- }
205
- function Group(label) {
206
- const el = document.createElement("div");
207
- el.setAttribute("role", "group");
208
- el.setAttribute("aria-label", label);
209
- content.appendChild(el);
210
- return {
211
- el,
212
- Item: (value, itemLabel) => createItem(value, itemLabel, el)
213
- };
214
- }
215
- function Separator() {
216
- const hr = document.createElement("hr");
217
- hr.setAttribute("role", "separator");
218
- content.appendChild(hr);
219
- return hr;
220
- }
221
- return { trigger, content, state, Item, Group, Separator };
222
- }
223
- };
224
-
225
- export { Select };
@@ -1,58 +0,0 @@
1
- import {
2
- Keys,
3
- isKey
4
- } from "./chunk-jctqs9m4.js";
5
- import {
6
- setChecked,
7
- setDataState
8
- } from "./chunk-vvjyx7fe.js";
9
- import {
10
- uniqueId
11
- } from "./chunk-8y1jf6xr.js";
12
-
13
- // src/checkbox/checkbox.ts
14
- import { signal } from "@vertz/ui";
15
- function dataStateFor(checked) {
16
- if (checked === "mixed")
17
- return "indeterminate";
18
- return checked ? "checked" : "unchecked";
19
- }
20
- var Checkbox = {
21
- Root(options = {}) {
22
- const { defaultChecked = false, disabled = false, onCheckedChange } = options;
23
- const state = {
24
- checked: signal(defaultChecked),
25
- disabled: signal(disabled)
26
- };
27
- const root = document.createElement("button");
28
- root.setAttribute("type", "button");
29
- root.setAttribute("role", "checkbox");
30
- root.id = uniqueId("checkbox");
31
- setChecked(root, defaultChecked);
32
- setDataState(root, dataStateFor(defaultChecked));
33
- if (disabled) {
34
- root.disabled = true;
35
- root.setAttribute("aria-disabled", "true");
36
- }
37
- function toggle() {
38
- if (state.disabled.peek())
39
- return;
40
- const current = state.checked.peek();
41
- const next = current === "mixed" ? true : !current;
42
- state.checked.value = next;
43
- setChecked(root, next);
44
- setDataState(root, dataStateFor(next));
45
- onCheckedChange?.(next);
46
- }
47
- root.addEventListener("click", toggle);
48
- root.addEventListener("keydown", (event) => {
49
- if (isKey(event, Keys.Space)) {
50
- event.preventDefault();
51
- toggle();
52
- }
53
- });
54
- return { root, state };
55
- }
56
- };
57
-
58
- export { Checkbox };
@@ -1,119 +0,0 @@
1
- // src/scroll-area/scroll-area.ts
2
- import { signal } from "@vertz/ui";
3
- var ScrollArea = {
4
- Root(options = {}) {
5
- const { orientation = "vertical" } = options;
6
- const state = {
7
- scrollTop: signal(0),
8
- scrollLeft: signal(0)
9
- };
10
- const root = document.createElement("div");
11
- root.style.position = "relative";
12
- root.style.overflow = "hidden";
13
- const viewport = document.createElement("div");
14
- viewport.style.overflow = "scroll";
15
- viewport.style.scrollbarWidth = "none";
16
- const content = document.createElement("div");
17
- const scrollbarY = document.createElement("div");
18
- scrollbarY.setAttribute("aria-hidden", "true");
19
- scrollbarY.setAttribute("data-orientation", "vertical");
20
- const thumbY = document.createElement("div");
21
- scrollbarY.appendChild(thumbY);
22
- const scrollbarX = document.createElement("div");
23
- scrollbarX.setAttribute("aria-hidden", "true");
24
- scrollbarX.setAttribute("data-orientation", "horizontal");
25
- const thumbX = document.createElement("div");
26
- scrollbarX.appendChild(thumbX);
27
- function syncThumbY() {
28
- const { scrollTop, scrollHeight, clientHeight } = viewport;
29
- if (scrollHeight <= clientHeight) {
30
- thumbY.style.height = "0";
31
- return;
32
- }
33
- const ratio = clientHeight / scrollHeight;
34
- thumbY.style.height = `${ratio * 100}%`;
35
- const scrollRatio = scrollTop / (scrollHeight - clientHeight);
36
- thumbY.style.transform = `translateY(${scrollRatio * (1 / ratio - 1) * 100}%)`;
37
- state.scrollTop.value = scrollTop;
38
- }
39
- function syncThumbX() {
40
- const { scrollLeft, scrollWidth, clientWidth } = viewport;
41
- if (scrollWidth <= clientWidth) {
42
- thumbX.style.width = "0";
43
- return;
44
- }
45
- const ratio = clientWidth / scrollWidth;
46
- thumbX.style.width = `${ratio * 100}%`;
47
- const scrollRatio = scrollLeft / (scrollWidth - clientWidth);
48
- thumbX.style.transform = `translateX(${scrollRatio * (1 / ratio - 1) * 100}%)`;
49
- state.scrollLeft.value = scrollLeft;
50
- }
51
- viewport.addEventListener("scroll", () => {
52
- if (orientation === "vertical" || orientation === "both")
53
- syncThumbY();
54
- if (orientation === "horizontal" || orientation === "both")
55
- syncThumbX();
56
- });
57
- let isDraggingY = false;
58
- let startY = 0;
59
- let startScrollTop = 0;
60
- thumbY.addEventListener("pointerdown", (e) => {
61
- isDraggingY = true;
62
- startY = e.clientY;
63
- startScrollTop = viewport.scrollTop;
64
- thumbY.setPointerCapture(e.pointerId);
65
- e.preventDefault();
66
- });
67
- thumbY.addEventListener("pointermove", (e) => {
68
- if (!isDraggingY)
69
- return;
70
- const delta = e.clientY - startY;
71
- const scrollbarHeight = scrollbarY.clientHeight;
72
- const scrollRange = viewport.scrollHeight - viewport.clientHeight;
73
- if (scrollbarHeight > 0) {
74
- viewport.scrollTop = startScrollTop + delta / scrollbarHeight * scrollRange;
75
- }
76
- });
77
- thumbY.addEventListener("pointerup", (e) => {
78
- isDraggingY = false;
79
- thumbY.releasePointerCapture(e.pointerId);
80
- });
81
- let isDraggingX = false;
82
- let startX = 0;
83
- let startScrollLeft = 0;
84
- thumbX.addEventListener("pointerdown", (e) => {
85
- isDraggingX = true;
86
- startX = e.clientX;
87
- startScrollLeft = viewport.scrollLeft;
88
- thumbX.setPointerCapture(e.pointerId);
89
- e.preventDefault();
90
- });
91
- thumbX.addEventListener("pointermove", (e) => {
92
- if (!isDraggingX)
93
- return;
94
- const delta = e.clientX - startX;
95
- const scrollbarWidth = scrollbarX.clientWidth;
96
- const scrollRange = viewport.scrollWidth - viewport.clientWidth;
97
- if (scrollbarWidth > 0) {
98
- viewport.scrollLeft = startScrollLeft + delta / scrollbarWidth * scrollRange;
99
- }
100
- });
101
- thumbX.addEventListener("pointerup", (e) => {
102
- isDraggingX = false;
103
- thumbX.releasePointerCapture(e.pointerId);
104
- });
105
- function update() {
106
- syncThumbY();
107
- syncThumbX();
108
- }
109
- viewport.appendChild(content);
110
- root.appendChild(viewport);
111
- if (orientation === "vertical" || orientation === "both")
112
- root.appendChild(scrollbarY);
113
- if (orientation === "horizontal" || orientation === "both")
114
- root.appendChild(scrollbarX);
115
- return { root, viewport, content, scrollbarY, thumbY, scrollbarX, thumbX, state, update };
116
- }
117
- };
118
-
119
- export { ScrollArea };
@@ -1,73 +0,0 @@
1
- import {
2
- setRovingTabindex
3
- } from "./chunk-e2v1c9ex.js";
4
- import {
5
- handleListNavigation
6
- } from "./chunk-jctqs9m4.js";
7
- import {
8
- setChecked,
9
- setDataState
10
- } from "./chunk-vvjyx7fe.js";
11
- import {
12
- uniqueId
13
- } from "./chunk-8y1jf6xr.js";
14
-
15
- // src/radio/radio.ts
16
- import { signal } from "@vertz/ui";
17
- var Radio = {
18
- Root(options = {}) {
19
- const { defaultValue = "", onValueChange } = options;
20
- const state = { value: signal(defaultValue) };
21
- const items = [];
22
- const itemValues = [];
23
- const root = document.createElement("div");
24
- root.setAttribute("role", "radiogroup");
25
- root.id = uniqueId("radiogroup");
26
- function selectItem(value) {
27
- state.value.value = value;
28
- for (let i = 0;i < items.length; i++) {
29
- const item = items[i];
30
- if (!item)
31
- continue;
32
- const isActive = itemValues[i] === value;
33
- setChecked(item, isActive);
34
- setDataState(item, isActive ? "checked" : "unchecked");
35
- }
36
- setRovingTabindex(items, itemValues.indexOf(value));
37
- onValueChange?.(value);
38
- }
39
- root.addEventListener("keydown", (event) => {
40
- const result = handleListNavigation(event, items, { orientation: "vertical" });
41
- if (result) {
42
- const idx = items.indexOf(result);
43
- if (idx >= 0) {
44
- const val = itemValues[idx];
45
- if (val !== undefined)
46
- selectItem(val);
47
- }
48
- }
49
- });
50
- function Item(value, label) {
51
- const item = document.createElement("div");
52
- item.setAttribute("role", "radio");
53
- item.id = uniqueId("radio");
54
- item.setAttribute("data-value", value);
55
- item.textContent = label ?? value;
56
- const isActive = value === state.value.peek();
57
- setChecked(item, isActive);
58
- setDataState(item, isActive ? "checked" : "unchecked");
59
- item.addEventListener("click", () => {
60
- selectItem(value);
61
- item.focus();
62
- });
63
- items.push(item);
64
- itemValues.push(value);
65
- root.appendChild(item);
66
- setRovingTabindex(items, itemValues.indexOf(state.value.peek()));
67
- return item;
68
- }
69
- return { root, state, Item };
70
- }
71
- };
72
-
73
- export { Radio };
@@ -1,93 +0,0 @@
1
- import {
2
- setRovingTabindex
3
- } from "./chunk-e2v1c9ex.js";
4
- import {
5
- Keys,
6
- handleListNavigation,
7
- isKey
8
- } from "./chunk-jctqs9m4.js";
9
- import {
10
- setDataState,
11
- setPressed
12
- } from "./chunk-vvjyx7fe.js";
13
-
14
- // src/toggle-group/toggle-group.ts
15
- import { signal } from "@vertz/ui";
16
- var ToggleGroup = {
17
- Root(options = {}) {
18
- const {
19
- type = "single",
20
- defaultValue = [],
21
- orientation = "horizontal",
22
- disabled = false,
23
- onValueChange
24
- } = options;
25
- const state = {
26
- value: signal([...defaultValue]),
27
- disabled: signal(disabled)
28
- };
29
- const items = [];
30
- const root = document.createElement("div");
31
- root.setAttribute("role", "group");
32
- root.setAttribute("data-orientation", orientation);
33
- function toggleValue(itemValue) {
34
- if (state.disabled.peek())
35
- return;
36
- const current = [...state.value.peek()];
37
- const idx = current.indexOf(itemValue);
38
- if (type === "single") {
39
- if (idx >= 0) {
40
- current.length = 0;
41
- } else {
42
- current.length = 0;
43
- current.push(itemValue);
44
- }
45
- } else {
46
- if (idx >= 0) {
47
- current.splice(idx, 1);
48
- } else {
49
- current.push(itemValue);
50
- }
51
- }
52
- state.value.value = current;
53
- onValueChange?.(current);
54
- for (const item of items) {
55
- const val = item.getAttribute("data-value") ?? "";
56
- const isOn = current.includes(val);
57
- setPressed(item, isOn);
58
- setDataState(item, isOn ? "on" : "off");
59
- }
60
- }
61
- root.addEventListener("keydown", (event) => {
62
- if (isKey(event, Keys.ArrowLeft, Keys.ArrowRight, Keys.ArrowUp, Keys.ArrowDown, Keys.Home, Keys.End)) {
63
- const result = handleListNavigation(event, items, { orientation });
64
- if (result) {
65
- const idx = items.indexOf(result);
66
- if (idx >= 0) {
67
- setRovingTabindex(items, idx);
68
- }
69
- }
70
- }
71
- });
72
- function Item(value) {
73
- const item = document.createElement("button");
74
- item.setAttribute("type", "button");
75
- item.setAttribute("data-value", value);
76
- const isOn = state.value.peek().includes(value);
77
- setPressed(item, isOn);
78
- setDataState(item, isOn ? "on" : "off");
79
- if (state.disabled.peek()) {
80
- item.disabled = true;
81
- item.setAttribute("aria-disabled", "true");
82
- }
83
- item.addEventListener("click", () => toggleValue(value));
84
- items.push(item);
85
- setRovingTabindex(items, 0);
86
- root.appendChild(item);
87
- return item;
88
- }
89
- return { root, state, Item };
90
- }
91
- };
92
-
93
- export { ToggleGroup };