@purpurds/toggle 5.27.2 → 5.27.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LICENSE.txt +4 -4
- package/dist/toggle.cjs.js +5 -5
- package/dist/toggle.cjs.js.map +1 -1
- package/dist/toggle.es.js +113 -104
- package/dist/toggle.es.js.map +1 -1
- package/package.json +5 -5
- package/src/toggle.stories.tsx +2 -0
package/dist/toggle.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsx as x, jsxs as
|
|
2
|
-
import { forwardRef as w, Children as y, isValidElement as
|
|
1
|
+
import { jsx as x, jsxs as G } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as w, Children as y, isValidElement as k, createElement as _, cloneElement as L, useEffect as D, Fragment as K, useCallback as X, createContext as Z, useMemo as H, useContext as fe, useRef as C, useState as $, useLayoutEffect as Q } from "react";
|
|
3
3
|
import "react-dom";
|
|
4
4
|
function ge(e) {
|
|
5
5
|
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
@@ -98,35 +98,35 @@ function E() {
|
|
|
98
98
|
function Se(e, n) {
|
|
99
99
|
typeof e == "function" ? e(n) : e != null && (e.current = n);
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function Pe(...e) {
|
|
102
102
|
return (n) => e.forEach(
|
|
103
103
|
(t) => Se(t, n)
|
|
104
104
|
);
|
|
105
105
|
}
|
|
106
106
|
const te = /* @__PURE__ */ w((e, n) => {
|
|
107
|
-
const { children: t, ...a } = e, c = y.toArray(t), r = c.find(
|
|
107
|
+
const { children: t, ...a } = e, c = y.toArray(t), r = c.find(Ae);
|
|
108
108
|
if (r) {
|
|
109
|
-
const o = r.props.children, u = c.map((i) => i === r ? y.count(o) > 1 ? y.only(null) : /* @__PURE__ */
|
|
110
|
-
return /* @__PURE__ */ _(
|
|
109
|
+
const o = r.props.children, u = c.map((i) => i === r ? y.count(o) > 1 ? y.only(null) : /* @__PURE__ */ k(o) ? o.props.children : null : i);
|
|
110
|
+
return /* @__PURE__ */ _(F, E({}, a, {
|
|
111
111
|
ref: n
|
|
112
|
-
}), /* @__PURE__ */
|
|
112
|
+
}), /* @__PURE__ */ k(o) ? /* @__PURE__ */ L(o, void 0, u) : null);
|
|
113
113
|
}
|
|
114
|
-
return /* @__PURE__ */ _(
|
|
114
|
+
return /* @__PURE__ */ _(F, E({}, a, {
|
|
115
115
|
ref: n
|
|
116
116
|
}), t);
|
|
117
117
|
});
|
|
118
118
|
te.displayName = "Slot";
|
|
119
|
-
const
|
|
119
|
+
const F = /* @__PURE__ */ w((e, n) => {
|
|
120
120
|
const { children: t, ...a } = e;
|
|
121
|
-
return /* @__PURE__ */
|
|
121
|
+
return /* @__PURE__ */ k(t) ? /* @__PURE__ */ L(t, {
|
|
122
122
|
...Ne(a, t.props),
|
|
123
|
-
ref: n ?
|
|
123
|
+
ref: n ? Pe(n, t.ref) : t.ref
|
|
124
124
|
}) : y.count(t) > 1 ? y.only(null) : null;
|
|
125
125
|
});
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
function
|
|
129
|
-
return /* @__PURE__ */
|
|
126
|
+
F.displayName = "SlotClone";
|
|
127
|
+
const ke = ({ children: e }) => /* @__PURE__ */ _(K, null, e);
|
|
128
|
+
function Ae(e) {
|
|
129
|
+
return /* @__PURE__ */ k(e) && e.type === ke;
|
|
130
130
|
}
|
|
131
131
|
function Ne(e, n) {
|
|
132
132
|
const t = {
|
|
@@ -166,7 +166,7 @@ const De = [
|
|
|
166
166
|
"span",
|
|
167
167
|
"svg",
|
|
168
168
|
"ul"
|
|
169
|
-
],
|
|
169
|
+
], Ce = De.reduce((e, n) => {
|
|
170
170
|
const t = /* @__PURE__ */ w((a, c) => {
|
|
171
171
|
const { asChild: r, ...o } = a, u = r ? te : n;
|
|
172
172
|
return D(() => {
|
|
@@ -179,14 +179,14 @@ const De = [
|
|
|
179
179
|
...e,
|
|
180
180
|
[n]: t
|
|
181
181
|
};
|
|
182
|
-
}, {}), Ee = /* @__PURE__ */ w((e, n) => /* @__PURE__ */ _(
|
|
182
|
+
}, {}), Ee = /* @__PURE__ */ w((e, n) => /* @__PURE__ */ _(Ce.label, E({}, e, {
|
|
183
183
|
ref: n,
|
|
184
184
|
onMouseDown: (t) => {
|
|
185
185
|
var a;
|
|
186
186
|
(a = e.onMouseDown) === null || a === void 0 || a.call(e, t), !t.defaultPrevented && t.detail > 1 && t.preventDefault();
|
|
187
187
|
}
|
|
188
|
-
}))),
|
|
189
|
-
function
|
|
188
|
+
}))), Oe = Ee;
|
|
189
|
+
function Re(e) {
|
|
190
190
|
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
191
191
|
}
|
|
192
192
|
var ne = { exports: {} };
|
|
@@ -226,11 +226,11 @@ var ne = { exports: {} };
|
|
|
226
226
|
})();
|
|
227
227
|
})(ne);
|
|
228
228
|
var Me = ne.exports;
|
|
229
|
-
const
|
|
229
|
+
const je = /* @__PURE__ */ Re(Me), z = {
|
|
230
230
|
"purpur-label": "_purpur-label_12cfi_1",
|
|
231
231
|
"purpur-label--negative": "_purpur-label--negative_12cfi_9",
|
|
232
232
|
"purpur-label--disabled": "_purpur-label--disabled_12cfi_12"
|
|
233
|
-
},
|
|
233
|
+
}, I = "purpur-label", He = ({
|
|
234
234
|
children: e,
|
|
235
235
|
className: n,
|
|
236
236
|
htmlFor: t,
|
|
@@ -239,17 +239,17 @@ const Xe = /* @__PURE__ */ je(Me), T = {
|
|
|
239
239
|
negative: r = !1,
|
|
240
240
|
...o
|
|
241
241
|
}) => {
|
|
242
|
-
const u =
|
|
242
|
+
const u = je([
|
|
243
243
|
n,
|
|
244
|
-
|
|
244
|
+
z[I],
|
|
245
245
|
{
|
|
246
|
-
[
|
|
247
|
-
[
|
|
246
|
+
[z[`${I}--disabled`]]: c,
|
|
247
|
+
[z[`${I}--negative`]]: r
|
|
248
248
|
}
|
|
249
249
|
]);
|
|
250
|
-
return /* @__PURE__ */ x(
|
|
250
|
+
return /* @__PURE__ */ x(Oe, { className: u, "data-testid": a, htmlFor: t, ...o, children: e });
|
|
251
251
|
};
|
|
252
|
-
function
|
|
252
|
+
function Le(e) {
|
|
253
253
|
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
254
254
|
}
|
|
255
255
|
var oe = { exports: {} };
|
|
@@ -288,8 +288,8 @@ var oe = { exports: {} };
|
|
|
288
288
|
e.exports ? (t.default = t, e.exports = t) : window.classNames = t;
|
|
289
289
|
})();
|
|
290
290
|
})(oe);
|
|
291
|
-
var
|
|
292
|
-
const
|
|
291
|
+
var Xe = oe.exports;
|
|
292
|
+
const Be = /* @__PURE__ */ Le(Xe), M = {
|
|
293
293
|
"purpur-paragraph": "_purpur-paragraph_1rh57_1",
|
|
294
294
|
"purpur-paragraph--disabled": "_purpur-paragraph--disabled_1rh57_7",
|
|
295
295
|
"purpur-paragraph--hyphens": "_purpur-paragraph--hyphens_1rh57_10",
|
|
@@ -304,26 +304,35 @@ const Le = /* @__PURE__ */ Re(Be), M = {
|
|
|
304
304
|
"purpur-paragraph--additional-100-medium": "_purpur-paragraph--additional-100-medium_1rh57_60",
|
|
305
305
|
"purpur-paragraph--overline-100": "_purpur-paragraph--overline-100_1rh57_67",
|
|
306
306
|
"purpur-paragraph--overline-200": "_purpur-paragraph--overline-200_1rh57_75"
|
|
307
|
-
},
|
|
308
|
-
PARAGRAPH100: "paragraph-100"
|
|
309
|
-
|
|
307
|
+
}, Te = {
|
|
308
|
+
PARAGRAPH100: "paragraph-100",
|
|
309
|
+
PARAGRAPH100MEDIUM: "paragraph-100-medium",
|
|
310
|
+
PARAGRAPH100BOLD: "paragraph-100-bold",
|
|
311
|
+
PARAGRAPH200: "paragraph-200",
|
|
312
|
+
PREAMBLE100: "preamble-100",
|
|
313
|
+
PREAMBLE200: "preamble-200",
|
|
314
|
+
ADDITIONAL100: "additional-100",
|
|
315
|
+
ADDITIONAL100MEDIUM: "additional-100-medium",
|
|
316
|
+
OVERLINE100: "overline-100",
|
|
317
|
+
OVERLINE200: "overline-200"
|
|
318
|
+
}, j = "purpur-paragraph", ae = ({
|
|
310
319
|
["data-testid"]: e,
|
|
311
320
|
children: n,
|
|
312
321
|
className: t,
|
|
313
322
|
disabled: a,
|
|
314
323
|
enableHyphenation: c = !1,
|
|
315
324
|
negative: r = !1,
|
|
316
|
-
variant: o =
|
|
325
|
+
variant: o = Te.PARAGRAPH100,
|
|
317
326
|
...u
|
|
318
327
|
}) => {
|
|
319
|
-
const i =
|
|
328
|
+
const i = Be([
|
|
320
329
|
t,
|
|
321
|
-
M[
|
|
322
|
-
M[`${
|
|
330
|
+
M[j],
|
|
331
|
+
M[`${j}--${o}`],
|
|
323
332
|
{
|
|
324
|
-
[M[`${
|
|
325
|
-
[M[`${
|
|
326
|
-
[M[`${
|
|
333
|
+
[M[`${j}--hyphens`]]: c,
|
|
334
|
+
[M[`${j}--disabled`]]: a,
|
|
335
|
+
[M[`${j}--negative`]]: r
|
|
327
336
|
}
|
|
328
337
|
]);
|
|
329
338
|
return /* @__PURE__ */ x("p", { ...u, className: i, "data-testid": e, children: n });
|
|
@@ -338,26 +347,26 @@ function N() {
|
|
|
338
347
|
return e;
|
|
339
348
|
}, N.apply(null, arguments);
|
|
340
349
|
}
|
|
341
|
-
function
|
|
350
|
+
function ze(e, n, { checkForDefaultPrevented: t = !0 } = {}) {
|
|
342
351
|
return function(c) {
|
|
343
352
|
if (e == null || e(c), t === !1 || !c.defaultPrevented) return n == null ? void 0 : n(c);
|
|
344
353
|
};
|
|
345
354
|
}
|
|
346
|
-
function
|
|
355
|
+
function Ie(e, n) {
|
|
347
356
|
typeof e == "function" ? e(n) : e != null && (e.current = n);
|
|
348
357
|
}
|
|
349
358
|
function ce(...e) {
|
|
350
359
|
return (n) => e.forEach(
|
|
351
|
-
(t) =>
|
|
360
|
+
(t) => Ie(t, n)
|
|
352
361
|
);
|
|
353
362
|
}
|
|
354
|
-
function
|
|
355
|
-
return
|
|
363
|
+
function qe(...e) {
|
|
364
|
+
return X(ce(...e), e);
|
|
356
365
|
}
|
|
357
|
-
function
|
|
366
|
+
function Fe(e, n = []) {
|
|
358
367
|
let t = [];
|
|
359
368
|
function a(r, o) {
|
|
360
|
-
const u = /* @__PURE__ */
|
|
369
|
+
const u = /* @__PURE__ */ Z(o), i = t.length;
|
|
361
370
|
t = [
|
|
362
371
|
...t,
|
|
363
372
|
o
|
|
@@ -383,7 +392,7 @@ function We(e, n = []) {
|
|
|
383
392
|
];
|
|
384
393
|
}
|
|
385
394
|
const c = () => {
|
|
386
|
-
const r = t.map((o) => /* @__PURE__ */
|
|
395
|
+
const r = t.map((o) => /* @__PURE__ */ Z(o));
|
|
387
396
|
return function(u) {
|
|
388
397
|
const i = (u == null ? void 0 : u[e]) || r;
|
|
389
398
|
return H(
|
|
@@ -402,10 +411,10 @@ function We(e, n = []) {
|
|
|
402
411
|
};
|
|
403
412
|
return c.scopeName = e, [
|
|
404
413
|
a,
|
|
405
|
-
|
|
414
|
+
Ue(c, ...n)
|
|
406
415
|
];
|
|
407
416
|
}
|
|
408
|
-
function
|
|
417
|
+
function Ue(...e) {
|
|
409
418
|
const n = e[0];
|
|
410
419
|
if (e.length === 1) return n;
|
|
411
420
|
const t = () => {
|
|
@@ -436,7 +445,7 @@ function Ie(...e) {
|
|
|
436
445
|
return t.scopeName = n.scopeName, t;
|
|
437
446
|
}
|
|
438
447
|
function ue(e) {
|
|
439
|
-
const n =
|
|
448
|
+
const n = C(e);
|
|
440
449
|
return D(() => {
|
|
441
450
|
n.current = e;
|
|
442
451
|
}), H(
|
|
@@ -447,12 +456,12 @@ function ue(e) {
|
|
|
447
456
|
[]
|
|
448
457
|
);
|
|
449
458
|
}
|
|
450
|
-
function
|
|
459
|
+
function Ve({ prop: e, defaultProp: n, onChange: t = () => {
|
|
451
460
|
} }) {
|
|
452
|
-
const [a, c] =
|
|
461
|
+
const [a, c] = We({
|
|
453
462
|
defaultProp: n,
|
|
454
463
|
onChange: t
|
|
455
|
-
}), r = e !== void 0, o = r ? e : a, u = ue(t), i =
|
|
464
|
+
}), r = e !== void 0, o = r ? e : a, u = ue(t), i = X((s) => {
|
|
456
465
|
if (r) {
|
|
457
466
|
const l = typeof s == "function" ? s(e) : s;
|
|
458
467
|
l !== e && u(l);
|
|
@@ -468,8 +477,8 @@ function Ue({ prop: e, defaultProp: n, onChange: t = () => {
|
|
|
468
477
|
i
|
|
469
478
|
];
|
|
470
479
|
}
|
|
471
|
-
function
|
|
472
|
-
const t = $(e), [a] = t, c =
|
|
480
|
+
function We({ defaultProp: e, onChange: n }) {
|
|
481
|
+
const t = $(e), [a] = t, c = C(a), r = ue(n);
|
|
473
482
|
return D(() => {
|
|
474
483
|
c.current !== a && (r(a), c.current = a);
|
|
475
484
|
}, [
|
|
@@ -478,8 +487,8 @@ function Ve({ defaultProp: e, onChange: n }) {
|
|
|
478
487
|
r
|
|
479
488
|
]), t;
|
|
480
489
|
}
|
|
481
|
-
function
|
|
482
|
-
const n =
|
|
490
|
+
function Ge(e) {
|
|
491
|
+
const n = C({
|
|
483
492
|
value: e,
|
|
484
493
|
previous: e
|
|
485
494
|
});
|
|
@@ -487,11 +496,11 @@ function Ze(e) {
|
|
|
487
496
|
e
|
|
488
497
|
]);
|
|
489
498
|
}
|
|
490
|
-
const
|
|
499
|
+
const Ze = globalThis != null && globalThis.document ? Q : () => {
|
|
491
500
|
};
|
|
492
501
|
function Je(e) {
|
|
493
502
|
const [n, t] = $(void 0);
|
|
494
|
-
return
|
|
503
|
+
return Ze(() => {
|
|
495
504
|
if (e) {
|
|
496
505
|
t({
|
|
497
506
|
width: e.offsetWidth,
|
|
@@ -523,27 +532,27 @@ function Je(e) {
|
|
|
523
532
|
const ie = /* @__PURE__ */ w((e, n) => {
|
|
524
533
|
const { children: t, ...a } = e, c = y.toArray(t), r = c.find(Ke);
|
|
525
534
|
if (r) {
|
|
526
|
-
const o = r.props.children, u = c.map((i) => i === r ? y.count(o) > 1 ? y.only(null) : /* @__PURE__ */
|
|
527
|
-
return /* @__PURE__ */ _(
|
|
535
|
+
const o = r.props.children, u = c.map((i) => i === r ? y.count(o) > 1 ? y.only(null) : /* @__PURE__ */ k(o) ? o.props.children : null : i);
|
|
536
|
+
return /* @__PURE__ */ _(U, N({}, a, {
|
|
528
537
|
ref: n
|
|
529
|
-
}), /* @__PURE__ */
|
|
538
|
+
}), /* @__PURE__ */ k(o) ? /* @__PURE__ */ L(o, void 0, u) : null);
|
|
530
539
|
}
|
|
531
|
-
return /* @__PURE__ */ _(
|
|
540
|
+
return /* @__PURE__ */ _(U, N({}, a, {
|
|
532
541
|
ref: n
|
|
533
542
|
}), t);
|
|
534
543
|
});
|
|
535
544
|
ie.displayName = "Slot";
|
|
536
|
-
const
|
|
545
|
+
const U = /* @__PURE__ */ w((e, n) => {
|
|
537
546
|
const { children: t, ...a } = e;
|
|
538
|
-
return /* @__PURE__ */
|
|
547
|
+
return /* @__PURE__ */ k(t) ? /* @__PURE__ */ L(t, {
|
|
539
548
|
...Qe(a, t.props),
|
|
540
549
|
ref: n ? ce(n, t.ref) : t.ref
|
|
541
550
|
}) : y.count(t) > 1 ? y.only(null) : null;
|
|
542
551
|
});
|
|
543
|
-
|
|
552
|
+
U.displayName = "SlotClone";
|
|
544
553
|
const Ye = ({ children: e }) => /* @__PURE__ */ _(K, null, e);
|
|
545
554
|
function Ke(e) {
|
|
546
|
-
return /* @__PURE__ */
|
|
555
|
+
return /* @__PURE__ */ k(e) && e.type === Ye;
|
|
547
556
|
}
|
|
548
557
|
function Qe(e, n) {
|
|
549
558
|
const t = {
|
|
@@ -596,11 +605,11 @@ const er = [
|
|
|
596
605
|
...e,
|
|
597
606
|
[n]: t
|
|
598
607
|
};
|
|
599
|
-
}, {}), le = "Switch", [rr, mr] =
|
|
600
|
-
const { __scopeSwitch: t, name: a, checked: c, defaultChecked: r, required: o, disabled: u, value: i = "on", onCheckedChange: s, ...h } = e, [l, p] = $(null), v =
|
|
608
|
+
}, {}), le = "Switch", [rr, mr] = Fe(le), [tr, nr] = rr(le), or = /* @__PURE__ */ w((e, n) => {
|
|
609
|
+
const { __scopeSwitch: t, name: a, checked: c, defaultChecked: r, required: o, disabled: u, value: i = "on", onCheckedChange: s, ...h } = e, [l, p] = $(null), v = qe(
|
|
601
610
|
n,
|
|
602
611
|
(m) => p(m)
|
|
603
|
-
), f =
|
|
612
|
+
), f = C(!1), g = l ? !!l.closest("form") : !0, [d = !1, b] = Ve({
|
|
604
613
|
prop: c,
|
|
605
614
|
defaultProp: r,
|
|
606
615
|
onChange: s
|
|
@@ -620,9 +629,9 @@ const er = [
|
|
|
620
629
|
value: i
|
|
621
630
|
}, h, {
|
|
622
631
|
ref: v,
|
|
623
|
-
onClick:
|
|
632
|
+
onClick: ze(e.onClick, (m) => {
|
|
624
633
|
b(
|
|
625
|
-
(
|
|
634
|
+
(A) => !A
|
|
626
635
|
), g && (f.current = m.isPropagationStopped(), f.current || m.stopPropagation());
|
|
627
636
|
})
|
|
628
637
|
})), g && /* @__PURE__ */ _(ur, {
|
|
@@ -646,7 +655,7 @@ const er = [
|
|
|
646
655
|
ref: n
|
|
647
656
|
}));
|
|
648
657
|
}), ur = (e) => {
|
|
649
|
-
const { control: n, checked: t, bubbles: a = !0, ...c } = e, r =
|
|
658
|
+
const { control: n, checked: t, bubbles: a = !0, ...c } = e, r = C(null), o = Ge(t), u = Je(n);
|
|
650
659
|
return D(() => {
|
|
651
660
|
const i = r.current, s = window.HTMLInputElement.prototype, l = Object.getOwnPropertyDescriptor(s, "checked").set;
|
|
652
661
|
if (o !== t && l) {
|
|
@@ -720,7 +729,7 @@ var de = { exports: {} };
|
|
|
720
729
|
})();
|
|
721
730
|
})(de);
|
|
722
731
|
var pr = de.exports;
|
|
723
|
-
const
|
|
732
|
+
const q = /* @__PURE__ */ lr(pr), S = {
|
|
724
733
|
"purpur-toggle": "_purpur-toggle_1xng6_1",
|
|
725
734
|
"purpur-toggle__track": "_purpur-toggle__track_1xng6_7",
|
|
726
735
|
"purpur-toggle__checkmark-container": "_purpur-toggle__checkmark-container_1xng6_45",
|
|
@@ -746,38 +755,38 @@ const F = /* @__PURE__ */ lr(pr), S = {
|
|
|
746
755
|
const m = Y(b.nativeEvent) ? b.nativeEvent.touches[0].clientX : b.nativeEvent.clientX;
|
|
747
756
|
l(m), t == null || t();
|
|
748
757
|
}
|
|
749
|
-
}, g =
|
|
758
|
+
}, g = X(
|
|
750
759
|
(b) => {
|
|
751
760
|
if (typeof h != "number")
|
|
752
761
|
return;
|
|
753
|
-
const
|
|
754
|
-
if (!
|
|
762
|
+
const A = (Y(b) ? b.touches[0].clientX : b.clientX) - h;
|
|
763
|
+
if (!A)
|
|
755
764
|
return;
|
|
756
|
-
const
|
|
757
|
-
!p && Math.abs(
|
|
758
|
-
const
|
|
759
|
-
s(
|
|
765
|
+
const O = o + A;
|
|
766
|
+
!p && Math.abs(O) && v(!0);
|
|
767
|
+
const B = O > r.right ? r.right : O < r.left ? r.left : O;
|
|
768
|
+
s(B), a == null || a({ x: B });
|
|
760
769
|
},
|
|
761
770
|
[a, s, p, h]
|
|
762
|
-
), d =
|
|
771
|
+
), d = X(() => {
|
|
763
772
|
l(void 0), s(void 0), v(!1), c == null || c();
|
|
764
773
|
}, [c, l]);
|
|
765
774
|
return D(() => (window.addEventListener("mousemove", g), window.addEventListener("touchmove", g), () => {
|
|
766
775
|
window.removeEventListener("mousemove", g), window.removeEventListener("touchmove", g);
|
|
767
776
|
}), [g]), D(() => (window.addEventListener("mouseup", d), window.addEventListener("touchend", d), () => {
|
|
768
777
|
window.removeEventListener("mouseup", d), window.removeEventListener("touchend", d);
|
|
769
|
-
}), [d]),
|
|
778
|
+
}), [d]), k(e) ? L(y.only(e), {
|
|
770
779
|
onMouseDown: f,
|
|
771
780
|
onTouchStart: f,
|
|
772
781
|
style: { ...u, transform: `translateX(${p ? i : o}px)` }
|
|
773
782
|
}) : null;
|
|
774
783
|
}, fr = ({ checked: e, onChange: n }) => {
|
|
775
|
-
var
|
|
776
|
-
const t =
|
|
784
|
+
var V, W;
|
|
785
|
+
const t = C(null), a = C(null), [c, r] = $(void 0), [o, u] = $(!1), [i, s] = $(0), [h, l] = $(0), [p, v] = $(0);
|
|
777
786
|
Q(() => {
|
|
778
|
-
var
|
|
779
|
-
l(((
|
|
780
|
-
}, [(
|
|
787
|
+
var R, T;
|
|
788
|
+
l(((R = a.current) == null ? void 0 : R.clientHeight) || 0), v(((T = t.current) == null ? void 0 : T.clientHeight) || 0);
|
|
789
|
+
}, [(V = a.current) == null ? void 0 : V.clientHeight, (W = t.current) == null ? void 0 : W.clientHeight]);
|
|
781
790
|
const f = (p || 0) - h, g = h + f, d = f / 2, b = g / 2, m = typeof c == "number" && (e ? c < b : c > b);
|
|
782
791
|
return {
|
|
783
792
|
trackRef: t,
|
|
@@ -785,8 +794,8 @@ const F = /* @__PURE__ */ lr(pr), S = {
|
|
|
785
794
|
isDragging: o,
|
|
786
795
|
bounds: { left: d, right: g },
|
|
787
796
|
position: e ? g : d,
|
|
788
|
-
onDrag: ({ x:
|
|
789
|
-
r(
|
|
797
|
+
onDrag: ({ x: R }) => {
|
|
798
|
+
r(R), Math.abs((e ? g : d) - R) > 2 && u(!0);
|
|
790
799
|
},
|
|
791
800
|
onStop: () => {
|
|
792
801
|
u(!1), o && s(Date.now()), m && (n == null || n(!e));
|
|
@@ -795,7 +804,7 @@ const F = /* @__PURE__ */ lr(pr), S = {
|
|
|
795
804
|
Date.now() - i > 50 && (n == null || n(!e)), r(void 0);
|
|
796
805
|
}
|
|
797
806
|
};
|
|
798
|
-
},
|
|
807
|
+
}, P = "purpur-toggle", gr = ({
|
|
799
808
|
["data-testid"]: e,
|
|
800
809
|
className: n,
|
|
801
810
|
label: t,
|
|
@@ -810,8 +819,8 @@ const F = /* @__PURE__ */ lr(pr), S = {
|
|
|
810
819
|
typeof r == "boolean" ? r : !!u
|
|
811
820
|
), p = !!(typeof r == "boolean" ? r : h), { thumbRef: v, trackRef: f, isDragging: g, onChangeWithDrag: d, ...b } = fr({
|
|
812
821
|
checked: p,
|
|
813
|
-
onChange: (
|
|
814
|
-
i.disabled || (a == null || a(
|
|
822
|
+
onChange: (A) => {
|
|
823
|
+
i.disabled || (a == null || a(A), l(A));
|
|
815
824
|
}
|
|
816
825
|
}), m = () => /* @__PURE__ */ x(
|
|
817
826
|
He,
|
|
@@ -819,14 +828,14 @@ const F = /* @__PURE__ */ lr(pr), S = {
|
|
|
819
828
|
htmlFor: i.id,
|
|
820
829
|
"data-testid": e && `${e}-label`,
|
|
821
830
|
disabled: i.disabled,
|
|
822
|
-
className:
|
|
823
|
-
S[`${
|
|
824
|
-
S[`${
|
|
831
|
+
className: q(
|
|
832
|
+
S[`${P}__label`],
|
|
833
|
+
S[`${P}__label--${c}`]
|
|
825
834
|
),
|
|
826
835
|
children: /* @__PURE__ */ x(ae, { variant: "paragraph-100", disabled: i.disabled, children: t })
|
|
827
836
|
}
|
|
828
837
|
);
|
|
829
|
-
return /* @__PURE__ */
|
|
838
|
+
return /* @__PURE__ */ G("div", { className: q([n, S[`${P}__container`]]), children: [
|
|
830
839
|
t && c === "left" && m(),
|
|
831
840
|
/* @__PURE__ */ x(
|
|
832
841
|
ir,
|
|
@@ -835,14 +844,14 @@ const F = /* @__PURE__ */ lr(pr), S = {
|
|
|
835
844
|
ref: s,
|
|
836
845
|
id: i.id,
|
|
837
846
|
"data-testid": e,
|
|
838
|
-
className: S[
|
|
847
|
+
className: S[P],
|
|
839
848
|
onCheckedChange: d,
|
|
840
849
|
checked: p,
|
|
841
|
-
children: /* @__PURE__ */
|
|
842
|
-
/* @__PURE__ */ x("span", { className: S[`${
|
|
850
|
+
children: /* @__PURE__ */ G("span", { ref: f, className: S[`${P}__track`], children: [
|
|
851
|
+
/* @__PURE__ */ x("span", { className: S[`${P}__checkmark-container`], children: /* @__PURE__ */ x(
|
|
843
852
|
re,
|
|
844
853
|
{
|
|
845
|
-
className: S[`${
|
|
854
|
+
className: S[`${P}__checkmark`],
|
|
846
855
|
svg: ve,
|
|
847
856
|
size: "xxs"
|
|
848
857
|
}
|
|
@@ -852,10 +861,10 @@ const F = /* @__PURE__ */ lr(pr), S = {
|
|
|
852
861
|
{
|
|
853
862
|
ref: v,
|
|
854
863
|
"data-testid": e && `${e}-thumb`,
|
|
855
|
-
className:
|
|
856
|
-
S[`${
|
|
864
|
+
className: q([
|
|
865
|
+
S[`${P}__thumb`],
|
|
857
866
|
{
|
|
858
|
-
[S[`${
|
|
867
|
+
[S[`${P}__thumb--dragging`]]: g
|
|
859
868
|
}
|
|
860
869
|
])
|
|
861
870
|
}
|