@versini/ui-togglegroup 4.0.5 → 4.0.6

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