@overdoser/react-toolkit 0.8.0 → 0.8.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.
@@ -1,26 +1,26 @@
1
- import { jsx as l, jsxs as H } from "react/jsx-runtime";
2
- import { forwardRef as R, useRef as g, useId as T, useMemo as j, useEffect as P, createContext as E, useContext as u } from "react";
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
3
  import { createPortal as K } from "react-dom";
4
- import s from "clsx";
5
- import { useFocusTrap as W } from "../../hooks/useFocusTrap.js";
6
- import { useKeyboard as $ } from "../../hooks/useKeyboard.js";
7
- import r from "./Modal.module.scss.js";
8
- const n = E({ classes: {}, titleId: "" }), p = ({ children: e, className: t, style: a, onClose: o }) => {
9
- const { classes: i, titleId: d } = u(n);
10
- return /* @__PURE__ */ H(
4
+ import d from "clsx";
5
+ import { useFocusTrap as O } from "../../hooks/useFocusTrap.js";
6
+ import { useKeyboard as S } from "../../hooks/useKeyboard.js";
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(
11
11
  "div",
12
12
  {
13
- id: d,
14
- className: s(r.header, o && r.headerWithClose, i.header, t),
15
- style: a,
13
+ id: c,
14
+ className: d(a.header, t && a.headerWithClose, n.header, r),
15
+ style: s,
16
16
  children: [
17
17
  e,
18
- o && /* @__PURE__ */ l(
18
+ t && /* @__PURE__ */ l(
19
19
  "button",
20
20
  {
21
21
  type: "button",
22
- className: s(r.closeButton, i.closeButton),
23
- onClick: o,
22
+ className: d(a.closeButton, n.closeButton),
23
+ onClick: t,
24
24
  "aria-label": "Close",
25
25
  children: "×"
26
26
  }
@@ -29,69 +29,74 @@ const n = E({ classes: {}, titleId: "" }), p = ({ children: e, className: t, sty
29
29
  }
30
30
  );
31
31
  };
32
- p.displayName = "Modal.Header";
33
- const v = ({ children: e, className: t, style: a }) => {
34
- const { classes: o } = u(n);
35
- return /* @__PURE__ */ l("div", { className: s(r.body, o.body, t), style: a, children: e });
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 });
36
36
  };
37
- v.displayName = "Modal.Body";
38
- const h = ({ children: e, className: t, style: a }) => {
39
- const { classes: o } = u(n);
40
- return /* @__PURE__ */ l("div", { className: s(r.footer, o.footer, t), style: a, children: e });
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 });
41
41
  };
42
- h.displayName = "Modal.Footer";
43
- const m = R(
42
+ B.displayName = "Modal.Footer";
43
+ const m = j(
44
44
  ({
45
45
  open: e,
46
- onClose: t,
47
- closeOnBackdrop: a = !0,
48
- closeOnEscape: o = !0,
49
- size: i = "md",
50
- classes: d,
51
- className: N,
52
- style: k,
46
+ onClose: r,
47
+ closeOnBackdrop: s = !0,
48
+ closeOnEscape: t = !0,
49
+ size: n = "md",
50
+ classes: c,
51
+ className: k,
52
+ style: w,
53
53
  children: x,
54
- "aria-label": f,
55
- "aria-labelledby": C
56
- }, M) => {
57
- const B = g(null), y = M ?? B, w = T(), b = C ?? `${w}-title`;
58
- W(y, e);
59
- const I = j(
54
+ "aria-label": p,
55
+ "aria-labelledby": g
56
+ }, i) => {
57
+ const b = v(null), C = (o) => {
58
+ b.current = o, typeof i == "function" ? i(o) : i && (i.current = o);
59
+ }, I = D(), h = g ?? `${I}-title`;
60
+ O(b, e);
61
+ const F = P(
60
62
  () => ({
61
63
  Escape: () => {
62
- o && t();
64
+ t && r();
63
65
  }
64
66
  }),
65
- [o, t]
67
+ [t, r]
66
68
  );
67
- $(I, e), P(() => {
69
+ S(F, e), U(() => {
68
70
  if (!e) return;
69
- const c = document.body.style.overflow;
71
+ const o = document.body.style.overflow;
70
72
  return document.body.style.overflow = "hidden", () => {
71
- document.body.style.overflow = c;
73
+ document.body.style.overflow = o;
72
74
  };
73
75
  }, [e]);
74
- const F = (c) => {
75
- a && c.target === c.currentTarget && t();
76
+ const f = v(!1), H = (o) => {
77
+ f.current = o.target === o.currentTarget;
78
+ }, R = (o) => {
79
+ s && f.current && o.target === o.currentTarget && r(), f.current = !1;
76
80
  };
77
81
  return e ? K(
78
82
  /* @__PURE__ */ l(
79
83
  "div",
80
84
  {
81
- className: s(r.backdrop, d?.backdrop),
82
- onClick: F,
85
+ className: d(a.backdrop, c?.backdrop),
86
+ onMouseDown: H,
87
+ onMouseUp: R,
83
88
  role: "presentation",
84
89
  children: /* @__PURE__ */ l(
85
90
  "div",
86
91
  {
87
- ref: y,
88
- className: s(r.modal, r[i], d?.modal, N),
89
- style: k,
92
+ ref: C,
93
+ className: d(a.modal, a[n], c?.modal, k),
94
+ style: w,
90
95
  role: "dialog",
91
96
  "aria-modal": "true",
92
- "aria-label": f,
93
- "aria-labelledby": f ? void 0 : b,
94
- children: /* @__PURE__ */ l(n.Provider, { value: { classes: d ?? {}, titleId: b }, children: x })
97
+ "aria-label": p,
98
+ "aria-labelledby": p ? void 0 : h,
99
+ children: /* @__PURE__ */ l(u.Provider, { value: { classes: c ?? {}, titleId: h }, children: x })
95
100
  }
96
101
  )
97
102
  }
@@ -101,9 +106,9 @@ const m = R(
101
106
  }
102
107
  );
103
108
  m.displayName = "Modal";
104
- m.Header = p;
105
- m.Body = v;
106
- m.Footer = h;
109
+ m.Header = M;
110
+ m.Body = N;
111
+ m.Footer = B;
107
112
  export {
108
113
  m as Modal
109
114
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overdoser/react-toolkit",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",