seam-react 0.1.1 → 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 CHANGED
@@ -1,501 +1,630 @@
1
- import { jsxs as N, jsx as a } from "react/jsx-runtime";
2
- import { forwardRef as L, useId as S, useMemo as j, createContext as F, useContext as U, useRef as x, useSyncExternalStore as K, useEffect as z, useState as Q, useCallback as C } from "react";
3
- import { createPortal as q } from "react-dom";
4
- import { useControllableState as H, useEventCallback as Y, useLockBodyScroll as Z, useFocusTrap as ee } from "seam-hooks";
5
- function y(...t) {
6
- return t.filter(Boolean).join(" ");
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(" ");
7
8
  }
8
- const te = L(function({
9
- variant: n = "primary",
10
- size: i = "md",
9
+ const Y = y(function({
10
+ variant: e = "primary",
11
+ size: n = "md",
11
12
  loading: r = !1,
12
- iconOnly: l = !1,
13
- type: u = "button",
14
- className: s,
15
- children: h,
16
- ...o
13
+ iconOnly: a = !1,
14
+ type: s = "button",
15
+ className: i,
16
+ children: d,
17
+ ...u
17
18
  }, c) {
18
19
  return /* @__PURE__ */ N(
19
20
  "button",
20
21
  {
21
- ...o,
22
+ ...u,
22
23
  ref: c,
23
- type: u,
24
- className: y("uk-button", s),
25
- "data-variant": n,
26
- "data-size": i,
24
+ type: s,
25
+ className: h("uk-button", i),
26
+ "data-variant": e,
27
+ "data-size": n,
27
28
  "data-loading": r ? "true" : void 0,
28
- "data-icon-only": l ? "true" : void 0,
29
- disabled: o.disabled || r,
29
+ "data-icon-only": a ? "true" : void 0,
30
+ disabled: u.disabled || r,
30
31
  "aria-busy": r || void 0,
31
32
  children: [
32
- r ? /* @__PURE__ */ a("span", { className: "uk-button__spinner", "aria-hidden": "true" }) : null,
33
- h
33
+ r ? /* @__PURE__ */ l("span", { className: "uk-button__spinner", "aria-hidden": "true" }) : null,
34
+ d
34
35
  ]
35
36
  }
36
37
  );
37
- }), ke = L(function({
38
- inputSize: n = "md",
39
- invalid: i = !1,
38
+ }), Ae = y(function({
39
+ inputSize: e = "md",
40
+ invalid: n = !1,
40
41
  className: r,
41
- "aria-invalid": l,
42
- ...u
43
- }, s) {
44
- return /* @__PURE__ */ a(
42
+ "aria-invalid": a,
43
+ ...s
44
+ }, i) {
45
+ return /* @__PURE__ */ l(
45
46
  "input",
46
47
  {
47
- ...u,
48
- ref: s,
49
- className: y("uk-input", r),
50
- "data-size": n,
51
- "aria-invalid": i ? !0 : l
48
+ ...s,
49
+ ref: i,
50
+ className: h("uk-input", r),
51
+ "data-size": e,
52
+ "aria-invalid": n ? !0 : a
52
53
  }
53
54
  );
54
- }), Te = L(function({
55
- checked: n,
56
- defaultChecked: i,
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,
57
73
  onCheckedChange: r,
58
- disabled: l,
59
- className: u,
60
- children: s,
61
- id: h,
62
- ...o
74
+ disabled: a,
75
+ className: s,
76
+ children: i,
77
+ id: d,
78
+ ...u
63
79
  }, c) {
64
- const m = S(), g = h ?? m, [_, v] = H({
65
- value: n,
66
- defaultValue: i ?? !1,
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,
67
83
  onChange: r
68
- });
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
+ };
69
112
  return /* @__PURE__ */ N(
70
113
  "label",
71
114
  {
72
- className: y("uk-switch", u),
73
- "data-disabled": l ? "true" : void 0,
115
+ className: h("uk-switch", s),
116
+ "data-disabled": a ? "true" : void 0,
74
117
  htmlFor: g,
118
+ onClickCapture: (t) => {
119
+ b.current && (t.preventDefault(), t.stopPropagation());
120
+ },
75
121
  children: [
76
- /* @__PURE__ */ a(
122
+ /* @__PURE__ */ l(
77
123
  "input",
78
124
  {
79
- ...o,
125
+ ...u,
80
126
  ref: c,
81
127
  id: g,
82
128
  type: "checkbox",
83
129
  role: "switch",
84
130
  className: "uk-switch__input",
85
- checked: _,
86
- disabled: l,
87
- "aria-checked": _,
88
- onChange: (p) => v(p.target.checked)
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 } })
89
163
  }
90
164
  ),
91
- /* @__PURE__ */ a("span", { className: "uk-switch__track", "aria-hidden": "true", children: /* @__PURE__ */ a("span", { className: "uk-switch__thumb" }) }),
92
- s ? /* @__PURE__ */ a("span", { className: "uk-switch__label", children: s }) : null
165
+ i ? /* @__PURE__ */ l("span", { className: "uk-switch__label", children: i }) : null
93
166
  ]
94
167
  }
95
168
  );
96
- }), O = F(null);
97
- function V(t) {
98
- const n = U(O);
99
- if (!n)
100
- throw new Error(`<${t}> must be rendered inside <Tabs>`);
101
- return n;
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;
102
175
  }
103
- function W(t, n) {
104
- return `${t}-tab-${encodeURIComponent(n)}`;
176
+ function W(o, e) {
177
+ return `${o}-tab-${encodeURIComponent(e)}`;
105
178
  }
106
- function X(t, n) {
107
- return `${t}-panel-${encodeURIComponent(n)}`;
179
+ function J(o, e) {
180
+ return `${o}-panel-${encodeURIComponent(e)}`;
108
181
  }
109
- function ne({
110
- value: t,
111
- defaultValue: n,
112
- onValueChange: i,
182
+ function ke({
183
+ value: o,
184
+ defaultValue: e,
185
+ onValueChange: n,
113
186
  orientation: r = "horizontal",
114
- className: l,
115
- children: u
187
+ className: a,
188
+ children: s
116
189
  }) {
117
- const s = S(), [h, o] = H({
118
- value: t,
119
- defaultValue: n ?? "",
120
- onChange: i
121
- }), c = j(
122
- () => ({ baseId: s, value: h, setValue: o, orientation: r }),
123
- [s, h, r, o]
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]
124
203
  );
125
- return /* @__PURE__ */ a(O.Provider, { value: c, children: /* @__PURE__ */ a("div", { className: y("uk-tabs", l), "data-orientation": r, children: u }) });
204
+ return /* @__PURE__ */ l(G.Provider, { value: c, children: /* @__PURE__ */ l("div", { className: h("uk-tabs", a), "data-orientation": r, children: s }) });
126
205
  }
127
- const re = L(function({ className: n, onKeyDown: i, ...r }, l) {
128
- const { orientation: u } = V("Tabs.List");
129
- return /* @__PURE__ */ a(
206
+ const Ce = y(function({ className: e, onKeyDown: n, ...r }, a) {
207
+ const { orientation: s } = O("Tabs.List");
208
+ return /* @__PURE__ */ l(
130
209
  "div",
131
210
  {
132
211
  ...r,
133
- ref: l,
212
+ ref: a,
134
213
  role: "tablist",
135
- "aria-orientation": u,
214
+ "aria-orientation": s,
136
215
  tabIndex: -1,
137
- className: y("uk-tabs__list", n),
138
- onKeyDown: (s) => {
139
- if (i?.(s), s.defaultPrevented)
216
+ className: h("uk-tabs__list", e),
217
+ onKeyDown: (i) => {
218
+ if (n?.(i), i.defaultPrevented)
140
219
  return;
141
- const o = s.target?.closest('[role="tab"]');
142
- if (!o || o.hasAttribute("disabled"))
220
+ const u = i.target?.closest('[role="tab"]');
221
+ if (!u || u.hasAttribute("disabled"))
143
222
  return;
144
223
  const c = Array.from(
145
- s.currentTarget.querySelectorAll(
224
+ i.currentTarget.querySelectorAll(
146
225
  '[role="tab"]:not([disabled])'
147
226
  )
148
- ), m = c.indexOf(o);
149
- if (m === -1)
227
+ ), p = c.indexOf(u);
228
+ if (p === -1)
150
229
  return;
151
- const g = u === "horizontal" ? "ArrowRight" : "ArrowDown", _ = u === "horizontal" ? "ArrowLeft" : "ArrowUp";
152
- let v = -1;
153
- switch (s.key) {
230
+ const g = s === "horizontal" ? "ArrowRight" : "ArrowDown", k = s === "horizontal" ? "ArrowLeft" : "ArrowUp";
231
+ let b = -1;
232
+ switch (i.key) {
154
233
  case g:
155
- v = (m + 1) % c.length;
234
+ b = (p + 1) % c.length;
156
235
  break;
157
- case _:
158
- v = (m - 1 + c.length) % c.length;
236
+ case k:
237
+ b = (p - 1 + c.length) % c.length;
159
238
  break;
160
239
  case "Home":
161
- v = 0;
240
+ b = 0;
162
241
  break;
163
242
  case "End":
164
- v = c.length - 1;
243
+ b = c.length - 1;
165
244
  break;
166
245
  default:
167
246
  return;
168
247
  }
169
- s.preventDefault();
170
- const p = c[v];
171
- p && (p.focus(), p.click());
248
+ i.preventDefault();
249
+ const m = c[b];
250
+ m && (m.focus(), m.click());
172
251
  }
173
252
  }
174
253
  );
175
- }), ae = L(function({ value: n, type: i = "button", className: r, onClick: l, ...u }, s) {
176
- const h = V("Tabs.Trigger"), o = h.value === n;
177
- return /* @__PURE__ */ a(
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(
178
257
  "button",
179
258
  {
180
- ...u,
181
- ref: s,
182
- type: i,
259
+ ...i,
260
+ ref: d,
261
+ type: n,
183
262
  role: "tab",
184
- id: W(h.baseId, n),
185
- "aria-selected": o,
186
- "aria-controls": X(h.baseId, n),
187
- tabIndex: o ? 0 : -1,
188
- "data-state": o ? "active" : "inactive",
189
- className: y("uk-tabs__trigger", r),
190
- onClick: (c) => {
191
- l?.(c), c.defaultPrevented || h.setValue(n);
192
- }
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
+ ]
193
284
  }
194
285
  );
195
- }), se = L(function({ value: n, className: i, ...r }, l) {
196
- const u = V("Tabs.Content"), s = u.value === n;
197
- return /* @__PURE__ */ a(
286
+ }), Te = y(function({ value: e, className: n, ...r }, a) {
287
+ const s = O("Tabs.Content"), i = s.value === e;
288
+ return /* @__PURE__ */ l(
198
289
  "div",
199
290
  {
200
291
  ...r,
201
- ref: l,
292
+ ref: a,
202
293
  role: "tabpanel",
203
- id: X(u.baseId, n),
204
- "aria-labelledby": W(u.baseId, n),
205
- hidden: !s,
294
+ id: J(s.baseId, e),
295
+ "aria-labelledby": W(s.baseId, e),
296
+ hidden: !i,
206
297
  tabIndex: 0,
207
- "data-state": s ? "active" : "inactive",
208
- className: y("uk-tabs__panel", i)
298
+ "data-state": i ? "active" : "inactive",
299
+ className: h("uk-tabs__panel", n)
209
300
  }
210
301
  );
211
- }), _e = Object.assign(ne, {
212
- List: re,
213
- Trigger: ae,
214
- Content: se
215
- }), oe = () => () => {
216
- }, ie = () => !0, ce = () => !1;
217
- function Ce({
218
- open: t,
219
- onOpenChange: n,
220
- title: i,
221
- description: r,
222
- footer: l,
223
- children: u,
224
- closeLabel: s = "Close",
225
- showCloseButton: h = !0,
226
- closeOnBackdropClick: o = !0,
227
- closeOnEscape: c = !0,
228
- initialFocusRef: m,
229
- returnFocusRef: g,
230
- className: _,
231
- "aria-label": v
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
232
324
  }) {
233
- const p = x(null), w = x(null), k = x(t), R = S(), T = S(), E = K(
234
- oe,
235
- ie,
236
- ce
237
- ), I = Y(() => {
238
- k.current && n(!1);
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
+ })
239
356
  });
240
- return Z(t), z(() => {
241
- k.current = t;
242
- }, [t]), z(() => {
243
- const d = p.current;
244
- d && (t && !d.open ? (w.current = document.activeElement instanceof HTMLElement ? document.activeElement : null, typeof d.showModal == "function" ? d.showModal() : d.setAttribute("open", "")) : !t && d.open && (typeof d.close == "function" ? d.close() : d.removeAttribute("open")));
245
- }, [t]), ee({
246
- active: t,
247
- containerRef: p,
248
- initialFocusRef: m,
249
- returnFocusRef: g ?? w
250
- }), z(() => {
251
- const d = p.current;
252
- if (!d)
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)
253
448
  return;
254
- const A = () => I(), M = (e) => {
255
- c || e.preventDefault();
256
- }, $ = (e) => {
257
- o && e.target === d && I();
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();
258
463
  };
259
- return d.addEventListener("close", A), d.addEventListener("cancel", M), d.addEventListener("click", $), () => {
260
- d.removeEventListener("close", A), d.removeEventListener("cancel", M), d.removeEventListener("click", $);
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);
261
466
  };
262
- }, [o, c, I]), E ? q(
263
- /* @__PURE__ */ a(
264
- "dialog",
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,
265
524
  {
266
- ref: p,
267
- className: y("uk-dialog", _),
268
- "aria-label": v,
269
- "aria-labelledby": i ? R : void 0,
270
- "aria-describedby": r ? T : void 0,
271
- children: /* @__PURE__ */ N("div", { className: "uk-dialog__panel", children: [
272
- i || r || h ? /* @__PURE__ */ N("header", { className: "uk-dialog__header", children: [
273
- /* @__PURE__ */ N("div", { className: "uk-dialog__heading", children: [
274
- i ? /* @__PURE__ */ a("h2", { id: R, className: "uk-dialog__title", children: i }) : null,
275
- r ? /* @__PURE__ */ a("p", { id: T, className: "uk-dialog__description", children: r }) : null
276
- ] }),
277
- h ? /* @__PURE__ */ a(
278
- te,
279
- {
280
- variant: "ghost",
281
- size: "sm",
282
- iconOnly: !0,
283
- "aria-label": s,
284
- className: "uk-dialog__close",
285
- onClick: I,
286
- children: /* @__PURE__ */ a(
287
- "svg",
288
- {
289
- viewBox: "0 0 20 20",
290
- width: "16",
291
- height: "16",
292
- "aria-hidden": "true",
293
- children: /* @__PURE__ */ a(
294
- "path",
295
- {
296
- d: "M5 5l10 10M15 5L5 15",
297
- stroke: "currentColor",
298
- strokeWidth: "1.8",
299
- strokeLinecap: "round"
300
- }
301
- )
302
- }
303
- )
304
- }
305
- ) : null
306
- ] }) : null,
307
- /* @__PURE__ */ a("div", { className: "uk-dialog__body", children: u }),
308
- l ? /* @__PURE__ */ a("footer", { className: "uk-dialog__footer", children: l }) : null
309
- ] })
310
- }
311
- ),
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 }) }),
312
543
  document.body
313
544
  ) : null;
314
545
  }
315
- const G = F(null), le = 200, ue = () => () => {
316
- }, de = () => !0, fe = () => !1;
317
- function he({
318
- record: t,
319
- closeLabel: n,
320
- onDismiss: i,
321
- onPause: r,
322
- onResume: l
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
323
561
  }) {
324
- return /* @__PURE__ */ N(
325
- "div",
562
+ return /* @__PURE__ */ l(q, { open: o, onOpenChange: e, children: /* @__PURE__ */ N(
563
+ ie,
326
564
  {
327
- className: "uk-toast",
328
- "data-variant": t.variant,
329
- "data-state": t.leaving ? "closed" : "open",
330
- onMouseEnter: () => r(t.id),
331
- onMouseLeave: () => l(t.id),
332
- onFocusCapture: () => r(t.id),
333
- onBlurCapture: () => l(t.id),
565
+ className: k,
566
+ closeOnBackdropClick: u,
567
+ closeOnEscape: c,
568
+ initialFocusRef: p,
569
+ returnFocusRef: g,
570
+ "aria-label": b,
334
571
  children: [
335
- /* @__PURE__ */ N("div", { className: "uk-toast__body", children: [
336
- t.title ? /* @__PURE__ */ a("div", { className: "uk-toast__title", children: t.title }) : null,
337
- t.description ? /* @__PURE__ */ a("div", { className: "uk-toast__description", children: t.description }) : null
338
- ] }),
339
- /* @__PURE__ */ a(
340
- "button",
341
- {
342
- type: "button",
343
- className: "uk-toast__close",
344
- "aria-label": n,
345
- onClick: () => i(t.id),
346
- children: /* @__PURE__ */ a("svg", { viewBox: "0 0 20 20", width: "14", height: "14", "aria-hidden": "true", children: /* @__PURE__ */ a(
347
- "path",
348
- {
349
- d: "M5 5l10 10M15 5L5 15",
350
- stroke: "currentColor",
351
- strokeWidth: "1.8",
352
- strokeLinecap: "round"
353
- }
354
- ) })
355
- }
356
- )
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
357
608
  ]
358
609
  }
359
- );
360
- }
361
- function we({
362
- children: t,
363
- placement: n = "top-right",
364
- duration: i = 4e3,
365
- maxToasts: r = 4,
366
- label: l = "Notifications",
367
- closeLabel: u = "Close"
368
- }) {
369
- const [s, h] = Q([]), o = x([]), c = x(/* @__PURE__ */ new Map()), m = x(
370
- /* @__PURE__ */ new Map()
371
- ), g = x(
372
- /* @__PURE__ */ new Map()
373
- ), _ = x(0), v = S(), p = K(
374
- ue,
375
- de,
376
- fe
377
- ), w = C((e) => {
378
- o.current = e, h(e);
379
- }, []), k = C((e) => {
380
- const f = m.current.get(e);
381
- f !== void 0 && (clearTimeout(f), m.current.delete(e));
382
- }, []), R = C((e) => {
383
- const f = g.current.get(e);
384
- f !== void 0 && (clearTimeout(f), g.current.delete(e));
385
- }, []), T = C(
386
- (e) => {
387
- k(e), !(g.current.has(e) || !o.current.some((b) => b.id === e)) && (w(
388
- o.current.map(
389
- (b) => b.id === e ? { ...b, leaving: !0 } : b
390
- )
391
- ), g.current.set(
392
- e,
393
- setTimeout(() => {
394
- g.current.delete(e), c.current.delete(e), w(o.current.filter((b) => b.id !== e));
395
- }, le)
396
- ));
397
- },
398
- [k, w]
399
- ), E = C(
400
- (e, f) => {
401
- k(e), !(f <= 0) && m.current.set(
402
- e,
403
- setTimeout(() => {
404
- m.current.delete(e), T(e);
405
- }, f)
406
- );
407
- },
408
- [k, T]
409
- ), I = C(
410
- (e) => {
411
- const f = `${v}-${_.current}`;
412
- _.current += 1;
413
- const b = {
414
- id: f,
415
- title: e.title,
416
- description: e.description,
417
- variant: e.variant ?? "info",
418
- duration: e.duration ?? i,
419
- leaving: !1
420
- }, D = [...o.current, b], P = Math.max(0, D.length - r);
421
- (P > 0 ? D.slice(0, P) : []).forEach((B) => {
422
- k(B.id), R(B.id), c.current.delete(B.id);
423
- });
424
- const J = P > 0 ? D.slice(P) : D;
425
- return c.current.set(f, b.duration), w(J), E(f, b.duration), f;
426
- },
427
- [
428
- v,
429
- k,
430
- R,
431
- w,
432
- i,
433
- r,
434
- E
435
- ]
436
- ), d = C(
437
- (e) => {
438
- k(e);
439
- },
440
- [k]
441
- ), A = C(
442
- (e) => {
443
- const f = c.current.get(e);
444
- f !== void 0 && E(e, f);
445
- },
446
- [E]
447
- ), M = C(() => {
448
- o.current.forEach((e) => T(e.id));
449
- }, [T]), $ = j(
450
- () => ({ toast: I, dismiss: T, dismissAll: M }),
451
- [T, M, I]
452
- );
453
- return z(() => {
454
- const e = m.current, f = g.current;
455
- return () => {
456
- e.forEach((b) => clearTimeout(b)), f.forEach((b) => clearTimeout(b)), e.clear(), f.clear();
457
- };
458
- }, []), /* @__PURE__ */ N(G.Provider, { value: $, children: [
459
- t,
460
- p ? q(
461
- /* @__PURE__ */ a(
462
- "section",
463
- {
464
- className: "uk-toast-viewport",
465
- "data-placement": n,
466
- "aria-label": l,
467
- "aria-live": "polite",
468
- "aria-atomic": "false",
469
- children: s.map((e) => /* @__PURE__ */ a(
470
- he,
471
- {
472
- record: e,
473
- closeLabel: u,
474
- onDismiss: T,
475
- onPause: d,
476
- onResume: A
477
- },
478
- e.id
479
- ))
480
- }
481
- ),
482
- document.body
483
- ) : null
484
- ] });
485
- }
486
- function xe() {
487
- const t = U(G);
488
- if (!t)
489
- throw new Error("useToast must be used within <ToastProvider>");
490
- return t;
610
+ ) });
491
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
+ });
492
623
  export {
493
- te as Button,
494
- Ce as Dialog,
495
- ke as Input,
496
- Te as Switch,
497
- _e as Tabs,
498
- we as ToastProvider,
499
- xe as useToast
624
+ Y as Button,
625
+ $e as Dialog,
626
+ Ae as Input,
627
+ He as Switch,
628
+ Oe as Tabs
500
629
  };
501
630
  //# sourceMappingURL=index.js.map