seam-react 0.0.0-stage → 0.2.0

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 ADDED
@@ -0,0 +1,630 @@
1
+ import { jsxs as N, jsx as l } from "react/jsx-runtime";
2
+ import { forwardRef as y, useId as L, useRef as M, useEffect as R, useMemo as F, createContext as j, useContext as B, isValidElement as se, cloneElement as K, useSyncExternalStore as ce, useState as $, useLayoutEffect as le } from "react";
3
+ import { useReducedMotion as S, useMotionValue as ue, animate as V, motion as A, MotionConfig as de, AnimatePresence as fe, useIsPresent as pe } from "motion/react";
4
+ import { createPortal as ge } from "react-dom";
5
+ import { useControllableState as H, useEventCallback as be, useLockBodyScroll as he, useFocusTrap as me } from "seam-hooks";
6
+ function h(...o) {
7
+ return o.filter(Boolean).join(" ");
8
+ }
9
+ const Y = y(function({
10
+ variant: e = "primary",
11
+ size: n = "md",
12
+ loading: r = !1,
13
+ iconOnly: a = !1,
14
+ type: s = "button",
15
+ className: i,
16
+ children: d,
17
+ ...u
18
+ }, c) {
19
+ return /* @__PURE__ */ N(
20
+ "button",
21
+ {
22
+ ...u,
23
+ ref: c,
24
+ type: s,
25
+ className: h("uk-button", i),
26
+ "data-variant": e,
27
+ "data-size": n,
28
+ "data-loading": r ? "true" : void 0,
29
+ "data-icon-only": a ? "true" : void 0,
30
+ disabled: u.disabled || r,
31
+ "aria-busy": r || void 0,
32
+ children: [
33
+ r ? /* @__PURE__ */ l("span", { className: "uk-button__spinner", "aria-hidden": "true" }) : null,
34
+ d
35
+ ]
36
+ }
37
+ );
38
+ }), Ae = y(function({
39
+ inputSize: e = "md",
40
+ invalid: n = !1,
41
+ className: r,
42
+ "aria-invalid": a,
43
+ ...s
44
+ }, i) {
45
+ return /* @__PURE__ */ l(
46
+ "input",
47
+ {
48
+ ...s,
49
+ ref: i,
50
+ className: h("uk-input", r),
51
+ "data-size": e,
52
+ "aria-invalid": n ? !0 : a
53
+ }
54
+ );
55
+ }), Ie = [0.23, 1, 0.32, 1], U = {
56
+ type: "spring",
57
+ bounce: 0,
58
+ duration: 0.3
59
+ }, X = {
60
+ type: "spring",
61
+ bounce: 0.04,
62
+ duration: 0.38
63
+ }, ye = {
64
+ type: "spring",
65
+ bounce: 0.08,
66
+ duration: 0.34
67
+ }, z = {
68
+ duration: 0.12,
69
+ ease: Ie
70
+ }, He = y(function({
71
+ checked: e,
72
+ defaultChecked: n,
73
+ onCheckedChange: r,
74
+ disabled: a,
75
+ className: s,
76
+ children: i,
77
+ id: d,
78
+ ...u
79
+ }, c) {
80
+ const p = L(), g = d ?? p, k = S() ?? !1, b = M(!1), m = M(null), [C, _] = H({
81
+ value: e,
82
+ defaultValue: n ?? !1,
83
+ onChange: r
84
+ }), D = ue(C ? 16 : 0);
85
+ R(() => {
86
+ if (m.current)
87
+ return;
88
+ const t = V(
89
+ D,
90
+ C ? 16 : 0,
91
+ k ? { duration: 0 } : U
92
+ );
93
+ return () => t.stop();
94
+ }, [C, k, D]);
95
+ const v = (t) => {
96
+ const f = m.current;
97
+ if (!(!f || f.pointerId !== t.pointerId)) {
98
+ if (f.moved) {
99
+ const T = f.samples[0], x = f.samples[f.samples.length - 1], E = T && x ? Math.max(x.time - T.time, 1) : 1, w = T && x ? (x.x - T.x) / E * 1e3 : 0, I = Math.abs(w) > 220 ? w > 0 : D.get() >= 8;
100
+ b.current = !0, m.current = null, _(I), V(
101
+ D,
102
+ I ? 16 : 0,
103
+ k ? { duration: 0 } : { ...U, velocity: w }
104
+ ), window.setTimeout(() => {
105
+ b.current = !1;
106
+ }, 0);
107
+ } else
108
+ m.current = null;
109
+ t.currentTarget.hasPointerCapture(t.pointerId) && typeof t.currentTarget.releasePointerCapture == "function" && t.currentTarget.releasePointerCapture(t.pointerId);
110
+ }
111
+ };
112
+ return /* @__PURE__ */ N(
113
+ "label",
114
+ {
115
+ className: h("uk-switch", s),
116
+ "data-disabled": a ? "true" : void 0,
117
+ htmlFor: g,
118
+ onClickCapture: (t) => {
119
+ b.current && (t.preventDefault(), t.stopPropagation());
120
+ },
121
+ children: [
122
+ /* @__PURE__ */ l(
123
+ "input",
124
+ {
125
+ ...u,
126
+ ref: c,
127
+ id: g,
128
+ type: "checkbox",
129
+ role: "switch",
130
+ className: "uk-switch__input",
131
+ checked: C,
132
+ disabled: a,
133
+ "aria-checked": C,
134
+ onChange: (t) => _(t.target.checked)
135
+ }
136
+ ),
137
+ /* @__PURE__ */ l(
138
+ "span",
139
+ {
140
+ className: "uk-switch__track",
141
+ "aria-hidden": "true",
142
+ onPointerDown: (t) => {
143
+ a || (m.current = {
144
+ pointerId: t.pointerId,
145
+ startX: t.clientX,
146
+ startValue: D.get(),
147
+ moved: !1,
148
+ samples: [{ x: t.clientX, time: performance.now() }]
149
+ }, typeof t.currentTarget.setPointerCapture == "function" && t.currentTarget.setPointerCapture(t.pointerId));
150
+ },
151
+ onPointerMove: (t) => {
152
+ const f = m.current;
153
+ if (!f || f.pointerId !== t.pointerId)
154
+ return;
155
+ const T = t.clientX - f.startX;
156
+ Math.abs(T) > 4 && (f.moved = !0), f.moved && (t.preventDefault(), D.set(Math.max(0, Math.min(16, f.startValue + T))), f.samples.push({ x: t.clientX, time: performance.now() }), f.samples = f.samples.filter(
157
+ (x) => performance.now() - x.time < 120
158
+ ));
159
+ },
160
+ onPointerUp: v,
161
+ onPointerCancel: v,
162
+ children: /* @__PURE__ */ l(A.span, { className: "uk-switch__thumb", style: { x: D } })
163
+ }
164
+ ),
165
+ i ? /* @__PURE__ */ l("span", { className: "uk-switch__label", children: i }) : null
166
+ ]
167
+ }
168
+ );
169
+ }), G = j(null);
170
+ function O(o) {
171
+ const e = B(G);
172
+ if (!e)
173
+ throw new Error(`<${o}> must be rendered inside <Tabs>`);
174
+ return e;
175
+ }
176
+ function W(o, e) {
177
+ return `${o}-tab-${encodeURIComponent(e)}`;
178
+ }
179
+ function J(o, e) {
180
+ return `${o}-panel-${encodeURIComponent(e)}`;
181
+ }
182
+ function ke({
183
+ value: o,
184
+ defaultValue: e,
185
+ onValueChange: n,
186
+ orientation: r = "horizontal",
187
+ className: a,
188
+ children: s
189
+ }) {
190
+ const i = L(), [d, u] = H({
191
+ value: o,
192
+ defaultValue: e ?? "",
193
+ onChange: n
194
+ }), c = F(
195
+ () => ({
196
+ baseId: i,
197
+ value: d,
198
+ setValue: u,
199
+ orientation: r,
200
+ indicatorId: `${i}-indicator`
201
+ }),
202
+ [i, d, r, u]
203
+ );
204
+ return /* @__PURE__ */ l(G.Provider, { value: c, children: /* @__PURE__ */ l("div", { className: h("uk-tabs", a), "data-orientation": r, children: s }) });
205
+ }
206
+ const Ce = y(function({ className: e, onKeyDown: n, ...r }, a) {
207
+ const { orientation: s } = O("Tabs.List");
208
+ return /* @__PURE__ */ l(
209
+ "div",
210
+ {
211
+ ...r,
212
+ ref: a,
213
+ role: "tablist",
214
+ "aria-orientation": s,
215
+ tabIndex: -1,
216
+ className: h("uk-tabs__list", e),
217
+ onKeyDown: (i) => {
218
+ if (n?.(i), i.defaultPrevented)
219
+ return;
220
+ const u = i.target?.closest('[role="tab"]');
221
+ if (!u || u.hasAttribute("disabled"))
222
+ return;
223
+ const c = Array.from(
224
+ i.currentTarget.querySelectorAll(
225
+ '[role="tab"]:not([disabled])'
226
+ )
227
+ ), p = c.indexOf(u);
228
+ if (p === -1)
229
+ return;
230
+ const g = s === "horizontal" ? "ArrowRight" : "ArrowDown", k = s === "horizontal" ? "ArrowLeft" : "ArrowUp";
231
+ let b = -1;
232
+ switch (i.key) {
233
+ case g:
234
+ b = (p + 1) % c.length;
235
+ break;
236
+ case k:
237
+ b = (p - 1 + c.length) % c.length;
238
+ break;
239
+ case "Home":
240
+ b = 0;
241
+ break;
242
+ case "End":
243
+ b = c.length - 1;
244
+ break;
245
+ default:
246
+ return;
247
+ }
248
+ i.preventDefault();
249
+ const m = c[b];
250
+ m && (m.focus(), m.click());
251
+ }
252
+ }
253
+ );
254
+ }), De = y(function({ value: e, type: n = "button", className: r, onClick: a, children: s, ...i }, d) {
255
+ const u = O("Tabs.Trigger"), c = u.value === e, p = S() ?? !1;
256
+ return /* @__PURE__ */ N(
257
+ "button",
258
+ {
259
+ ...i,
260
+ ref: d,
261
+ type: n,
262
+ role: "tab",
263
+ id: W(u.baseId, e),
264
+ "aria-selected": c,
265
+ "aria-controls": J(u.baseId, e),
266
+ tabIndex: c ? 0 : -1,
267
+ "data-state": c ? "active" : "inactive",
268
+ className: h("uk-tabs__trigger", r),
269
+ onClick: (g) => {
270
+ a?.(g), g.defaultPrevented || u.setValue(e);
271
+ },
272
+ children: [
273
+ s,
274
+ c ? /* @__PURE__ */ l(
275
+ A.span,
276
+ {
277
+ className: "uk-tabs__indicator",
278
+ layoutId: u.indicatorId,
279
+ "aria-hidden": "true",
280
+ transition: p ? { duration: 0 } : ye
281
+ }
282
+ ) : null
283
+ ]
284
+ }
285
+ );
286
+ }), Te = y(function({ value: e, className: n, ...r }, a) {
287
+ const s = O("Tabs.Content"), i = s.value === e;
288
+ return /* @__PURE__ */ l(
289
+ "div",
290
+ {
291
+ ...r,
292
+ ref: a,
293
+ role: "tabpanel",
294
+ id: J(s.baseId, e),
295
+ "aria-labelledby": W(s.baseId, e),
296
+ hidden: !i,
297
+ tabIndex: 0,
298
+ "data-state": i ? "active" : "inactive",
299
+ className: h("uk-tabs__panel", n)
300
+ }
301
+ );
302
+ }), Oe = Object.assign(ke, {
303
+ List: Ce,
304
+ Trigger: De,
305
+ Content: Te
306
+ }), Q = j(null), xe = () => () => {
307
+ }, _e = () => !0, ve = () => !1;
308
+ function P(o) {
309
+ const e = B(Q);
310
+ if (!e)
311
+ throw new Error(`<${o}> must be rendered inside <Dialog.Root>`);
312
+ return e;
313
+ }
314
+ function Z(o, e) {
315
+ return (n) => {
316
+ o?.(n), n.defaultPrevented || e(n);
317
+ };
318
+ }
319
+ function q({
320
+ children: o,
321
+ open: e,
322
+ defaultOpen: n,
323
+ onOpenChange: r
324
+ }) {
325
+ const a = L(), [s, i] = $(!1), [d, u] = $(!1), [c, p] = H({
326
+ value: e,
327
+ defaultValue: n ?? !1,
328
+ onChange: r
329
+ }), g = F(
330
+ () => ({
331
+ open: c,
332
+ setOpen: p,
333
+ triggerId: `${a}-trigger`,
334
+ contentId: `${a}-content`,
335
+ titleId: `${a}-title`,
336
+ descriptionId: `${a}-description`,
337
+ hasTitle: s,
338
+ setHasTitle: i,
339
+ hasDescription: d,
340
+ setHasDescription: u
341
+ }),
342
+ [a, c, d, s, p]
343
+ );
344
+ return /* @__PURE__ */ l(Q.Provider, { value: g, children: o });
345
+ }
346
+ function we({ children: o }) {
347
+ const e = P("Dialog.Trigger"), n = o, r = n.props.onClick;
348
+ return K(n, {
349
+ id: e.triggerId,
350
+ "aria-haspopup": "dialog",
351
+ "aria-expanded": e.open,
352
+ "aria-controls": e.open ? e.contentId : void 0,
353
+ onClick: Z(r, () => {
354
+ e.setOpen(!e.open);
355
+ })
356
+ });
357
+ }
358
+ function ee({
359
+ children: o,
360
+ label: e = "Close"
361
+ }) {
362
+ const n = P("Dialog.Close");
363
+ if (se(o)) {
364
+ const r = o, a = r.props.onClick;
365
+ return K(r, {
366
+ onClick: Z(a, () => {
367
+ n.setOpen(!1);
368
+ })
369
+ });
370
+ }
371
+ return /* @__PURE__ */ l(Y, { variant: "ghost", onClick: () => n.setOpen(!1), children: e });
372
+ }
373
+ const te = y(function({ className: e, ...n }, r) {
374
+ return /* @__PURE__ */ l(
375
+ "header",
376
+ {
377
+ ...n,
378
+ ref: r,
379
+ className: h("uk-dialog__header", e)
380
+ }
381
+ );
382
+ }), ne = y(function({ className: e, children: n, ...r }, a) {
383
+ const s = P("Dialog.Title"), i = s.setHasTitle;
384
+ return R(() => (i(!0), () => i(!1)), [i]), /* @__PURE__ */ l(
385
+ "h2",
386
+ {
387
+ ...r,
388
+ ref: a,
389
+ id: s.titleId,
390
+ className: h("uk-dialog__title", e),
391
+ children: n
392
+ }
393
+ );
394
+ }), re = y(
395
+ function({ className: e, ...n }, r) {
396
+ const a = P("Dialog.Description"), s = a.setHasDescription;
397
+ return R(() => (s(!0), () => s(!1)), [s]), /* @__PURE__ */ l(
398
+ "p",
399
+ {
400
+ ...n,
401
+ ref: r,
402
+ id: a.descriptionId,
403
+ className: h("uk-dialog__description", e)
404
+ }
405
+ );
406
+ }
407
+ ), oe = y(function({ className: e, ...n }, r) {
408
+ return /* @__PURE__ */ l("div", { ...n, ref: r, className: h("uk-dialog__body", e) });
409
+ }), ae = y(function({ className: e, ...n }, r) {
410
+ return /* @__PURE__ */ l(
411
+ "footer",
412
+ {
413
+ ...n,
414
+ ref: r,
415
+ className: h("uk-dialog__footer", e)
416
+ }
417
+ );
418
+ });
419
+ function Ne({
420
+ requestClose: o,
421
+ contentId: e,
422
+ titleId: n,
423
+ descriptionId: r,
424
+ hasTitle: a,
425
+ hasDescription: s,
426
+ children: i,
427
+ closeOnBackdropClick: d = !0,
428
+ closeOnEscape: u = !0,
429
+ initialFocusRef: c,
430
+ returnFocusRef: p,
431
+ className: g,
432
+ "aria-label": k,
433
+ "aria-labelledby": b,
434
+ "aria-describedby": m
435
+ }) {
436
+ const C = M(null), _ = M(null), D = pe(), v = S() ?? !1;
437
+ return he(!0), le(() => {
438
+ const t = C.current;
439
+ t && (_.current ?? (_.current = document.activeElement instanceof HTMLElement ? document.activeElement : null), !t.open && (typeof t.showModal == "function" ? t.showModal() : t.setAttribute("open", "")));
440
+ }, []), me({
441
+ active: !0,
442
+ containerRef: C,
443
+ initialFocusRef: c,
444
+ returnFocusRef: p ?? _
445
+ }), R(() => {
446
+ const t = C.current;
447
+ if (!t)
448
+ return;
449
+ const f = () => {
450
+ t.open || (typeof t.showModal == "function" ? t.showModal() : t.setAttribute("open", ""));
451
+ }, T = () => {
452
+ if (!u) {
453
+ f();
454
+ return;
455
+ }
456
+ o();
457
+ }, x = (I) => {
458
+ I.preventDefault(), u && o();
459
+ }, E = (I) => {
460
+ u || I.key !== "Escape" || I.defaultPrevented || (I.preventDefault(), I.stopPropagation());
461
+ }, w = (I) => {
462
+ d && I.target === t && o();
463
+ };
464
+ return t.addEventListener("close", T), t.addEventListener("cancel", x), t.addEventListener("keydown", E, !0), t.addEventListener("click", w), () => {
465
+ t.removeEventListener("close", T), t.removeEventListener("cancel", x), t.removeEventListener("keydown", E, !0), t.removeEventListener("click", w);
466
+ };
467
+ }, [d, u, o]), /* @__PURE__ */ l(
468
+ "dialog",
469
+ {
470
+ ref: C,
471
+ id: e,
472
+ className: h("uk-dialog", g),
473
+ closedby: u || d ? "any" : "none",
474
+ "data-state": D ? "open" : "closed",
475
+ inert: !D,
476
+ "aria-label": k,
477
+ "aria-labelledby": b ?? (k ? void 0 : a ? n : void 0),
478
+ "aria-describedby": m ?? (s ? r : void 0),
479
+ children: /* @__PURE__ */ l(
480
+ A.div,
481
+ {
482
+ className: "uk-dialog__panel",
483
+ initial: v ? { opacity: 0 } : {
484
+ opacity: 0,
485
+ transform: "translateY(12px) scale(0.96)"
486
+ },
487
+ animate: {
488
+ opacity: 1,
489
+ transform: "translateY(0px) scale(1)",
490
+ transition: v ? z : { ...X, delay: 0.06 }
491
+ },
492
+ exit: v ? { opacity: 0, transition: z } : {
493
+ opacity: 0,
494
+ transform: "translateY(8px) scale(0.97)",
495
+ transition: X
496
+ },
497
+ children: i
498
+ }
499
+ )
500
+ }
501
+ );
502
+ }
503
+ function ie({
504
+ children: o,
505
+ closeOnBackdropClick: e = !0,
506
+ closeOnEscape: n = !0,
507
+ initialFocusRef: r,
508
+ returnFocusRef: a,
509
+ className: s,
510
+ "aria-label": i,
511
+ "aria-labelledby": d,
512
+ "aria-describedby": u
513
+ }) {
514
+ const c = P("Dialog.Content"), p = be(() => {
515
+ c.setOpen(!1);
516
+ });
517
+ return ce(
518
+ xe,
519
+ _e,
520
+ ve
521
+ ) ? ge(
522
+ /* @__PURE__ */ l(de, { reducedMotion: "user", children: /* @__PURE__ */ l(fe, { children: c.open ? /* @__PURE__ */ l(
523
+ Ne,
524
+ {
525
+ requestClose: p,
526
+ contentId: c.contentId,
527
+ titleId: c.titleId,
528
+ descriptionId: c.descriptionId,
529
+ hasTitle: c.hasTitle,
530
+ hasDescription: c.hasDescription,
531
+ closeOnBackdropClick: e,
532
+ closeOnEscape: n,
533
+ initialFocusRef: r,
534
+ returnFocusRef: a,
535
+ className: s,
536
+ "aria-label": i,
537
+ "aria-labelledby": d,
538
+ "aria-describedby": u,
539
+ children: o
540
+ },
541
+ "uk-dialog"
542
+ ) : null }) }),
543
+ document.body
544
+ ) : null;
545
+ }
546
+ function Pe({
547
+ open: o,
548
+ onOpenChange: e,
549
+ title: n,
550
+ description: r,
551
+ footer: a,
552
+ children: s,
553
+ closeLabel: i = "Close",
554
+ showCloseButton: d = !0,
555
+ closeOnBackdropClick: u = !0,
556
+ closeOnEscape: c = !0,
557
+ initialFocusRef: p,
558
+ returnFocusRef: g,
559
+ className: k,
560
+ "aria-label": b
561
+ }) {
562
+ return /* @__PURE__ */ l(q, { open: o, onOpenChange: e, children: /* @__PURE__ */ N(
563
+ ie,
564
+ {
565
+ className: k,
566
+ closeOnBackdropClick: u,
567
+ closeOnEscape: c,
568
+ initialFocusRef: p,
569
+ returnFocusRef: g,
570
+ "aria-label": b,
571
+ children: [
572
+ n || r || d ? /* @__PURE__ */ N(te, { children: [
573
+ /* @__PURE__ */ N("div", { className: "uk-dialog__heading", children: [
574
+ n ? /* @__PURE__ */ l(ne, { children: n }) : null,
575
+ r ? /* @__PURE__ */ l(re, { children: r }) : null
576
+ ] }),
577
+ d ? /* @__PURE__ */ l(ee, { children: /* @__PURE__ */ l(
578
+ Y,
579
+ {
580
+ variant: "ghost",
581
+ size: "sm",
582
+ iconOnly: !0,
583
+ "aria-label": i,
584
+ className: "uk-dialog__close",
585
+ children: /* @__PURE__ */ l(
586
+ "svg",
587
+ {
588
+ viewBox: "0 0 20 20",
589
+ width: "16",
590
+ height: "16",
591
+ "aria-hidden": "true",
592
+ children: /* @__PURE__ */ l(
593
+ "path",
594
+ {
595
+ d: "M5 5l10 10M15 5L5 15",
596
+ stroke: "currentColor",
597
+ strokeWidth: "1.8",
598
+ strokeLinecap: "round"
599
+ }
600
+ )
601
+ }
602
+ )
603
+ }
604
+ ) }) : null
605
+ ] }) : null,
606
+ /* @__PURE__ */ l(oe, { children: s }),
607
+ a ? /* @__PURE__ */ l(ae, { children: a }) : null
608
+ ]
609
+ }
610
+ ) });
611
+ }
612
+ const $e = Object.assign(Pe, {
613
+ Root: q,
614
+ Trigger: we,
615
+ Content: ie,
616
+ Header: te,
617
+ Title: ne,
618
+ Description: re,
619
+ Body: oe,
620
+ Footer: ae,
621
+ Close: ee
622
+ });
623
+ export {
624
+ Y as Button,
625
+ $e as Dialog,
626
+ Ae as Input,
627
+ He as Switch,
628
+ Oe as Tabs
629
+ };
630
+ //# sourceMappingURL=index.js.map