@overdoser/react-toolkit 0.16.0 → 0.17.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.
@@ -1,25 +1,25 @@
1
- import { jsx as d, jsxs as K } from "react/jsx-runtime";
2
- import { forwardRef as q, useRef as x, useId as G, useState as u, useEffect as w, useMemo as J, createContext as Q, useContext as h } from "react";
3
- import { createPortal as V } from "react-dom";
4
- import l from "clsx";
5
- import { useFocusTrap as X } from "../../hooks/useFocusTrap.js";
6
- import { useKeyboard as Y } from "../../hooks/useKeyboard.js";
1
+ import { jsx as c, jsxs as z } from "react/jsx-runtime";
2
+ import { forwardRef as q, useRef as T, useId as G, useState as u, useEffect as w, createContext as J, useContext as h } from "react";
3
+ import { createPortal as K } from "react-dom";
4
+ import d from "clsx";
5
+ import { useFocusTrap as Q } from "../../hooks/useFocusTrap.js";
6
+ import { useEscapeLayer as V, EscapeLayerProvider as X } from "../../hooks/useEscapeLayer.js";
7
7
  import t from "./Drawer.module.scss.js";
8
- const m = Q({ classes: {}, titleId: "" }), M = ({ children: e, className: a, style: s, onClose: o }) => {
9
- const { classes: i, titleId: y } = h(m);
10
- return /* @__PURE__ */ K(
8
+ const m = J({ classes: {}, titleId: "" }), x = ({ children: e, className: s, style: a, onClose: o }) => {
9
+ const { classes: i, titleId: p } = h(m);
10
+ return /* @__PURE__ */ z(
11
11
  "div",
12
12
  {
13
- id: y,
14
- className: l(t.header, o && t.headerWithClose, i.header, a),
15
- style: s,
13
+ id: p,
14
+ className: d(t.header, o && t.headerWithClose, i.header, s),
15
+ style: a,
16
16
  children: [
17
17
  e,
18
- o && /* @__PURE__ */ d(
18
+ o && /* @__PURE__ */ c(
19
19
  "button",
20
20
  {
21
21
  type: "button",
22
- className: l(t.closeButton, i.closeButton),
22
+ className: d(t.closeButton, i.closeButton),
23
23
  onClick: o,
24
24
  "aria-label": "Close",
25
25
  children: "×"
@@ -29,91 +29,90 @@ const m = Q({ classes: {}, titleId: "" }), M = ({ children: e, className: a, sty
29
29
  }
30
30
  );
31
31
  };
32
- M.displayName = "Drawer.Header";
33
- const R = ({ children: e, className: a, style: s }) => {
32
+ x.displayName = "Drawer.Header";
33
+ const R = ({ children: e, className: s, style: a }) => {
34
34
  const { classes: o } = h(m);
35
- return /* @__PURE__ */ d("div", { className: l(t.body, o.body, a), style: s, children: e });
35
+ return /* @__PURE__ */ c("div", { className: d(t.body, o.body, s), style: a, children: e });
36
36
  };
37
37
  R.displayName = "Drawer.Body";
38
- const _ = ({ children: e, className: a, style: s }) => {
38
+ const M = ({ children: e, className: s, style: a }) => {
39
39
  const { classes: o } = h(m);
40
- return /* @__PURE__ */ d("div", { className: l(t.footer, o.footer, a), style: s, children: e });
40
+ return /* @__PURE__ */ c("div", { className: d(t.footer, o.footer, s), style: a, children: e });
41
41
  };
42
- _.displayName = "Drawer.Footer";
43
- const Z = 340, f = q(
42
+ M.displayName = "Drawer.Footer";
43
+ const Y = 340, f = q(
44
44
  ({
45
45
  open: e,
46
- onClose: a,
47
- side: s = "right",
46
+ onClose: s,
47
+ side: a = "right",
48
48
  size: o = "md",
49
49
  variant: i = "temporary",
50
- closeOnBackdrop: y = !0,
51
- closeOnEscape: N = !0,
52
- classes: p,
53
- className: $,
54
- style: A,
55
- children: C,
56
- "aria-label": k,
57
- "aria-labelledby": F
50
+ closeOnBackdrop: p = !0,
51
+ closeOnEscape: C = !0,
52
+ classes: y,
53
+ className: _,
54
+ style: $,
55
+ children: A,
56
+ "aria-label": N,
57
+ "aria-labelledby": E
58
58
  }, n) => {
59
- const B = x(null), H = (r) => {
59
+ const B = T(null), F = (r) => {
60
60
  B.current = r, typeof n == "function" ? n(r) : n && (n.current = r);
61
- }, O = G(), g = F ?? `${O}-title`, b = i === "temporary", [c, D] = u(e), [I, S] = u(!1), [T, j] = u(s), [E, P] = u(o);
61
+ }, O = G(), g = E ?? `${O}-title`, b = i === "temporary", [l, k] = u(e), [D, I] = u(!1), [S, H] = u(a), [P, j] = u(o);
62
62
  w(() => {
63
- e && (D(!0), S(!1), j(s), P(o));
64
- }, [e, s, o]), w(() => {
65
- if (e || !c) return;
66
- S(!0);
67
- const r = setTimeout(() => D(!1), Z);
63
+ e && (k(!0), I(!1), H(a), j(o));
64
+ }, [e, a, o]), w(() => {
65
+ if (e || !l) return;
66
+ I(!0);
67
+ const r = setTimeout(() => k(!1), Y);
68
68
  return () => clearTimeout(r);
69
- }, [e, c]), X(B, c && e && b);
70
- const U = J(
71
- () => ({ Escape: () => N && a() }),
72
- [N, a]
73
- );
74
- Y(U, e), w(() => {
75
- if (!c) return;
69
+ }, [e, l]), Q(B, l && e && b);
70
+ const L = V(() => {
71
+ C && s();
72
+ }, e);
73
+ w(() => {
74
+ if (!l) return;
76
75
  const r = document.body.style.overflow;
77
76
  return document.body.style.overflow = "hidden", () => {
78
77
  document.body.style.overflow = r;
79
78
  };
80
- }, [c]);
81
- const v = x(!1), W = (r) => {
79
+ }, [l]);
80
+ const v = T(!1), U = (r) => {
82
81
  v.current = r.target === r.currentTarget;
83
- }, z = (r) => {
84
- y && v.current && r.target === r.currentTarget && a(), v.current = !1;
82
+ }, W = (r) => {
83
+ p && v.current && r.target === r.currentTarget && s(), v.current = !1;
85
84
  };
86
- return c ? V(
87
- /* @__PURE__ */ d(
85
+ return l ? K(
86
+ /* @__PURE__ */ c(
88
87
  "div",
89
88
  {
90
- className: l(
89
+ className: d(
91
90
  t.backdrop,
92
- I && t.backdropClosing,
91
+ D && t.backdropClosing,
93
92
  !b && t.backdropBare,
94
- p?.backdrop
93
+ y?.backdrop
95
94
  ),
96
- onMouseDown: W,
97
- onMouseUp: z,
95
+ onMouseDown: U,
96
+ onMouseUp: W,
98
97
  role: "presentation",
99
- children: /* @__PURE__ */ d(
98
+ children: /* @__PURE__ */ c(
100
99
  "div",
101
100
  {
102
- ref: H,
103
- className: l(
101
+ ref: F,
102
+ className: d(
104
103
  t.drawer,
105
- t[`side_${T}`],
106
- t[`size_${E}`],
107
- t[`${I ? "slideOut" : "slideIn"}_${T}`],
108
- p?.drawer,
109
- $
104
+ t[`side_${S}`],
105
+ t[`size_${P}`],
106
+ t[`${D ? "slideOut" : "slideIn"}_${S}`],
107
+ y?.drawer,
108
+ _
110
109
  ),
111
- style: A,
110
+ style: $,
112
111
  role: "dialog",
113
112
  "aria-modal": b ? "true" : void 0,
114
- "aria-label": k,
115
- "aria-labelledby": k ? void 0 : g,
116
- children: /* @__PURE__ */ d(m.Provider, { value: { classes: p ?? {}, titleId: g }, children: C })
113
+ "aria-label": N,
114
+ "aria-labelledby": N ? void 0 : g,
115
+ children: /* @__PURE__ */ c(m.Provider, { value: { classes: y ?? {}, titleId: g }, children: /* @__PURE__ */ c(X, { value: L, children: A }) })
117
116
  }
118
117
  )
119
118
  }
@@ -123,9 +122,9 @@ const Z = 340, f = q(
123
122
  }
124
123
  );
125
124
  f.displayName = "Drawer";
126
- f.Header = M;
125
+ f.Header = x;
127
126
  f.Body = R;
128
- f.Footer = _;
127
+ f.Footer = M;
129
128
  export {
130
129
  f as Drawer
131
130
  };
@@ -1,11 +1,11 @@
1
- import { jsx as f, jsxs as p } from "react/jsx-runtime";
2
- import { forwardRef as G, useState as H, useRef as b, useId as J, useEffect as S, useCallback as v } from "react";
3
- import { createPortal as Q } from "react-dom";
1
+ import { jsx as d, jsxs as p } from "react/jsx-runtime";
2
+ import { forwardRef as J, useState as K, useRef as v, useId as Q, useEffect as S, useCallback as b } from "react";
3
+ import { createPortal as T } from "react-dom";
4
4
  import o from "clsx";
5
5
  import t from "./Dropdown.module.scss.js";
6
- import { useKeyboard as T } from "../../hooks/useKeyboard.js";
7
- import { usePortalPosition as U } from "../../hooks/usePortalPosition.js";
8
- const V = G(
6
+ import { useEscapeLayer as U, EscapeLayerProvider as V } from "../../hooks/useEscapeLayer.js";
7
+ import { usePortalPosition as X } from "../../hooks/usePortalPosition.js";
8
+ const Y = J(
9
9
  ({
10
10
  trigger: k,
11
11
  children: D,
@@ -14,47 +14,42 @@ const V = G(
14
14
  style: z,
15
15
  id: O,
16
16
  onOpen: y,
17
- onClose: c,
17
+ onClose: s,
18
18
  options: i,
19
19
  placeholder: W = "Select...",
20
- value: w,
21
- onChange: x,
20
+ value: L,
21
+ onChange: w,
22
22
  error: q = !1,
23
- fullWidth: s = !0,
23
+ fullWidth: a = !0,
24
24
  portal: u = !0,
25
25
  classes: n
26
- }, K) => {
27
- const [r, N] = H(!1), E = b(null), a = b(null), h = b(null), I = J();
26
+ }, M) => {
27
+ const [r, x] = K(!1), E = v(null), m = v(null), h = v(null), N = Q();
28
28
  S(() => {
29
- r && a.current && a.current.querySelector('[role="menuitem"]:not(:disabled)')?.focus();
29
+ r && m.current && m.current.querySelector('[role="menuitem"]:not(:disabled)')?.focus();
30
30
  }, [r]);
31
- const l = v(() => {
32
- N(!1), c?.(), h.current?.focus();
33
- }, [c]), M = v(() => {
34
- N((e) => {
35
- const m = !e;
36
- return m ? y?.() : c?.(), m;
31
+ const c = b(() => {
32
+ x(!1), s?.(), h.current?.focus();
33
+ }, [s]), A = b(() => {
34
+ x((e) => {
35
+ const f = !e;
36
+ return f ? y?.() : s?.(), f;
37
37
  });
38
- }, [y, c]), A = v(
38
+ }, [y, s]), B = b(
39
39
  (e) => {
40
- x?.(e), l();
40
+ w?.(e), c();
41
41
  },
42
- [x, l]
42
+ [w, c]
43
43
  );
44
44
  S(() => {
45
45
  if (!r) return;
46
- const e = (m) => {
47
- const P = m.target;
48
- E.current?.contains(P) || a.current?.contains(P) || l();
46
+ const e = (f) => {
47
+ const R = f.target;
48
+ E.current?.contains(R) || m.current?.contains(R) || c();
49
49
  };
50
50
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
51
- }, [r, l]), T(
52
- {
53
- Escape: () => l()
54
- },
55
- r
56
- );
57
- const d = U(h, r && u), L = i?.find((e) => e.value === w)?.label, B = i ? L || W : k, C = i && !L, F = i ? i.map((e) => /* @__PURE__ */ f(
51
+ }, [r, c]);
52
+ const C = U(c, r), l = X(h, r && u), I = i?.find((e) => e.value === L)?.label, F = i ? I || W : k, G = i && !I, H = i ? i.map((e) => /* @__PURE__ */ d(
58
53
  "button",
59
54
  {
60
55
  type: "button",
@@ -62,39 +57,39 @@ const V = G(
62
57
  className: o(
63
58
  t.item,
64
59
  e.disabled && t.itemDisabled,
65
- e.value === w && t.itemSelected,
60
+ e.value === L && t.itemSelected,
66
61
  n?.item
67
62
  ),
68
63
  disabled: e.disabled,
69
- onClick: () => A(e.value),
64
+ onClick: () => B(e.value),
70
65
  children: e.label
71
66
  },
72
67
  e.value
73
- )) : D, R = (e) => /* @__PURE__ */ f(
68
+ )) : D, P = (e) => /* @__PURE__ */ d(
74
69
  "div",
75
70
  {
76
- ref: a,
77
- id: I,
71
+ ref: m,
72
+ id: N,
78
73
  className: o(
79
74
  t.menu,
80
75
  r && t.menuOpen,
81
76
  g === "left" ? t.alignLeft : t.alignRight,
82
- !u && s && t.fullWidth,
77
+ !u && a && t.fullWidth,
83
78
  n?.menu
84
79
  ),
85
80
  style: e,
86
81
  role: "menu",
87
- children: F
82
+ children: /* @__PURE__ */ d(V, { value: C, children: H })
88
83
  }
89
84
  );
90
85
  return /* @__PURE__ */ p(
91
86
  "div",
92
87
  {
93
- ref: K,
94
- className: o(t.root, s && t.fullWidth, n?.root, j),
88
+ ref: M,
89
+ className: o(t.root, a && t.fullWidth, n?.root, j),
95
90
  style: z,
96
91
  children: [
97
- /* @__PURE__ */ p("div", { ref: E, style: s ? { width: "100%" } : void 0, children: [
92
+ /* @__PURE__ */ p("div", { ref: E, style: a ? { width: "100%" } : void 0, children: [
98
93
  /* @__PURE__ */ p(
99
94
  "button",
100
95
  {
@@ -105,32 +100,32 @@ const V = G(
105
100
  t.trigger,
106
101
  r && t.triggerOpen,
107
102
  q && t.triggerError,
108
- s && t.fullWidth,
103
+ a && t.fullWidth,
109
104
  n?.trigger
110
105
  ),
111
- onClick: M,
106
+ onClick: A,
112
107
  "aria-expanded": r,
113
108
  "aria-haspopup": "menu",
114
- "aria-controls": r ? I : void 0,
109
+ "aria-controls": r ? N : void 0,
115
110
  children: [
116
- /* @__PURE__ */ f("span", { className: o(t.triggerLabel, C && t.placeholder, n?.triggerLabel), children: B }),
117
- /* @__PURE__ */ f("span", { className: o(t.chevron, n?.chevron), "aria-hidden": "true" })
111
+ /* @__PURE__ */ d("span", { className: o(t.triggerLabel, G && t.placeholder, n?.triggerLabel), children: F }),
112
+ /* @__PURE__ */ d("span", { className: o(t.chevron, n?.chevron), "aria-hidden": "true" })
118
113
  ]
119
114
  }
120
115
  ),
121
- !u && R()
116
+ !u && P()
122
117
  ] }),
123
- u && r && typeof document < "u" && Q(
124
- R({
118
+ u && r && typeof document < "u" && T(
119
+ P({
125
120
  position: "fixed",
126
- top: d.top + 4,
127
- left: g === "right" ? void 0 : d.left,
121
+ top: l.top + 4,
122
+ left: g === "right" ? void 0 : l.left,
128
123
  // clientWidth, not innerWidth: `right` on a fixed element is
129
124
  // measured from the viewport edge inside the scrollbar, while
130
125
  // innerWidth includes it — the menu would shift left by the
131
126
  // scrollbar width whenever the page scrolls.
132
- right: g === "right" ? document.documentElement.clientWidth - (d.left + d.width) : void 0,
133
- minWidth: d.width,
127
+ right: g === "right" ? document.documentElement.clientWidth - (l.left + l.width) : void 0,
128
+ minWidth: l.width,
134
129
  zIndex: "var(--crk-z-floating)"
135
130
  }),
136
131
  document.body
@@ -140,7 +135,7 @@ const V = G(
140
135
  );
141
136
  }
142
137
  );
143
- V.displayName = "Dropdown";
138
+ Y.displayName = "Dropdown";
144
139
  export {
145
- V as Dropdown
140
+ Y as Dropdown
146
141
  };
@@ -1,26 +1,26 @@
1
- import { jsx as l, jsxs as T } from "react/jsx-runtime";
2
- import { forwardRef as j, useRef as v, useId as D, useMemo as P, useEffect as U, createContext as E, useContext as y } from "react";
3
- import { createPortal as K } from "react-dom";
1
+ import { jsx as l, jsxs as E } from "react/jsx-runtime";
2
+ import { forwardRef as H, useRef as h, useId as P, useEffect as j, createContext as D, useContext as p } from "react";
3
+ import { createPortal as L } from "react-dom";
4
4
  import d from "clsx";
5
5
  import { useFocusTrap as O } from "../../hooks/useFocusTrap.js";
6
- import { useKeyboard as S } from "../../hooks/useKeyboard.js";
6
+ import { useEscapeLayer as U, EscapeLayerProvider as S } from "../../hooks/useEscapeLayer.js";
7
7
  import a from "./Modal.module.scss.js";
8
- const u = E({ classes: {}, titleId: "" }), M = ({ children: e, className: r, style: s, onClose: t }) => {
9
- const { classes: n, titleId: c } = y(u);
10
- return /* @__PURE__ */ T(
8
+ const u = D({ classes: {}, titleId: "" }), M = ({ children: e, className: t, style: s, onClose: r }) => {
9
+ const { classes: n, titleId: c } = p(u);
10
+ return /* @__PURE__ */ E(
11
11
  "div",
12
12
  {
13
13
  id: c,
14
- className: d(a.header, t && a.headerWithClose, n.header, r),
14
+ className: d(a.header, r && a.headerWithClose, n.header, t),
15
15
  style: s,
16
16
  children: [
17
17
  e,
18
- t && /* @__PURE__ */ l(
18
+ r && /* @__PURE__ */ l(
19
19
  "button",
20
20
  {
21
21
  type: "button",
22
22
  className: d(a.closeButton, n.closeButton),
23
- onClick: t,
23
+ onClick: r,
24
24
  "aria-label": "Close",
25
25
  children: "×"
26
26
  }
@@ -30,73 +30,68 @@ const u = E({ classes: {}, titleId: "" }), M = ({ children: e, className: r, sty
30
30
  );
31
31
  };
32
32
  M.displayName = "Modal.Header";
33
- const N = ({ children: e, className: r, style: s }) => {
34
- const { classes: t } = y(u);
35
- return /* @__PURE__ */ l("div", { className: d(a.body, t.body, r), style: s, children: e });
33
+ const N = ({ children: e, className: t, style: s }) => {
34
+ const { classes: r } = p(u);
35
+ return /* @__PURE__ */ l("div", { className: d(a.body, r.body, t), style: s, children: e });
36
36
  };
37
37
  N.displayName = "Modal.Body";
38
- const B = ({ children: e, className: r, style: s }) => {
39
- const { classes: t } = y(u);
40
- return /* @__PURE__ */ l("div", { className: d(a.footer, t.footer, r), style: s, children: e });
38
+ const B = ({ children: e, className: t, style: s }) => {
39
+ const { classes: r } = p(u);
40
+ return /* @__PURE__ */ l("div", { className: d(a.footer, r.footer, t), style: s, children: e });
41
41
  };
42
42
  B.displayName = "Modal.Footer";
43
- const m = j(
43
+ const m = H(
44
44
  ({
45
45
  open: e,
46
- onClose: r,
46
+ onClose: t,
47
47
  closeOnBackdrop: s = !0,
48
- closeOnEscape: t = !0,
48
+ closeOnEscape: r = !0,
49
49
  size: n = "md",
50
50
  classes: c,
51
- className: k,
52
- style: w,
53
- children: x,
54
- "aria-label": p,
55
- "aria-labelledby": g
51
+ className: w,
52
+ style: x,
53
+ children: k,
54
+ "aria-label": y,
55
+ "aria-labelledby": C
56
56
  }, i) => {
57
- const b = v(null), C = (o) => {
57
+ const b = h(null), g = (o) => {
58
58
  b.current = o, typeof i == "function" ? i(o) : i && (i.current = o);
59
- }, I = D(), h = g ?? `${I}-title`;
59
+ }, I = P(), v = C ?? `${I}-title`;
60
60
  O(b, e);
61
- const F = P(
62
- () => ({
63
- Escape: () => {
64
- t && r();
65
- }
66
- }),
67
- [t, r]
68
- );
69
- S(F, e), U(() => {
61
+ const F = U(() => {
62
+ r && t();
63
+ }, e);
64
+ j(() => {
70
65
  if (!e) return;
71
66
  const o = document.body.style.overflow;
72
67
  return document.body.style.overflow = "hidden", () => {
73
68
  document.body.style.overflow = o;
74
69
  };
75
70
  }, [e]);
76
- const f = v(!1), H = (o) => {
71
+ const f = h(!1), R = (o) => {
77
72
  f.current = o.target === o.currentTarget;
78
- }, R = (o) => {
79
- s && f.current && o.target === o.currentTarget && r(), f.current = !1;
73
+ }, T = (o) => {
74
+ s && f.current && o.target === o.currentTarget && t(), f.current = !1;
80
75
  };
81
- return e ? K(
76
+ return e ? L(
82
77
  /* @__PURE__ */ l(
83
78
  "div",
84
79
  {
85
80
  className: d(a.backdrop, c?.backdrop),
86
- onMouseDown: H,
87
- onMouseUp: R,
81
+ onMouseDown: R,
82
+ onMouseUp: T,
88
83
  role: "presentation",
89
84
  children: /* @__PURE__ */ l(
90
85
  "div",
91
86
  {
92
- ref: C,
93
- className: d(a.modal, a[n], c?.modal, k),
94
- style: w,
87
+ ref: g,
88
+ className: d(a.modal, a[n], c?.modal, w),
89
+ style: x,
95
90
  role: "dialog",
96
91
  "aria-modal": "true",
97
- "aria-label": p,
98
- "aria-labelledby": p ? void 0 : h,
99
- children: /* @__PURE__ */ l(u.Provider, { value: { classes: c ?? {}, titleId: h }, children: x })
92
+ "aria-label": y,
93
+ "aria-labelledby": y ? void 0 : v,
94
+ children: /* @__PURE__ */ l(u.Provider, { value: { classes: c ?? {}, titleId: v }, children: /* @__PURE__ */ l(S, { value: F, children: k }) })
100
95
  }
101
96
  )
102
97
  }