@versini/ui-togglegroup 4.0.0 → 4.0.2

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.
@@ -1,7 +1,656 @@
1
- import "react/jsx-runtime";
2
- import { ToggleGroup as g, ToggleGroupItem as m } from "../../index.js";
3
- import "react";
1
+ import { jsx as f } from "react/jsx-runtime";
2
+ import * as l from "react";
3
+ import b, { useContext as pe } from "react";
4
+ import E from "clsx";
5
+ const ge = "av-togglegroup", me = "av-togglegroup-item-wrapper", ve = "av-togglegroup-item";
6
+ function U(e, t = []) {
7
+ let r = [];
8
+ function o(s, u) {
9
+ const c = l.createContext(u), i = r.length;
10
+ r = [...r, u];
11
+ const a = (d) => {
12
+ var v;
13
+ const { scope: h, children: T, ...p } = d, m = ((v = h == null ? void 0 : h[e]) == null ? void 0 : v[i]) || c, I = l.useMemo(() => p, Object.values(p));
14
+ return /* @__PURE__ */ f(m.Provider, { value: I, children: T });
15
+ };
16
+ a.displayName = s + "Provider";
17
+ function g(d, h) {
18
+ var m;
19
+ const T = ((m = h == null ? void 0 : h[e]) == null ? void 0 : m[i]) || c, p = l.useContext(T);
20
+ if (p) return p;
21
+ if (u !== void 0) return u;
22
+ throw new Error(`\`${d}\` must be used within \`${s}\``);
23
+ }
24
+ return [a, g];
25
+ }
26
+ const n = () => {
27
+ const s = r.map((u) => l.createContext(u));
28
+ return function(c) {
29
+ const i = (c == null ? void 0 : c[e]) || s;
30
+ return l.useMemo(
31
+ () => ({ [`__scope${e}`]: { ...c, [e]: i } }),
32
+ [c, i]
33
+ );
34
+ };
35
+ };
36
+ return n.scopeName = e, [o, Ce(n, ...t)];
37
+ }
38
+ function Ce(...e) {
39
+ const t = e[0];
40
+ if (e.length === 1) return t;
41
+ const r = () => {
42
+ const o = e.map((n) => ({
43
+ useScope: n(),
44
+ scopeName: n.scopeName
45
+ }));
46
+ return function(s) {
47
+ const u = o.reduce((c, { useScope: i, scopeName: a }) => {
48
+ const d = i(s)[`__scope${a}`];
49
+ return { ...c, ...d };
50
+ }, {});
51
+ return l.useMemo(() => ({ [`__scope${t.scopeName}`]: u }), [u]);
52
+ };
53
+ };
54
+ return r.scopeName = t.scopeName, r;
55
+ }
56
+ function j(e, t) {
57
+ if (typeof e == "function")
58
+ return e(t);
59
+ e != null && (e.current = t);
60
+ }
61
+ function z(...e) {
62
+ return (t) => {
63
+ let r = !1;
64
+ const o = e.map((n) => {
65
+ const s = j(n, t);
66
+ return !r && typeof s == "function" && (r = !0), s;
67
+ });
68
+ if (r)
69
+ return () => {
70
+ for (let n = 0; n < o.length; n++) {
71
+ const s = o[n];
72
+ typeof s == "function" ? s() : j(e[n], null);
73
+ }
74
+ };
75
+ };
76
+ }
77
+ function L(...e) {
78
+ return l.useCallback(z(...e), e);
79
+ }
80
+ // @__NO_SIDE_EFFECTS__
81
+ function V(e) {
82
+ const t = /* @__PURE__ */ be(e), r = l.forwardRef((o, n) => {
83
+ const { children: s, ...u } = o, c = l.Children.toArray(s), i = c.find(Ie);
84
+ if (i) {
85
+ const a = i.props.children, g = c.map((d) => d === i ? l.Children.count(a) > 1 ? l.Children.only(null) : l.isValidElement(a) ? a.props.children : null : d);
86
+ return /* @__PURE__ */ f(t, { ...u, ref: n, children: l.isValidElement(a) ? l.cloneElement(a, void 0, g) : null });
87
+ }
88
+ return /* @__PURE__ */ f(t, { ...u, ref: n, children: s });
89
+ });
90
+ return r.displayName = `${e}.Slot`, r;
91
+ }
92
+ // @__NO_SIDE_EFFECTS__
93
+ function be(e) {
94
+ const t = l.forwardRef((r, o) => {
95
+ const { children: n, ...s } = r;
96
+ if (l.isValidElement(n)) {
97
+ const u = Se(n), c = ye(s, n.props);
98
+ return n.type !== l.Fragment && (c.ref = o ? z(o, u) : u), l.cloneElement(n, c);
99
+ }
100
+ return l.Children.count(n) > 1 ? l.Children.only(null) : null;
101
+ });
102
+ return t.displayName = `${e}.SlotClone`, t;
103
+ }
104
+ var he = Symbol("radix.slottable");
105
+ function Ie(e) {
106
+ return l.isValidElement(e) && typeof e.type == "function" && "__radixId" in e.type && e.type.__radixId === he;
107
+ }
108
+ function ye(e, t) {
109
+ const r = { ...t };
110
+ for (const o in t) {
111
+ const n = e[o], s = t[o];
112
+ /^on[A-Z]/.test(o) ? n && s ? r[o] = (...c) => {
113
+ s(...c), n(...c);
114
+ } : n && (r[o] = n) : o === "style" ? r[o] = { ...n, ...s } : o === "className" && (r[o] = [n, s].filter(Boolean).join(" "));
115
+ }
116
+ return { ...e, ...r };
117
+ }
118
+ function Se(e) {
119
+ var o, n;
120
+ let t = (o = Object.getOwnPropertyDescriptor(e.props, "ref")) == null ? void 0 : o.get, r = t && "isReactWarning" in t && t.isReactWarning;
121
+ return r ? e.ref : (t = (n = Object.getOwnPropertyDescriptor(e, "ref")) == null ? void 0 : n.get, r = t && "isReactWarning" in t && t.isReactWarning, r ? e.props.ref : e.props.ref || e.ref);
122
+ }
123
+ var Te = [
124
+ "a",
125
+ "button",
126
+ "div",
127
+ "form",
128
+ "h2",
129
+ "h3",
130
+ "img",
131
+ "input",
132
+ "label",
133
+ "li",
134
+ "nav",
135
+ "ol",
136
+ "p",
137
+ "span",
138
+ "svg",
139
+ "ul"
140
+ ], A = Te.reduce((e, t) => {
141
+ const r = /* @__PURE__ */ V(`Primitive.${t}`), o = l.forwardRef((n, s) => {
142
+ const { asChild: u, ...c } = n, i = u ? r : t;
143
+ return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ f(i, { ...c, ref: s });
144
+ });
145
+ return o.displayName = `Primitive.${t}`, { ...e, [t]: o };
146
+ }, {});
147
+ function x(e, t, { checkForDefaultPrevented: r = !0 } = {}) {
148
+ return function(n) {
149
+ if (e == null || e(n), r === !1 || !n.defaultPrevented)
150
+ return t == null ? void 0 : t(n);
151
+ };
152
+ }
153
+ function Re(e) {
154
+ const t = e + "CollectionProvider", [r, o] = U(t), [n, s] = r(
155
+ t,
156
+ { collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() }
157
+ ), u = (m) => {
158
+ const { scope: I, children: v } = m, C = b.useRef(null), S = b.useRef(/* @__PURE__ */ new Map()).current;
159
+ return /* @__PURE__ */ f(n, { scope: I, itemMap: S, collectionRef: C, children: v });
160
+ };
161
+ u.displayName = t;
162
+ const c = e + "CollectionSlot", i = /* @__PURE__ */ V(c), a = b.forwardRef(
163
+ (m, I) => {
164
+ const { scope: v, children: C } = m, S = s(c, v), R = L(I, S.collectionRef);
165
+ return /* @__PURE__ */ f(i, { ref: R, children: C });
166
+ }
167
+ );
168
+ a.displayName = c;
169
+ const g = e + "CollectionItemSlot", d = "data-radix-collection-item", h = /* @__PURE__ */ V(g), T = b.forwardRef(
170
+ (m, I) => {
171
+ const { scope: v, children: C, ...S } = m, R = b.useRef(null), _ = L(I, R), G = s(g, v);
172
+ return b.useEffect(() => (G.itemMap.set(R, { ref: R, ...S }), () => void G.itemMap.delete(R))), /* @__PURE__ */ f(h, { [d]: "", ref: _, children: C });
173
+ }
174
+ );
175
+ T.displayName = g;
176
+ function p(m) {
177
+ const I = s(e + "CollectionConsumer", m);
178
+ return b.useCallback(() => {
179
+ const C = I.collectionRef.current;
180
+ if (!C) return [];
181
+ const S = Array.from(C.querySelectorAll(`[${d}]`));
182
+ return Array.from(I.itemMap.values()).sort(
183
+ (G, F) => S.indexOf(G.ref.current) - S.indexOf(F.ref.current)
184
+ );
185
+ }, [I.collectionRef, I.itemMap]);
186
+ }
187
+ return [
188
+ { Provider: u, Slot: a, ItemSlot: T },
189
+ p,
190
+ o
191
+ ];
192
+ }
193
+ var Pe = globalThis != null && globalThis.document ? l.useLayoutEffect : () => {
194
+ }, xe = l[" useId ".trim().toString()] || (() => {
195
+ }), _e = 0;
196
+ function Ge(e) {
197
+ const [t, r] = l.useState(xe());
198
+ return Pe(() => {
199
+ r((o) => o ?? String(_e++));
200
+ }, [e]), t ? `radix-${t}` : "";
201
+ }
202
+ function B(e) {
203
+ const t = l.useRef(e);
204
+ return l.useEffect(() => {
205
+ t.current = e;
206
+ }), l.useMemo(() => (...r) => {
207
+ var o;
208
+ return (o = t.current) == null ? void 0 : o.call(t, ...r);
209
+ }, []);
210
+ }
211
+ function N({
212
+ prop: e,
213
+ defaultProp: t,
214
+ onChange: r = () => {
215
+ }
216
+ }) {
217
+ const [o, n] = Ee({ defaultProp: t, onChange: r }), s = e !== void 0, u = s ? e : o, c = B(r), i = l.useCallback(
218
+ (a) => {
219
+ if (s) {
220
+ const d = typeof a == "function" ? a(e) : a;
221
+ d !== e && c(d);
222
+ } else
223
+ n(a);
224
+ },
225
+ [s, e, n, c]
226
+ );
227
+ return [u, i];
228
+ }
229
+ function Ee({
230
+ defaultProp: e,
231
+ onChange: t
232
+ }) {
233
+ const r = l.useState(e), [o] = r, n = l.useRef(o), s = B(t);
234
+ return l.useEffect(() => {
235
+ n.current !== o && (s(o), n.current = o);
236
+ }, [o, n, s]), r;
237
+ }
238
+ var we = l.createContext(void 0);
239
+ function q(e) {
240
+ const t = l.useContext(we);
241
+ return e || t || "ltr";
242
+ }
243
+ var D = "rovingFocusGroup.onEntryFocus", Ae = { bubbles: !1, cancelable: !0 }, M = "RovingFocusGroup", [$, Z, Fe] = Re(M), [ke, J] = U(
244
+ M,
245
+ [Fe]
246
+ ), [Ne, Me] = ke(M), Q = l.forwardRef(
247
+ (e, t) => /* @__PURE__ */ f($.Provider, { scope: e.__scopeRovingFocusGroup, children: /* @__PURE__ */ f($.Slot, { scope: e.__scopeRovingFocusGroup, children: /* @__PURE__ */ f(Oe, { ...e, ref: t }) }) })
248
+ );
249
+ Q.displayName = M;
250
+ var Oe = l.forwardRef((e, t) => {
251
+ const {
252
+ __scopeRovingFocusGroup: r,
253
+ orientation: o,
254
+ loop: n = !1,
255
+ dir: s,
256
+ currentTabStopId: u,
257
+ defaultCurrentTabStopId: c,
258
+ onCurrentTabStopIdChange: i,
259
+ onEntryFocus: a,
260
+ preventScrollOnEntryFocus: g = !1,
261
+ ...d
262
+ } = e, h = l.useRef(null), T = L(t, h), p = q(s), [m = null, I] = N({
263
+ prop: u,
264
+ defaultProp: c,
265
+ onChange: i
266
+ }), [v, C] = l.useState(!1), S = B(a), R = Z(r), _ = l.useRef(!1), [G, F] = l.useState(0);
267
+ return l.useEffect(() => {
268
+ const y = h.current;
269
+ if (y)
270
+ return y.addEventListener(D, S), () => y.removeEventListener(D, S);
271
+ }, [S]), /* @__PURE__ */ f(
272
+ Ne,
273
+ {
274
+ scope: r,
275
+ orientation: o,
276
+ dir: p,
277
+ loop: n,
278
+ currentTabStopId: m,
279
+ onItemFocus: l.useCallback(
280
+ (y) => I(y),
281
+ [I]
282
+ ),
283
+ onItemShiftTab: l.useCallback(() => C(!0), []),
284
+ onFocusableItemAdd: l.useCallback(
285
+ () => F((y) => y + 1),
286
+ []
287
+ ),
288
+ onFocusableItemRemove: l.useCallback(
289
+ () => F((y) => y - 1),
290
+ []
291
+ ),
292
+ children: /* @__PURE__ */ f(
293
+ A.div,
294
+ {
295
+ tabIndex: v || G === 0 ? -1 : 0,
296
+ "data-orientation": o,
297
+ ...d,
298
+ ref: T,
299
+ style: { outline: "none", ...e.style },
300
+ onMouseDown: x(e.onMouseDown, () => {
301
+ _.current = !0;
302
+ }),
303
+ onFocus: x(e.onFocus, (y) => {
304
+ const ae = !_.current;
305
+ if (y.target === y.currentTarget && ae && !v) {
306
+ const W = new CustomEvent(D, Ae);
307
+ if (y.currentTarget.dispatchEvent(W), !W.defaultPrevented) {
308
+ const O = R().filter((P) => P.focusable), ie = O.find((P) => P.active), fe = O.find((P) => P.id === m), de = [ie, fe, ...O].filter(
309
+ Boolean
310
+ ).map((P) => P.ref.current);
311
+ ee(de, g);
312
+ }
313
+ }
314
+ _.current = !1;
315
+ }),
316
+ onBlur: x(e.onBlur, () => C(!1))
317
+ }
318
+ )
319
+ }
320
+ );
321
+ }), X = "RovingFocusGroupItem", H = l.forwardRef(
322
+ (e, t) => {
323
+ const {
324
+ __scopeRovingFocusGroup: r,
325
+ focusable: o = !0,
326
+ active: n = !1,
327
+ tabStopId: s,
328
+ ...u
329
+ } = e, c = Ge(), i = s || c, a = Me(X, r), g = a.currentTabStopId === i, d = Z(r), { onFocusableItemAdd: h, onFocusableItemRemove: T } = a;
330
+ return l.useEffect(() => {
331
+ if (o)
332
+ return h(), () => T();
333
+ }, [o, h, T]), /* @__PURE__ */ f(
334
+ $.ItemSlot,
335
+ {
336
+ scope: r,
337
+ id: i,
338
+ focusable: o,
339
+ active: n,
340
+ children: /* @__PURE__ */ f(
341
+ A.span,
342
+ {
343
+ tabIndex: g ? 0 : -1,
344
+ "data-orientation": a.orientation,
345
+ ...u,
346
+ ref: t,
347
+ onMouseDown: x(e.onMouseDown, (p) => {
348
+ o ? a.onItemFocus(i) : p.preventDefault();
349
+ }),
350
+ onFocus: x(e.onFocus, () => a.onItemFocus(i)),
351
+ onKeyDown: x(e.onKeyDown, (p) => {
352
+ if (p.key === "Tab" && p.shiftKey) {
353
+ a.onItemShiftTab();
354
+ return;
355
+ }
356
+ if (p.target !== p.currentTarget) return;
357
+ const m = Ve(p, a.orientation, a.dir);
358
+ if (m !== void 0) {
359
+ if (p.metaKey || p.ctrlKey || p.altKey || p.shiftKey) return;
360
+ p.preventDefault();
361
+ let v = d().filter((C) => C.focusable).map((C) => C.ref.current);
362
+ if (m === "last") v.reverse();
363
+ else if (m === "prev" || m === "next") {
364
+ m === "prev" && v.reverse();
365
+ const C = v.indexOf(p.currentTarget);
366
+ v = a.loop ? $e(v, C + 1) : v.slice(C + 1);
367
+ }
368
+ setTimeout(() => ee(v));
369
+ }
370
+ })
371
+ }
372
+ )
373
+ }
374
+ );
375
+ }
376
+ );
377
+ H.displayName = X;
378
+ var De = {
379
+ ArrowLeft: "prev",
380
+ ArrowUp: "prev",
381
+ ArrowRight: "next",
382
+ ArrowDown: "next",
383
+ PageUp: "first",
384
+ Home: "first",
385
+ PageDown: "last",
386
+ End: "last"
387
+ };
388
+ function Le(e, t) {
389
+ return t !== "rtl" ? e : e === "ArrowLeft" ? "ArrowRight" : e === "ArrowRight" ? "ArrowLeft" : e;
390
+ }
391
+ function Ve(e, t, r) {
392
+ const o = Le(e.key, r);
393
+ if (!(t === "vertical" && ["ArrowLeft", "ArrowRight"].includes(o)) && !(t === "horizontal" && ["ArrowUp", "ArrowDown"].includes(o)))
394
+ return De[o];
395
+ }
396
+ function ee(e, t = !1) {
397
+ const r = document.activeElement;
398
+ for (const o of e)
399
+ if (o === r || (o.focus({ preventScroll: t }), document.activeElement !== r)) return;
400
+ }
401
+ function $e(e, t) {
402
+ return e.map((r, o) => e[(t + o) % e.length]);
403
+ }
404
+ var Ue = Q, Be = H, Ke = "Toggle", te = l.forwardRef((e, t) => {
405
+ const { pressed: r, defaultPressed: o = !1, onPressedChange: n, ...s } = e, [u = !1, c] = N({
406
+ prop: r,
407
+ onChange: n,
408
+ defaultProp: o
409
+ });
410
+ return /* @__PURE__ */ f(
411
+ A.button,
412
+ {
413
+ type: "button",
414
+ "aria-pressed": u,
415
+ "data-state": u ? "on" : "off",
416
+ "data-disabled": e.disabled ? "" : void 0,
417
+ ...s,
418
+ ref: t,
419
+ onClick: x(e.onClick, () => {
420
+ e.disabled || c(!u);
421
+ })
422
+ }
423
+ );
424
+ });
425
+ te.displayName = Ke;
426
+ var w = "ToggleGroup", [oe, ct] = U(w, [
427
+ J
428
+ ]), re = J(), K = b.forwardRef((e, t) => {
429
+ const { type: r, ...o } = e;
430
+ if (r === "single")
431
+ return /* @__PURE__ */ f(We, { ...o, ref: t });
432
+ if (r === "multiple")
433
+ return /* @__PURE__ */ f(je, { ...o, ref: t });
434
+ throw new Error(`Missing prop \`type\` expected on \`${w}\``);
435
+ });
436
+ K.displayName = w;
437
+ var [ne, se] = oe(w), We = b.forwardRef((e, t) => {
438
+ const {
439
+ value: r,
440
+ defaultValue: o,
441
+ onValueChange: n = () => {
442
+ },
443
+ ...s
444
+ } = e, [u, c] = N({
445
+ prop: r,
446
+ defaultProp: o,
447
+ onChange: n
448
+ });
449
+ return /* @__PURE__ */ f(
450
+ ne,
451
+ {
452
+ scope: e.__scopeToggleGroup,
453
+ type: "single",
454
+ value: u ? [u] : [],
455
+ onItemActivate: c,
456
+ onItemDeactivate: b.useCallback(() => c(""), [c]),
457
+ children: /* @__PURE__ */ f(ce, { ...s, ref: t })
458
+ }
459
+ );
460
+ }), je = b.forwardRef((e, t) => {
461
+ const {
462
+ value: r,
463
+ defaultValue: o,
464
+ onValueChange: n = () => {
465
+ },
466
+ ...s
467
+ } = e, [u = [], c] = N({
468
+ prop: r,
469
+ defaultProp: o,
470
+ onChange: n
471
+ }), i = b.useCallback(
472
+ (g) => c((d = []) => [...d, g]),
473
+ [c]
474
+ ), a = b.useCallback(
475
+ (g) => c((d = []) => d.filter((h) => h !== g)),
476
+ [c]
477
+ );
478
+ return /* @__PURE__ */ f(
479
+ ne,
480
+ {
481
+ scope: e.__scopeToggleGroup,
482
+ type: "multiple",
483
+ value: u,
484
+ onItemActivate: i,
485
+ onItemDeactivate: a,
486
+ children: /* @__PURE__ */ f(ce, { ...s, ref: t })
487
+ }
488
+ );
489
+ });
490
+ K.displayName = w;
491
+ var [Ye, ze] = oe(w), ce = b.forwardRef(
492
+ (e, t) => {
493
+ const {
494
+ __scopeToggleGroup: r,
495
+ disabled: o = !1,
496
+ rovingFocus: n = !0,
497
+ orientation: s,
498
+ dir: u,
499
+ loop: c = !0,
500
+ ...i
501
+ } = e, a = re(r), g = q(u), d = { role: "group", dir: g, ...i };
502
+ return /* @__PURE__ */ f(Ye, { scope: r, rovingFocus: n, disabled: o, children: n ? /* @__PURE__ */ f(
503
+ Ue,
504
+ {
505
+ asChild: !0,
506
+ ...a,
507
+ orientation: s,
508
+ dir: g,
509
+ loop: c,
510
+ children: /* @__PURE__ */ f(A.div, { ...d, ref: t })
511
+ }
512
+ ) : /* @__PURE__ */ f(A.div, { ...d, ref: t }) });
513
+ }
514
+ ), k = "ToggleGroupItem", ue = b.forwardRef(
515
+ (e, t) => {
516
+ const r = se(k, e.__scopeToggleGroup), o = ze(k, e.__scopeToggleGroup), n = re(e.__scopeToggleGroup), s = r.value.includes(e.value), u = o.disabled || e.disabled, c = { ...e, pressed: s, disabled: u }, i = b.useRef(null);
517
+ return o.rovingFocus ? /* @__PURE__ */ f(
518
+ Be,
519
+ {
520
+ asChild: !0,
521
+ ...n,
522
+ focusable: !u,
523
+ active: s,
524
+ ref: i,
525
+ children: /* @__PURE__ */ f(Y, { ...c, ref: t })
526
+ }
527
+ ) : /* @__PURE__ */ f(Y, { ...c, ref: t });
528
+ }
529
+ );
530
+ ue.displayName = k;
531
+ var Y = b.forwardRef(
532
+ (e, t) => {
533
+ const { __scopeToggleGroup: r, value: o, ...n } = e, s = se(k, r), u = { role: "radio", "aria-checked": e.pressed, "aria-pressed": void 0 }, c = s.type === "single" ? u : void 0;
534
+ return /* @__PURE__ */ f(
535
+ te,
536
+ {
537
+ ...c,
538
+ ...n,
539
+ ref: t,
540
+ onPressedChange: (i) => {
541
+ i ? s.onItemActivate(o) : s.onItemDeactivate(o);
542
+ }
543
+ }
544
+ );
545
+ }
546
+ ), qe = K, Ze = ue;
547
+ const le = b.createContext({
548
+ size: "medium",
549
+ focusMode: "system",
550
+ mode: "system"
551
+ }), Je = ({ focusMode: e }) => E("focus:outline", "focus:outline-2", "focus:outline-offset", {
552
+ "focus:outline-focus-light": e === "light",
553
+ "focus:outline-focus-dark": e === "dark",
554
+ "focus:outline-focus-light dark:focus:outline-focus-dark": e === "alt-system",
555
+ "focus:outline-focus-dark dark:focus:outline-focus-light": e === "system"
556
+ }), Qe = ({ mode: e }) => E({
557
+ "data-[state=on]:bg-surface-medium": e === "dark",
558
+ "data-[state=on]:bg-surface-lightest": e === "light",
559
+ "data-[state=on]:bg-surface-lightest dark:data-[state=on]:bg-surface-medium": e === "system",
560
+ "data-[state=on]:bg-surface-medium dark:data-[state=on]:bg-surface-lightest": e === "alt-system"
561
+ }), Xe = ({ size: e }) => E({
562
+ "h-5 px-2": e === "small",
563
+ "h-6 px-3": e === "medium",
564
+ "h-7 px-4": e === "large"
565
+ }), He = ({ mode: e }) => E(
566
+ me,
567
+ "px-1",
568
+ "relative",
569
+ "border-r",
570
+ "last:border-transparent",
571
+ "has-[button[aria-checked='true']]:border-transparent",
572
+ "has-[+_*_button[aria-checked='false']]:border-border-medium",
573
+ {
574
+ "border-surface-light": e === "light",
575
+ "border-surface-darker": e === "dark",
576
+ "border-surface-light dark:border-surface-darker": e === "system",
577
+ "border-surface-darker dark:border-surface-light": e === "alt-system"
578
+ }
579
+ ), et = ({
580
+ focusMode: e,
581
+ mode: t,
582
+ size: r
583
+ }) => ({
584
+ wrapperClass: He({ mode: t }),
585
+ itemClass: E(
586
+ ve,
587
+ "flex items-center justify-center bg-transparent",
588
+ "rounded-xs",
589
+ "transition duration-200 ease",
590
+ Xe({ size: r }),
591
+ Je({ focusMode: e }),
592
+ Qe({ mode: t })
593
+ )
594
+ }), tt = ({
595
+ mode: e,
596
+ className: t
597
+ }) => E(
598
+ ge,
599
+ "inline-flex p-1",
600
+ "rounded-xs",
601
+ {
602
+ "bg-surface-light text-copy-dark": e === "light",
603
+ "bg-surface-darker text-copy-lighter": e === "dark",
604
+ "bg-surface-light text-copy-dark dark:bg-surface-darker dark:text-copy-lighter": e === "system",
605
+ "bg-surface-darker text-copy-lighter dark:bg-surface-light dark:text-copy-dark": e === "alt-system"
606
+ },
607
+ t
608
+ ), ut = ({
609
+ children: e,
610
+ value: t,
611
+ onValueChange: r,
612
+ disabled: o,
613
+ mode: n = "system",
614
+ focusMode: s = "system",
615
+ size: u = "medium",
616
+ defaultValue: c,
617
+ className: i,
618
+ ...a
619
+ }) => {
620
+ const g = tt({ mode: n, className: i }), d = { size: u, focusMode: s, mode: n };
621
+ return /* @__PURE__ */ f(le.Provider, { value: d, children: /* @__PURE__ */ f(
622
+ qe,
623
+ {
624
+ disabled: o,
625
+ className: g,
626
+ value: t,
627
+ defaultValue: c,
628
+ onValueChange: r,
629
+ ...a,
630
+ type: "single",
631
+ children: e
632
+ }
633
+ ) });
634
+ }, lt = ({ value: e, disabled: t }) => {
635
+ const { size: r, focusMode: o, mode: n } = pe(le), { itemClass: s, wrapperClass: u } = et({
636
+ focusMode: o,
637
+ mode: n,
638
+ size: r
639
+ });
640
+ return /* @__PURE__ */ f("div", { className: u, children: /* @__PURE__ */ f(
641
+ Ze,
642
+ {
643
+ disabled: t,
644
+ className: s,
645
+ value: e,
646
+ children: e
647
+ }
648
+ ) });
649
+ };
4
650
  export {
5
- g as ToggleGroup,
6
- m as ToggleGroupItem
651
+ ge as TOGGLEGROUP_CLASSNAME,
652
+ ve as TOGGLEGROUP_ITEM_CLASSNAME,
653
+ me as TOGGLEGROUP_ITEM_WRAPPER_CLASSNAME,
654
+ ut as ToggleGroup,
655
+ lt as ToggleGroupItem
7
656
  };
