@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.
- package/dist/index.js +215 -197
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,51 +1,54 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import * as
|
|
3
|
-
import
|
|
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.
|
|
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.
|
|
12
|
-
buildTime: "12/18/2024
|
|
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
|
|
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 =
|
|
22
|
+
const u = l.createContext(c), i = o.length;
|
|
23
23
|
o = [...o, c];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
37
|
+
return [d, v];
|
|
35
38
|
}
|
|
36
39
|
const n = () => {
|
|
37
|
-
const s = o.map((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
|
|
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,
|
|
49
|
+
return n.scopeName = e, [r, be(n, ...t)];
|
|
47
50
|
}
|
|
48
|
-
function
|
|
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:
|
|
58
|
-
const p = i(s)[`__scope${
|
|
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
|
|
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
|
|
67
|
-
typeof e == "function"
|
|
69
|
+
function W(e, t) {
|
|
70
|
+
if (typeof e == "function")
|
|
71
|
+
return e(t);
|
|
72
|
+
e != null && (e.current = t);
|
|
68
73
|
}
|
|
69
|
-
function
|
|
70
|
-
return (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
|
|
91
|
+
return l.useCallback(z(...e), e);
|
|
74
92
|
}
|
|
75
|
-
var A =
|
|
76
|
-
const { children: o, ...r } = e, n =
|
|
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 ?
|
|
79
|
-
return /* @__PURE__ */
|
|
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__ */
|
|
99
|
+
return /* @__PURE__ */ a(L, { ...r, ref: t, children: o });
|
|
82
100
|
});
|
|
83
101
|
A.displayName = "Slot";
|
|
84
|
-
var L =
|
|
102
|
+
var L = l.forwardRef((e, t) => {
|
|
85
103
|
const { children: o, ...r } = e;
|
|
86
|
-
if (
|
|
87
|
-
const n =
|
|
88
|
-
return
|
|
89
|
-
...
|
|
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 ?
|
|
109
|
+
ref: t ? z(t, n) : n
|
|
92
110
|
});
|
|
93
111
|
}
|
|
94
|
-
return
|
|
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__ */
|
|
115
|
+
var Ie = ({ children: e }) => /* @__PURE__ */ a(ge, { children: e });
|
|
98
116
|
function Te(e) {
|
|
99
|
-
return
|
|
117
|
+
return l.isValidElement(e) && e.type === Ie;
|
|
100
118
|
}
|
|
101
|
-
function
|
|
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
|
|
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 =
|
|
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__ */
|
|
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:
|
|
152
|
-
return /* @__PURE__ */
|
|
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 =
|
|
156
|
-
(I,
|
|
157
|
-
const { scope:
|
|
158
|
-
return /* @__PURE__ */
|
|
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
|
|
163
|
-
(I,
|
|
164
|
-
const { scope:
|
|
165
|
-
return
|
|
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 =
|
|
169
|
-
function
|
|
170
|
-
const
|
|
171
|
-
return
|
|
172
|
-
const T =
|
|
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
|
|
175
|
-
return Array.from(
|
|
176
|
-
(G, x) =>
|
|
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
|
-
}, [
|
|
196
|
+
}, [f.collectionRef, f.itemMap]);
|
|
179
197
|
}
|
|
180
198
|
return [
|
|
181
199
|
{ Provider: c, Slot: i, ItemSlot: p },
|
|
182
|
-
|
|
200
|
+
h,
|
|
183
201
|
r
|
|
184
202
|
];
|
|
185
203
|
}
|
|
186
|
-
var Ge = globalThis != null && globalThis.document ?
|
|
187
|
-
}, Pe =
|
|
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] =
|
|
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 =
|
|
197
|
-
return
|
|
214
|
+
const t = l.useRef(e);
|
|
215
|
+
return l.useEffect(() => {
|
|
198
216
|
t.current = e;
|
|
199
|
-
}),
|
|
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 =
|
|
211
|
-
(
|
|
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
|
|
231
|
+
const p = typeof d == "function" ? d(e) : d;
|
|
214
232
|
p !== e && u(p);
|
|
215
233
|
} else
|
|
216
|
-
n(
|
|
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 =
|
|
227
|
-
return
|
|
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 =
|
|
232
|
-
function
|
|
233
|
-
const t =
|
|
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,
|
|
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),
|
|
240
|
-
(e, t) => /* @__PURE__ */
|
|
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
|
-
|
|
243
|
-
var De =
|
|
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:
|
|
253
|
-
preventScrollOnEntryFocus:
|
|
270
|
+
onEntryFocus: d,
|
|
271
|
+
preventScrollOnEntryFocus: v = !1,
|
|
254
272
|
...p
|
|
255
|
-
} = e,
|
|
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
|
-
}), [
|
|
260
|
-
return
|
|
261
|
-
const
|
|
262
|
-
if (
|
|
263
|
-
return
|
|
264
|
-
}, [_]), /* @__PURE__ */
|
|
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:
|
|
287
|
+
dir: f,
|
|
270
288
|
loop: n,
|
|
271
|
-
currentTabStopId:
|
|
272
|
-
onItemFocus:
|
|
273
|
-
(
|
|
289
|
+
currentTabStopId: m,
|
|
290
|
+
onItemFocus: l.useCallback(
|
|
291
|
+
(y) => T(y),
|
|
274
292
|
[T]
|
|
275
293
|
),
|
|
276
|
-
onItemShiftTab:
|
|
277
|
-
onFocusableItemAdd:
|
|
278
|
-
() => K((
|
|
294
|
+
onItemShiftTab: l.useCallback(() => b(!0), []),
|
|
295
|
+
onFocusableItemAdd: l.useCallback(
|
|
296
|
+
() => K((y) => y + 1),
|
|
279
297
|
[]
|
|
280
298
|
),
|
|
281
|
-
onFocusableItemRemove:
|
|
282
|
-
() => K((
|
|
299
|
+
onFocusableItemRemove: l.useCallback(
|
|
300
|
+
() => K((y) => y - 1),
|
|
283
301
|
[]
|
|
284
302
|
),
|
|
285
|
-
children: /* @__PURE__ */
|
|
303
|
+
children: /* @__PURE__ */ a(
|
|
286
304
|
w.div,
|
|
287
305
|
{
|
|
288
|
-
tabIndex:
|
|
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, (
|
|
297
|
-
const
|
|
298
|
-
if (
|
|
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 (
|
|
301
|
-
const M = G().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((
|
|
304
|
-
|
|
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
|
-
}),
|
|
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,
|
|
323
|
-
return
|
|
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
|
|
326
|
-
}, [r,
|
|
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__ */
|
|
351
|
+
children: /* @__PURE__ */ a(
|
|
334
352
|
w.span,
|
|
335
353
|
{
|
|
336
|
-
tabIndex:
|
|
337
|
-
"data-orientation":
|
|
354
|
+
tabIndex: v ? 0 : -1,
|
|
355
|
+
"data-orientation": d.orientation,
|
|
338
356
|
...c,
|
|
339
357
|
ref: t,
|
|
340
|
-
onMouseDown: S(e.onMouseDown, (
|
|
341
|
-
r ?
|
|
358
|
+
onMouseDown: S(e.onMouseDown, (f) => {
|
|
359
|
+
r ? d.onItemFocus(i) : f.preventDefault();
|
|
342
360
|
}),
|
|
343
|
-
onFocus: S(e.onFocus, () =>
|
|
344
|
-
onKeyDown: S(e.onKeyDown, (
|
|
345
|
-
if (
|
|
346
|
-
|
|
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 (
|
|
350
|
-
const
|
|
351
|
-
if (
|
|
352
|
-
if (
|
|
353
|
-
|
|
354
|
-
let
|
|
355
|
-
if (
|
|
356
|
-
else if (
|
|
357
|
-
|
|
358
|
-
const b =
|
|
359
|
-
|
|
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(() =>
|
|
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
|
-
|
|
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
|
|
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 =
|
|
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__ */
|
|
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
|
-
|
|
419
|
-
var E = "ToggleGroup", [
|
|
420
|
-
|
|
421
|
-
]),
|
|
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__ */
|
|
442
|
+
return /* @__PURE__ */ a(We, { ...r, ref: t });
|
|
425
443
|
if (o === "multiple")
|
|
426
|
-
return /* @__PURE__ */
|
|
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 [
|
|
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__ */
|
|
443
|
-
|
|
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:
|
|
450
|
-
children: /* @__PURE__ */
|
|
467
|
+
onItemDeactivate: C.useCallback(() => u(""), [u]),
|
|
468
|
+
children: /* @__PURE__ */ a(ce, { ...s, ref: t })
|
|
451
469
|
}
|
|
452
470
|
);
|
|
453
|
-
}), Ye =
|
|
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 =
|
|
465
|
-
(
|
|
482
|
+
}), i = C.useCallback(
|
|
483
|
+
(v) => u((p = []) => [...p, v]),
|
|
466
484
|
[u]
|
|
467
|
-
),
|
|
468
|
-
(
|
|
485
|
+
), d = C.useCallback(
|
|
486
|
+
(v) => u((p = []) => p.filter((h) => h !== v)),
|
|
469
487
|
[u]
|
|
470
488
|
);
|
|
471
|
-
return /* @__PURE__ */
|
|
472
|
-
|
|
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:
|
|
479
|
-
children: /* @__PURE__ */
|
|
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] =
|
|
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,
|
|
495
|
-
return /* @__PURE__ */
|
|
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
|
-
...
|
|
517
|
+
...d,
|
|
500
518
|
orientation: s,
|
|
501
|
-
dir:
|
|
519
|
+
dir: v,
|
|
502
520
|
loop: u,
|
|
503
|
-
children: /* @__PURE__ */
|
|
521
|
+
children: /* @__PURE__ */ a(w.div, { ...p, ref: t })
|
|
504
522
|
}
|
|
505
|
-
) : /* @__PURE__ */
|
|
523
|
+
) : /* @__PURE__ */ a(w.div, { ...p, ref: t }) });
|
|
506
524
|
}
|
|
507
|
-
), F = "ToggleGroupItem",
|
|
525
|
+
), F = "ToggleGroupItem", ue = C.forwardRef(
|
|
508
526
|
(e, t) => {
|
|
509
|
-
const o =
|
|
510
|
-
return r.rovingFocus ? /* @__PURE__ */
|
|
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__ */
|
|
536
|
+
children: /* @__PURE__ */ a(Y, { ...u, ref: t })
|
|
519
537
|
}
|
|
520
|
-
) : /* @__PURE__ */
|
|
538
|
+
) : /* @__PURE__ */ a(Y, { ...u, ref: t });
|
|
521
539
|
}
|
|
522
540
|
);
|
|
523
|
-
|
|
524
|
-
var
|
|
541
|
+
ue.displayName = F;
|
|
542
|
+
var Y = C.forwardRef(
|
|
525
543
|
(e, t) => {
|
|
526
|
-
const { __scopeToggleGroup: o, value: r, ...n } = e, s =
|
|
527
|
-
return /* @__PURE__ */
|
|
528
|
-
|
|
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 =
|
|
540
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
),
|
|
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
|
-
...
|
|
638
|
+
...d
|
|
621
639
|
}) => {
|
|
622
|
-
const
|
|
623
|
-
return /* @__PURE__ */
|
|
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:
|
|
645
|
+
className: v,
|
|
628
646
|
value: t,
|
|
629
647
|
defaultValue: u,
|
|
630
648
|
onValueChange: o,
|
|
631
|
-
...
|
|
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 } =
|
|
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__ */
|
|
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
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
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.
|
|
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.
|
|
41
|
+
"@radix-ui/react-toggle-group": "1.1.1",
|
|
42
42
|
"@tailwindcss/typography": "0.5.15",
|
|
43
|
-
"@versini/ui-private": "1.5.
|
|
43
|
+
"@versini/ui-private": "1.5.1",
|
|
44
44
|
"clsx": "2.1.1",
|
|
45
|
-
"tailwindcss": "3.4.
|
|
45
|
+
"tailwindcss": "3.4.17"
|
|
46
46
|
},
|
|
47
47
|
"sideEffects": [
|
|
48
48
|
"**/*.css"
|
|
49
49
|
],
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "123c2555b25210da73697c4fdd3b6a5f67a3b993"
|
|
51
51
|
}
|