@versini/ui-togglegroup 1.2.0 → 1.2.1

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