package/dist/index.js CHANGED
@@ -1,663 +1,21 @@
1
- import { jsx as l, Fragment as ge } from "react/jsx-runtime";
2
- import * as u from "react";
3
- import C, { useContext as me } from "react";
4
- import P from "clsx";
1
+ import { TOGGLEGROUP_CLASSNAME as E, TOGGLEGROUP_ITEM_CLASSNAME as e, TOGGLEGROUP_ITEM_WRAPPER_CLASSNAME as T, ToggleGroup as i, ToggleGroupItem as r } from "./components/ToggleGroup/ToggleGroup.js";
5
2
  /*!
6
- @versini/ui-togglegroup v4.0.0
3
+ @versini/ui-togglegroup v4.0.2
7
4
  © 2025 gizmette.com
8
5
  */
9
6
  try {
10
7
  window.__VERSINI_UI_TOGGLEGROUP__ || (window.__VERSINI_UI_TOGGLEGROUP__ = {
11
- version: "4.0.0",
12
- buildTime: "03/18/2025 07:53 PM EDT",
8
+ version: "4.0.2",
9
+ buildTime: "04/12/2025 09:18 AM EDT",
13
10
  homepage: "https://github.com/aversini/ui-components",
14
11
  license: "MIT"
15
12
  });
16
13
  } catch {
17
14
  }
