@versini/ui-togglegroup 4.0.2 → 4.0.4

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