@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 +42 -1
- package/dist/components/ToggleGroup/ToggleGroup.js +210 -218
- package/dist/index.js +3 -3
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
1
|
# @versini/ui-togglegroup
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](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
|
|
3
|
-
import
|
|
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,
|
|
9
|
-
const
|
|
10
|
-
o = [...o,
|
|
8
|
+
function r(s, l) {
|
|
9
|
+
const c = u.createContext(l), i = o.length;
|
|
10
|
+
o = [...o, l];
|
|
11
11
|
const g = (d) => {
|
|
12
|
-
|
|
13
|
-
|
|
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,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (
|
|
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((
|
|
28
|
-
return function(
|
|
29
|
-
const i =
|
|
30
|
-
return
|
|
31
|
-
() => ({ [`__scope${e}`]: { ...
|
|
32
|
-
[
|
|
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
|
|
45
|
+
const l = r.reduce((c, { useScope: i, scopeName: g }) => {
|
|
48
46
|
const d = i(s)[`__scope${g}`];
|
|
49
|
-
return { ...
|
|
47
|
+
return { ...c, ...d };
|
|
50
48
|
}, {});
|
|
51
|
-
return
|
|
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
|
|
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
|
|
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 =
|
|
83
|
-
const { children: s, ...
|
|
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 =
|
|
86
|
-
return /* @__PURE__ */ f(t, { ...
|
|
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, { ...
|
|
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 =
|
|
92
|
+
const t = u.forwardRef((o, r) => {
|
|
95
93
|
const { children: n, ...s } = o;
|
|
96
|
-
if (
|
|
97
|
-
const
|
|
98
|
-
return n.type !==
|
|
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
|
|
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
|
|
106
|
-
return
|
|
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
|
|
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] = (...
|
|
113
|
-
const i = s(...
|
|
114
|
-
return n(...
|
|
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
|
|
120
|
-
|
|
121
|
-
|
|
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
|
|
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 =
|
|
143
|
-
const o = /* @__PURE__ */ $(`Primitive.${t}`), r =
|
|
144
|
-
const { asChild:
|
|
145
|
-
return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ f(i, { ...
|
|
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
|
|
146
|
+
function x(e, t, { checkForDefaultPrevented: o = !0 } = {}) {
|
|
150
147
|
return function(n) {
|
|
151
|
-
if (e
|
|
152
|
-
return t
|
|
148
|
+
if (e?.(n), o === !1 || !n.defaultPrevented)
|
|
149
|
+
return t?.(n);
|
|
153
150
|
};
|
|
154
151
|
}
|
|
155
|
-
function
|
|
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
|
-
),
|
|
160
|
-
const { scope: p, children: b } = h,
|
|
161
|
-
return /* @__PURE__ */ f(n, { scope: p, itemMap:
|
|
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
|
-
|
|
164
|
-
const
|
|
160
|
+
l.displayName = t;
|
|
161
|
+
const c = e + "CollectionSlot", i = /* @__PURE__ */ $(c), g = v.forwardRef(
|
|
165
162
|
(h, p) => {
|
|
166
|
-
const { scope: b, children:
|
|
167
|
-
return /* @__PURE__ */ f(i, { ref:
|
|
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 =
|
|
171
|
-
const a = e + "CollectionItemSlot", d = "data-radix-collection-item",
|
|
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:
|
|
174
|
-
return
|
|
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
|
-
|
|
178
|
-
function
|
|
174
|
+
y.displayName = a;
|
|
175
|
+
function S(h) {
|
|
179
176
|
const p = s(e + "CollectionConsumer", h);
|
|
180
|
-
return
|
|
181
|
-
const
|
|
182
|
-
if (!
|
|
183
|
-
const
|
|
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) =>
|
|
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:
|
|
191
|
-
|
|
187
|
+
{ Provider: l, Slot: g, ItemSlot: y },
|
|
188
|
+
S,
|
|
192
189
|
r
|
|
193
190
|
];
|
|
194
191
|
}
|
|
195
|
-
var
|
|
196
|
-
},
|
|
197
|
-
}),
|
|
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] =
|
|
200
|
-
return
|
|
201
|
-
o((r) => r ?? String(
|
|
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 =
|
|
206
|
-
return
|
|
202
|
+
const t = u.useRef(e);
|
|
203
|
+
return u.useEffect(() => {
|
|
207
204
|
t.current = e;
|
|
208
|
-
}),
|
|
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 =
|
|
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,
|
|
215
|
+
const [n, s, l] = Ae({
|
|
222
216
|
defaultProp: t,
|
|
223
217
|
onChange: o
|
|
224
|
-
}),
|
|
218
|
+
}), c = e !== void 0, i = c ? e : n;
|
|
225
219
|
{
|
|
226
|
-
const a =
|
|
227
|
-
|
|
220
|
+
const a = u.useRef(e !== void 0);
|
|
221
|
+
u.useEffect(() => {
|
|
228
222
|
const d = a.current;
|
|
229
|
-
d !==
|
|
230
|
-
`${r} is changing from ${d ? "controlled" : "uncontrolled"} to ${
|
|
231
|
-
), a.current =
|
|
232
|
-
}, [
|
|
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 =
|
|
228
|
+
const g = u.useCallback(
|
|
235
229
|
(a) => {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
[
|
|
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] =
|
|
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]),
|
|
255
|
-
|
|
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 =
|
|
263
|
-
function
|
|
264
|
-
const t =
|
|
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,
|
|
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),
|
|
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
|
-
|
|
274
|
-
var $e =
|
|
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:
|
|
281
|
-
defaultCurrentTabStopId:
|
|
272
|
+
currentTabStopId: l,
|
|
273
|
+
defaultCurrentTabStopId: c,
|
|
282
274
|
onCurrentTabStopIdChange: i,
|
|
283
275
|
onEntryFocus: g,
|
|
284
276
|
preventScrollOnEntryFocus: a = !1,
|
|
285
277
|
...d
|
|
286
|
-
} = e,
|
|
287
|
-
prop:
|
|
288
|
-
defaultProp:
|
|
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,
|
|
292
|
-
return
|
|
293
|
-
const
|
|
294
|
-
if (
|
|
295
|
-
return
|
|
296
|
-
}, [
|
|
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:
|
|
293
|
+
dir: S,
|
|
302
294
|
loop: n,
|
|
303
295
|
currentTabStopId: h,
|
|
304
|
-
onItemFocus:
|
|
305
|
-
(
|
|
296
|
+
onItemFocus: u.useCallback(
|
|
297
|
+
(R) => p(R),
|
|
306
298
|
[p]
|
|
307
299
|
),
|
|
308
|
-
onItemShiftTab:
|
|
309
|
-
onFocusableItemAdd:
|
|
310
|
-
() => k((
|
|
300
|
+
onItemShiftTab: u.useCallback(() => T(!0), []),
|
|
301
|
+
onFocusableItemAdd: u.useCallback(
|
|
302
|
+
() => k((R) => R + 1),
|
|
311
303
|
[]
|
|
312
304
|
),
|
|
313
|
-
onFocusableItemRemove:
|
|
314
|
-
() => k((
|
|
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:
|
|
315
|
+
ref: y,
|
|
324
316
|
style: { outline: "none", ...e.style },
|
|
325
|
-
onMouseDown:
|
|
317
|
+
onMouseDown: x(e.onMouseDown, () => {
|
|
326
318
|
_.current = !0;
|
|
327
319
|
}),
|
|
328
|
-
onFocus:
|
|
320
|
+
onFocus: x(e.onFocus, (R) => {
|
|
329
321
|
const ie = !_.current;
|
|
330
|
-
if (
|
|
322
|
+
if (R.target === R.currentTarget && ie && !b) {
|
|
331
323
|
const K = new CustomEvent(D, Ne);
|
|
332
|
-
if (
|
|
333
|
-
const O =
|
|
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((
|
|
327
|
+
).map((P) => P.ref.current);
|
|
336
328
|
ee(pe, a);
|
|
337
329
|
}
|
|
338
330
|
}
|
|
339
331
|
_.current = !1;
|
|
340
332
|
}),
|
|
341
|
-
onBlur:
|
|
333
|
+
onBlur: x(e.onBlur, () => T(!1))
|
|
342
334
|
}
|
|
343
335
|
)
|
|
344
336
|
}
|
|
345
337
|
);
|
|
346
|
-
}),
|
|
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:
|
|
354
|
-
...
|
|
355
|
-
} = e, i = _e(), g = s || i, a = Le(
|
|
356
|
-
return
|
|
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
|
|
359
|
-
}, [r,
|
|
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
|
-
...
|
|
363
|
+
...c,
|
|
372
364
|
ref: t,
|
|
373
|
-
onMouseDown:
|
|
365
|
+
onMouseDown: x(e.onMouseDown, (p) => {
|
|
374
366
|
r ? a.onItemFocus(g) : p.preventDefault();
|
|
375
367
|
}),
|
|
376
|
-
onFocus:
|
|
377
|
-
onKeyDown:
|
|
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
|
|
388
|
-
if (b === "last")
|
|
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" &&
|
|
391
|
-
const
|
|
392
|
-
|
|
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(
|
|
386
|
+
setTimeout(() => ee(m));
|
|
395
387
|
}
|
|
396
388
|
}),
|
|
397
|
-
children: typeof
|
|
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
|
-
|
|
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 =
|
|
432
|
-
const { pressed: o, defaultPressed: r, onPressedChange: n, ...s } = e, [
|
|
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":
|
|
443
|
-
"data-state":
|
|
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:
|
|
448
|
-
e.disabled ||
|
|
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
|
|
455
|
-
|
|
456
|
-
]), ne =
|
|
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(
|
|
451
|
+
return /* @__PURE__ */ f(He, { ...r, ref: t });
|
|
460
452
|
if (o === "multiple")
|
|
461
|
-
return /* @__PURE__ */ f(
|
|
462
|
-
throw new Error(`Missing prop \`type\` expected on \`${
|
|
453
|
+
return /* @__PURE__ */ f(Ye, { ...r, ref: t });
|
|
454
|
+
throw new Error(`Missing prop \`type\` expected on \`${E}\``);
|
|
463
455
|
});
|
|
464
|
-
B.displayName =
|
|
465
|
-
var [se, ce] = re(
|
|
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, [
|
|
464
|
+
} = e, [l, c] = M({
|
|
473
465
|
prop: o,
|
|
474
466
|
defaultProp: r ?? "",
|
|
475
467
|
onChange: n,
|
|
476
|
-
caller:
|
|
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:
|
|
484
|
-
onItemActivate:
|
|
485
|
-
onItemDeactivate:
|
|
486
|
-
children: /* @__PURE__ */ f(
|
|
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
|
-
}),
|
|
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, [
|
|
488
|
+
} = e, [l, c] = M({
|
|
497
489
|
prop: o,
|
|
498
490
|
defaultProp: r ?? [],
|
|
499
491
|
onChange: n,
|
|
500
|
-
caller:
|
|
501
|
-
}), i =
|
|
502
|
-
(a) =>
|
|
503
|
-
[
|
|
504
|
-
), g =
|
|
505
|
-
(a) =>
|
|
506
|
-
[
|
|
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:
|
|
505
|
+
value: l,
|
|
514
506
|
onItemActivate: i,
|
|
515
507
|
onItemDeactivate: g,
|
|
516
|
-
children: /* @__PURE__ */ f(
|
|
508
|
+
children: /* @__PURE__ */ f(le, { ...s, ref: t })
|
|
517
509
|
}
|
|
518
510
|
);
|
|
519
511
|
});
|
|
520
|
-
B.displayName =
|
|
521
|
-
var [
|
|
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:
|
|
529
|
-
loop:
|
|
520
|
+
dir: l,
|
|
521
|
+
loop: c = !0,
|
|
530
522
|
...i
|
|
531
|
-
} = e, g = ne(o), a =
|
|
532
|
-
return /* @__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:
|
|
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",
|
|
536
|
+
), N = "ToggleGroupItem", ue = v.forwardRef(
|
|
545
537
|
(e, t) => {
|
|
546
|
-
const o = ce(N, e.__scopeToggleGroup), r =
|
|
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: !
|
|
544
|
+
focusable: !l,
|
|
553
545
|
active: s,
|
|
554
546
|
ref: i,
|
|
555
|
-
children: /* @__PURE__ */ f(j, { ...
|
|
547
|
+
children: /* @__PURE__ */ f(j, { ...c, ref: t })
|
|
556
548
|
}
|
|
557
|
-
) : /* @__PURE__ */ f(j, { ...
|
|
549
|
+
) : /* @__PURE__ */ f(j, { ...c, ref: t });
|
|
558
550
|
}
|
|
559
551
|
);
|
|
560
|
-
|
|
561
|
-
var j =
|
|
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),
|
|
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
|
-
...
|
|
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
|
-
),
|
|
577
|
-
const ae =
|
|
568
|
+
), Ze = B, Je = ue;
|
|
569
|
+
const ae = v.createContext({
|
|
578
570
|
size: "medium",
|
|
579
571
|
focusMode: "system",
|
|
580
572
|
mode: "system"
|
|
581
|
-
}),
|
|
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
|
-
}),
|
|
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
|
-
|
|
622
|
-
|
|
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:
|
|
646
|
-
defaultValue:
|
|
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:
|
|
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
|
-
|
|
644
|
+
Ze,
|
|
653
645
|
{
|
|
654
646
|
disabled: r,
|
|
655
647
|
className: a,
|
|
656
648
|
value: t,
|
|
657
|
-
defaultValue:
|
|
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:
|
|
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:
|
|
671
|
-
|
|
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.
|
|
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.
|
|
9
|
-
buildTime: "
|
|
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.
|
|
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.
|
|
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": "
|
|
54
|
+
"gitHead": "42daab1fb88c366495abbc1db78a9987de05e59b"
|
|
54
55
|
}
|