18
- const ve = "av-togglegroup", Ce = "av-togglegroup-item-wrapper", he = "av-togglegroup-item";
19
- function U(e, t = []) {
20
- let o = [];
21
- function r(s, c) {
22
- const a = u.createContext(c), i = o.length;
23
- o = [...o, c];
24
- const d = (p) => {
25
- var g;
26
- const { scope: h, children: I, ...f } = p, m = ((g = h == null ? void 0 : h[e]) == null ? void 0 : g[i]) || a, T = u.useMemo(() => f, Object.values(f));
27
- return /* @__PURE__ */ l(m.Provider, { value: T, children: I });
28
- };
29
- d.displayName = s + "Provider";
30
- function v(p, h) {
31
- var m;
32
- const I = ((m = h == null ? void 0 : h[e]) == null ? void 0 : m[i]) || a, f = u.useContext(I);
33
- if (f) return f;
34
- if (c !== void 0) return c;
35
- throw new Error(`\`${p}\` must be used within \`${s}\``);
36
- }
37
- return [d, v];
38
- }
39
- const n = () => {
40
- const s = o.map((c) => u.createContext(c));
41
- return function(a) {
42
- const i = (a == null ? void 0 : a[e]) || s;
43
- return u.useMemo(
44
- () => ({ [`__scope${e}`]: { ...a, [e]: i } }),
45
- [a, i]
46
- );
47
- };
48
- };
49
- return n.scopeName = e, [r, be(n, ...t)];
50
- }
51
- function be(...e) {
52
- const t = e[0];
53
- if (e.length === 1) return t;
54
- const o = () => {
55
- const r = e.map((n) => ({
56
- useScope: n(),
57
- scopeName: n.scopeName
58
- }));
59
- return function(s) {
60
- const c = r.reduce((a, { useScope: i, scopeName: d }) => {
61
- const p = i(s)[`__scope${d}`];
62
- return { ...a, ...p };
63
- }, {});
64
- return u.useMemo(() => ({ [`__scope${t.scopeName}`]: c }), [c]);
65
- };
66
- };
67
- return o.scopeName = t.scopeName, o;
68
- }
69
- function j(e, t) {
70
- if (typeof e == "function")
71
- return e(t);
72
- e != null && (e.current = t);
73
- }
74
- function z(...e) {
75
- return (t) => {
76
- let o = !1;
77
- const r = e.map((n) => {
78
- const s = j(n, t);
79
- return !o && typeof s == "function" && (o = !0), s;
80
- });
81
- if (o)
82
- return () => {
83
- for (let n = 0; n < r.length; n++) {
84
- const s = r[n];
85
- typeof s == "function" ? s() : j(e[n], null);
86
- }
87
- };
88
- };
89
- }
90
- function D(...e) {
91
- return u.useCallback(z(...e), e);
92
- }
93
- var A = u.forwardRef((e, t) => {
94
- const { children: o, ...r } = e, n = u.Children.toArray(o), s = n.find(Te);
95
- if (s) {
96
- const c = s.props.children, a = n.map((i) => i === s ? u.Children.count(c) > 1 ? u.Children.only(null) : u.isValidElement(c) ? c.props.children : null : i);
97
- return /* @__PURE__ */ l(L, { ...r, ref: t, children: u.isValidElement(c) ? u.cloneElement(c, void 0, a) : null });
98
- }
99
- return /* @__PURE__ */ l(L, { ...r, ref: t, children: o });
100
- });
101
- A.displayName = "Slot";
102
- var L = u.forwardRef((e, t) => {
103
- const { children: o, ...r } = e;
104
- if (u.isValidElement(o)) {
105
- const n = ye(o), s = Re(r, o.props);
106
- return o.type !== u.Fragment && (s.ref = t ? z(t, n) : n), u.cloneElement(o, s);
107
- }
108
- return u.Children.count(o) > 1 ? u.Children.only(null) : null;
109
- });
110
- L.displayName = "SlotClone";
111
- var Ie = ({ children: e }) => /* @__PURE__ */ l(ge, { children: e });
112
- function Te(e) {
113
- return u.isValidElement(e) && e.type === Ie;
114
- }
115
- function Re(e, t) {
116
- const o = { ...t };
117
- for (const r in t) {
118
- const n = e[r], s = t[r];
119
- /^on[A-Z]/.test(r) ? n && s ? o[r] = (...a) => {
120
- s(...a), n(...a);
121
- } : n && (o[r] = n) : r === "style" ? o[r] = { ...n, ...s } : r === "className" && (o[r] = [n, s].filter(Boolean).join(" "));
122
- }
123
- return { ...e, ...o };
124
- }
125
- function ye(e) {
126
- var r, n;
127
- let t = (r = Object.getOwnPropertyDescriptor(e.props, "ref")) == null ? void 0 : r.get, o = t && "isReactWarning" in t && t.isReactWarning;
128
- return o ? e.ref : (t = (n = Object.getOwnPropertyDescriptor(e, "ref")) == null ? void 0 : n.get, o = t && "isReactWarning" in t && t.isReactWarning, o ? e.props.ref : e.props.ref || e.ref);
129
- }
130
- var Se = [
131
- "a",
132
- "button",
133
- "div",
134
- "form",
135
- "h2",
136
- "h3",
137
- "img",
138
- "input",
139
- "label",
140
- "li",
141
- "nav",
142
- "ol",
143
- "p",
144
- "span",
145
- "svg",
146
- "ul"
147
- ], w = Se.reduce((e, t) => {
148
- const o = u.forwardRef((r, n) => {
149
- const { asChild: s, ...c } = r, a = s ? A : t;
150
- return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ l(a, { ...c, ref: n });
151
- });
152
- return o.displayName = `Primitive.${t}`, { ...e, [t]: o };
153
- }, {});
154
- function S(e, t, { checkForDefaultPrevented: o = !0 } = {}) {
155
- return function(n) {
156
- if (e == null || e(n), o === !1 || !n.defaultPrevented)
157
- return t == null ? void 0 : t(n);
158
- };
159
- }
160
- function _e(e) {
161
- const t = e + "CollectionProvider", [o, r] = U(t), [n, s] = o(
162
- t,
163
- { collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() }
164
- ), c = (I) => {
165
- const { scope: f, children: m } = I, T = C.useRef(null), g = C.useRef(/* @__PURE__ */ new Map()).current;
166
- return /* @__PURE__ */ l(n, { scope: f, itemMap: g, collectionRef: T, children: m });
167
- };
168
- c.displayName = t;
169
- const a = e + "CollectionSlot", i = C.forwardRef(
170
- (I, f) => {
171
- const { scope: m, children: T } = I, g = s(a, m), b = D(f, g.collectionRef);
172
- return /* @__PURE__ */ l(A, { ref: b, children: T });
173
- }
174
- );
175
- i.displayName = a;
176
- const d = e + "CollectionItemSlot", v = "data-radix-collection-item", p = C.forwardRef(
177
- (I, f) => {
178
- const { scope: m, children: T, ...g } = I, b = C.useRef(null), _ = D(f, b), G = s(d, m);
179
- return C.useEffect(() => (G.itemMap.set(b, { ref: b, ...g }), () => void G.itemMap.delete(b))), /* @__PURE__ */ l(A, { [v]: "", ref: _, children: T });
180
- }
181
- );
182
- p.displayName = d;
183
- function h(I) {
184
- const f = s(e + "CollectionConsumer", I);
185
- return C.useCallback(() => {
186
- const T = f.collectionRef.current;
187
- if (!T) return [];
188
- const g = Array.from(T.querySelectorAll(`[${v}]`));
189
- return Array.from(f.itemMap.values()).sort(
190
- (G, E) => g.indexOf(G.ref.current) - g.indexOf(E.ref.current)
191
- );
192
- }, [f.collectionRef, f.itemMap]);
193
- }
194
- return [
195
- { Provider: c, Slot: i, ItemSlot: p },
196
- h,
197
- r
198
- ];
199
- }
200
- var Ge = globalThis != null && globalThis.document ? u.useLayoutEffect : () => {
201
- }, Pe = u.useId || (() => {
202
- }), xe = 0;
203
- function Ee(e) {
204
- const [t, o] = u.useState(Pe());
205
- return Ge(() => {
206
- o((r) => r ?? String(xe++));
207
- }, [e]), t ? `radix-${t}` : "";
208
- }
209
- function $(e) {
210
- const t = u.useRef(e);
211
- return u.useEffect(() => {
212
- t.current = e;
213
- }), u.useMemo(() => (...o) => {
214
- var r;
215
- return (r = t.current) == null ? void 0 : r.call(t, ...o);
216
- }, []);
217
- }
218
- function k({
219
- prop: e,
220
- defaultProp: t,
221
- onChange: o = () => {
222
- }
223
- }) {
224
- const [r, n] = we({ defaultProp: t, onChange: o }), s = e !== void 0, c = s ? e : r, a = $(o), i = u.useCallback(
225
- (d) => {
226
- if (s) {
227
- const p = typeof d == "function" ? d(e) : d;
228
- p !== e && a(p);
229
- } else
230
- n(d);
231
- },
232
- [s, e, n, a]
233
- );
234
- return [c, i];
235
- }
236
- function we({
237
- defaultProp: e,
238
- onChange: t
239
- }) {
240
- const o = u.useState(e), [r] = o, n = u.useRef(r), s = $(t);
241
- return u.useEffect(() => {
242
- n.current !== r && (s(r), n.current = r);
243
- }, [r, n, s]), o;
244
- }
245
- var Ae = u.createContext(void 0);
246
- function q(e) {
247
- const t = u.useContext(Ae);
248
- return e || t || "ltr";
249
- }
250
- var O = "rovingFocusGroup.onEntryFocus", Fe = { bubbles: !1, cancelable: !0 }, N = "RovingFocusGroup", [V, Z, ke] = _e(N), [Ne, J] = U(
251
- N,
252
- [ke]
253
- ), [Me, Oe] = Ne(N), Q = u.forwardRef(
254
- (e, t) => /* @__PURE__ */ l(V.Provider, { scope: e.__scopeRovingFocusGroup, children: /* @__PURE__ */ l(V.Slot, { scope: e.__scopeRovingFocusGroup, children: /* @__PURE__ */ l(De, { ...e, ref: t }) }) })
255
- );
256
- Q.displayName = N;
257
- var De = u.forwardRef((e, t) => {
258
- const {
259
- __scopeRovingFocusGroup: o,
260
- orientation: r,
261
- loop: n = !1,
262
- dir: s,
263
- currentTabStopId: c,
264
- defaultCurrentTabStopId: a,
265
- onCurrentTabStopIdChange: i,
266
- onEntryFocus: d,
267
- preventScrollOnEntryFocus: v = !1,
268
- ...p
269
- } = e, h = u.useRef(null), I = D(t, h), f = q(s), [m = null, T] = k({
270
- prop: c,
271
- defaultProp: a,
272
- onChange: i
273
- }), [g, b] = u.useState(!1), _ = $(d), G = Z(o), E = u.useRef(!1), [le, K] = u.useState(0);
274
- return u.useEffect(() => {
275
- const R = h.current;
276
- if (R)
277
- return R.addEventListener(O, _), () => R.removeEventListener(O, _);
278
- }, [_]), /* @__PURE__ */ l(
279
- Me,
280
- {
281
- scope: o,
282
- orientation: r,
283
- dir: f,
284
- loop: n,
285
- currentTabStopId: m,
286
- onItemFocus: u.useCallback(
287
- (R) => T(R),
288
- [T]
289
- ),
290
- onItemShiftTab: u.useCallback(() => b(!0), []),
291
- onFocusableItemAdd: u.useCallback(
292
- () => K((R) => R + 1),
293
- []
294
- ),
295
- onFocusableItemRemove: u.useCallback(
296
- () => K((R) => R - 1),
297
- []
298
- ),
299
- children: /* @__PURE__ */ l(
300
- w.div,
301
- {
302
- tabIndex: g || le === 0 ? -1 : 0,
303
- "data-orientation": r,
304
- ...p,
305
- ref: I,
306
- style: { outline: "none", ...e.style },
307
- onMouseDown: S(e.onMouseDown, () => {
308
- E.current = !0;
309
- }),
310
- onFocus: S(e.onFocus, (R) => {
311
- const ie = !E.current;
312
- if (R.target === R.currentTarget && ie && !g) {
313
- const W = new CustomEvent(O, Fe);
314
- if (R.currentTarget.dispatchEvent(W), !W.defaultPrevented) {
315
- const M = G().filter((y) => y.focusable), fe = M.find((y) => y.active), de = M.find((y) => y.id === m), pe = [fe, de, ...M].filter(
316
- Boolean
317
- ).map((y) => y.ref.current);
318
- ee(pe, v);
319
- }
320
- }
321
- E.current = !1;
322
- }),
323
- onBlur: S(e.onBlur, () => b(!1))
324
- }
325
- )
326
- }
327
- );
328
- }), X = "RovingFocusGroupItem", H = u.forwardRef(
329
- (e, t) => {
330
- const {
331
- __scopeRovingFocusGroup: o,
332
- focusable: r = !0,
333
- active: n = !1,
334
- tabStopId: s,
335
- ...c
336
- } = e, a = Ee(), i = s || a, d = Oe(X, o), v = d.currentTabStopId === i, p = Z(o), { onFocusableItemAdd: h, onFocusableItemRemove: I } = d;
337
- return u.useEffect(() => {
338
- if (r)
339
- return h(), () => I();
340
- }, [r, h, I]), /* @__PURE__ */ l(
341
- V.ItemSlot,
342
- {
343
- scope: o,
344
- id: i,
345
- focusable: r,
346
- active: n,
347
- children: /* @__PURE__ */ l(
348
- w.span,
349
- {
350
- tabIndex: v ? 0 : -1,
351
- "data-orientation": d.orientation,
352
- ...c,
353
- ref: t,
354
- onMouseDown: S(e.onMouseDown, (f) => {
355
- r ? d.onItemFocus(i) : f.preventDefault();
356
- }),
357
- onFocus: S(e.onFocus, () => d.onItemFocus(i)),
358
- onKeyDown: S(e.onKeyDown, (f) => {
359
- if (f.key === "Tab" && f.shiftKey) {
360
- d.onItemShiftTab();
361
- return;
362
- }
363
- if (f.target !== f.currentTarget) return;
364
- const m = Ue(f, d.orientation, d.dir);
365
- if (m !== void 0) {
366
- if (f.metaKey || f.ctrlKey || f.altKey || f.shiftKey) return;
367
- f.preventDefault();
368
- let g = p().filter((b) => b.focusable).map((b) => b.ref.current);
369
- if (m === "last") g.reverse();
370
- else if (m === "prev" || m === "next") {
371
- m === "prev" && g.reverse();
372
- const b = g.indexOf(f.currentTarget);
373
- g = d.loop ? $e(g, b + 1) : g.slice(b + 1);
374
- }
375
- setTimeout(() => ee(g));
376
- }
377
- })
378
- }
379
- )
380
- }
381
- );
382
- }
383
- );
384
- H.displayName = X;
385
- var Le = {
386
- ArrowLeft: "prev",
387
- ArrowUp: "prev",
388
- ArrowRight: "next",
389
- ArrowDown: "next",
390
- PageUp: "first",
391
- Home: "first",
392
- PageDown: "last",
393
- End: "last"
394
- };
395
- function Ve(e, t) {
396
- return t !== "rtl" ? e : e === "ArrowLeft" ? "ArrowRight" : e === "ArrowRight" ? "ArrowLeft" : e;
397
- }
398
- function Ue(e, t, o) {
399
- const r = Ve(e.key, o);
400
- if (!(t === "vertical" && ["ArrowLeft", "ArrowRight"].includes(r)) && !(t === "horizontal" && ["ArrowUp", "ArrowDown"].includes(r)))
401
- return Le[r];
402
- }
403
- function ee(e, t = !1) {
404
- const o = document.activeElement;
405
- for (const r of e)
406
- if (r === o || (r.focus({ preventScroll: t }), document.activeElement !== o)) return;
407
- }
408
- function $e(e, t) {
409
- return e.map((o, r) => e[(t + r) % e.length]);
410
- }
411
- var Be = Q, Ke = H, We = "Toggle", te = u.forwardRef((e, t) => {
412
- const { pressed: o, defaultPressed: r = !1, onPressedChange: n, ...s } = e, [c = !1, a] = k({
413
- prop: o,
414
- onChange: n,
415
- defaultProp: r
416
- });
417
- return /* @__PURE__ */ l(
418
- w.button,
419
- {
420
- type: "button",
421
- "aria-pressed": c,
422
- "data-state": c ? "on" : "off",
423
- "data-disabled": e.disabled ? "" : void 0,
424
- ...s,
425
- ref: t,
426
- onClick: S(e.onClick, () => {
427
- e.disabled || a(!c);
428
- })
429
- }
430
- );
431
- });
432
- te.displayName = We;
433
- var x = "ToggleGroup", [oe, ut] = U(x, [
434
- J
435
- ]), re = J(), B = C.forwardRef((e, t) => {
436
- const { type: o, ...r } = e;
437
- if (o === "single")
438
- return /* @__PURE__ */ l(je, { ...r, ref: t });
439
- if (o === "multiple")
440
- return /* @__PURE__ */ l(Ye, { ...r, ref: t });
441
- throw new Error(`Missing prop \`type\` expected on \`${x}\``);
442
- });
443
- B.displayName = x;
444
- var [ne, se] = oe(x), je = C.forwardRef((e, t) => {
445
- const {
446
- value: o,
447
- defaultValue: r,
448
- onValueChange: n = () => {
449
- },
450
- ...s
451
- } = e, [c, a] = k({
452
- prop: o,
453
- defaultProp: r,
454
- onChange: n
455
- });
456
- return /* @__PURE__ */ l(
457
- ne,
458
- {
459
- scope: e.__scopeToggleGroup,
460
- type: "single",
461
- value: c ? [c] : [],
462
- onItemActivate: a,
463
- onItemDeactivate: C.useCallback(() => a(""), [a]),
464
- children: /* @__PURE__ */ l(ce, { ...s, ref: t })
465
- }
466
- );
467
- }), Ye = C.forwardRef((e, t) => {
468
- const {
469
- value: o,
470
- defaultValue: r,
471
- onValueChange: n = () => {
472
- },
473
- ...s
474
- } = e, [c = [], a] = k({
475
- prop: o,
476
- defaultProp: r,
477
- onChange: n
478
- }), i = C.useCallback(
479
- (v) => a((p = []) => [...p, v]),
480
- [a]
481
- ), d = C.useCallback(
482
- (v) => a((p = []) => p.filter((h) => h !== v)),
483
- [a]
484
- );
485
- return /* @__PURE__ */ l(
486
- ne,
487
- {
488
- scope: e.__scopeToggleGroup,
489
- type: "multiple",
490
- value: c,
491
- onItemActivate: i,
492
- onItemDeactivate: d,
493
- children: /* @__PURE__ */ l(ce, { ...s, ref: t })
494
- }
495
- );
496
- });
497
- B.displayName = x;
498
- var [ze, qe] = oe(x), ce = C.forwardRef(
499
- (e, t) => {
500
- const {
501
- __scopeToggleGroup: o,
502
- disabled: r = !1,
503
- rovingFocus: n = !0,
504
- orientation: s,
505
- dir: c,
506
- loop: a = !0,
507
- ...i
508
- } = e, d = re(o), v = q(c), p = { role: "group", dir: v, ...i };
509
- return /* @__PURE__ */ l(ze, { scope: o, rovingFocus: n, disabled: r, children: n ? /* @__PURE__ */ l(
510
- Be,
511
- {
512
- asChild: !0,
513
- ...d,
514
- orientation: s,
515
- dir: v,
516
- loop: a,
517
- children: /* @__PURE__ */ l(w.div, { ...p, ref: t })
518
- }
519
- ) : /* @__PURE__ */ l(w.div, { ...p, ref: t }) });
520
- }
521
- ), F = "ToggleGroupItem", ue = C.forwardRef(
522
- (e, t) => {
523
- const o = se(F, e.__scopeToggleGroup), r = qe(F, e.__scopeToggleGroup), n = re(e.__scopeToggleGroup), s = o.value.includes(e.value), c = r.disabled || e.disabled, a = { ...e, pressed: s, disabled: c }, i = C.useRef(null);
524
- return r.rovingFocus ? /* @__PURE__ */ l(
525
- Ke,
526
- {
527
- asChild: !0,
528
- ...n,
529
- focusable: !c,
530
- active: s,
531
- ref: i,
532
- children: /* @__PURE__ */ l(Y, { ...a, ref: t })
533
- }
534
- ) : /* @__PURE__ */ l(Y, { ...a, ref: t });
535
- }
536
- );
537
- ue.displayName = F;
538
- var Y = C.forwardRef(
539
- (e, t) => {
540
- const { __scopeToggleGroup: o, value: r, ...n } = e, s = se(F, o), c = { role: "radio", "aria-checked": e.pressed, "aria-pressed": void 0 }, a = s.type === "single" ? c : void 0;
541
- return /* @__PURE__ */ l(
542
- te,
543
- {
544
- ...a,
545
- ...n,
546
- ref: t,
547
- onPressedChange: (i) => {
548
- i ? s.onItemActivate(r) : s.onItemDeactivate(r);
549
- }
550
- }
551
- );
552
- }
553
- ), Ze = B, Je = ue;
554
- const ae = C.createContext({
555
- size: "medium",
556
- focusMode: "system",
557
- mode: "system"
558
- }), Qe = ({ focusMode: e }) => P("focus:outline", "focus:outline-2", "focus:outline-offset", {
559
- "focus:outline-focus-light": e === "light",
560
- "focus:outline-focus-dark": e === "dark",
561
- "focus:outline-focus-light dark:focus:outline-focus-dark": e === "alt-system",
562
- "focus:outline-focus-dark dark:focus:outline-focus-light": e === "system"
563
- }), Xe = ({ mode: e }) => P({
564
- "data-[state=on]:bg-surface-medium": e === "dark",
565
- "data-[state=on]:bg-surface-lightest": e === "light",
566
- "data-[state=on]:bg-surface-lightest dark:data-[state=on]:bg-surface-medium": e === "system",
567
- "data-[state=on]:bg-surface-medium dark:data-[state=on]:bg-surface-lightest": e === "alt-system"
568
- }), He = ({ size: e }) => P({
569
- "h-5 px-2": e === "small",
570
- "h-6 px-3": e === "medium",
571
- "h-7 px-4": e === "large"
572
- }), et = ({ mode: e }) => P(
573
- Ce,
574
- "px-1",
575
- "relative",
576
- "border-r",
577
- "last:border-transparent",
578
- "has-[button[aria-checked='true']]:border-transparent",
579
- "has-[+_*_button[aria-checked='false']]:border-border-medium",
580
- {
581
- "border-surface-light": e === "light",
582
- "border-surface-darker": e === "dark",
583
- "border-surface-light dark:border-surface-darker": e === "system",
584
- "border-surface-darker dark:border-surface-light": e === "alt-system"
585
- }
586
- ), tt = ({
587
- focusMode: e,
588
- mode: t,
589
- size: o
590
- }) => ({
591
- wrapperClass: et({ mode: t }),
592
- itemClass: P(
593
- he,
594
- "flex items-center justify-center bg-transparent",
595
- "rounded-xs",
596
- "transition duration-200 ease",
597
- He({ size: o }),
598
- Qe({ focusMode: e }),
599
- Xe({ mode: t })
600
- )
601
- }), ot = ({
602
- mode: e,
603
- className: t
604
- }) => P(
605
- ve,
606
- "inline-flex p-1",
607
- "rounded-xs",
608
- {
609
- "bg-surface-light text-copy-dark": e === "light",
610
- "bg-surface-darker text-copy-lighter": e === "dark",
611
- "bg-surface-light text-copy-dark dark:bg-surface-darker dark:text-copy-lighter": e === "system",
612
- "bg-surface-darker text-copy-lighter dark:bg-surface-light dark:text-copy-dark": e === "alt-system"
613
- },
614
- t
615
- ), at = ({
616
- children: e,
617
- value: t,
618
- onValueChange: o,
619
- disabled: r,
620
- mode: n = "system",
621
- focusMode: s = "system",
622
- size: c = "medium",
623
- defaultValue: a,
624
- className: i,
625
- ...d
626
- }) => {
627
- const v = ot({ mode: n, className: i }), p = { size: c, focusMode: s, mode: n };
628
- return /* @__PURE__ */ l(ae.Provider, { value: p, children: /* @__PURE__ */ l(
629
- Ze,
630
- {
631
- disabled: r,
632
- className: v,
633
- value: t,
634
- defaultValue: a,
635
- onValueChange: o,
636
- ...d,
637
- type: "single",
638
- children: e
639
- }
640
- ) });
641
- }, lt = ({ value: e, disabled: t }) => {
642
- const { size: o, focusMode: r, mode: n } = me(ae), { itemClass: s, wrapperClass: c } = tt({
643
- focusMode: r,
644
- mode: n,
645
- size: o
646
- });
647
- return /* @__PURE__ */ l("div", { className: c, children: /* @__PURE__ */ l(
648
- Je,
649
- {
650
- disabled: t,
651
- className: s,
652
- value: e,
653
- children: e
654
- }
655
- ) });
656
- };
657
15
  export {
658
- ve as TOGGLEGROUP_CLASSNAME,
659
- he as TOGGLEGROUP_ITEM_CLASSNAME,
660
- Ce as TOGGLEGROUP_ITEM_WRAPPER_CLASSNAME,
661
- at as ToggleGroup,
662
- lt as ToggleGroupItem
16
+ E as TOGGLEGROUP_CLASSNAME,
17
+ e as TOGGLEGROUP_ITEM_CLASSNAME,
18
+ T as TOGGLEGROUP_ITEM_WRAPPER_CLASSNAME,
19
+ i as ToggleGroup,
20
+ r as ToggleGroupItem
663
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/ui-togglegroup",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -39,16 +39,16 @@
39
39
  "react-dom": "^18.3.1 || ^19.0.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@versini/ui-types": "5.0.0"
42
+ "@versini/ui-types": "5.0.2"
43
43
  },
44
44
  "dependencies": {
45
- "@radix-ui/react-toggle-group": "1.1.2",
45
+ "@radix-ui/react-toggle-group": "1.1.3",
46
46
  "@tailwindcss/typography": "0.5.16",
47
47
  "clsx": "2.1.1",
48
- "tailwindcss": "4.0.14"
48
+ "tailwindcss": "4.1.3"
49
49
  },
50
50
  "sideEffects": [
51
51
  "**/*.css"
52
52
  ],
53
- "gitHead": "40a943e1215f5344afa169a21267769e60ed81fd"
53
+ "gitHead": "1bc09c4f0904bd8c01a22b1a32299fdd7598ae32"
54
54
  }