@overdoser/react-toolkit 0.8.1 → 0.8.3

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/CHANGELOG.md CHANGED
@@ -4,6 +4,55 @@ All notable changes to `@overdoser/react-toolkit` are documented here.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/), and this
5
5
  project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [0.8.3]
8
+
9
+ One more callback-ref fix, found by auditing for the 0.8.1/0.8.2
10
+ pattern. No API changes.
11
+
12
+ ### Fixed
13
+
14
+ - **`Select` (searchable) fires its synthetic `change` event with callback
15
+ refs.** Like Modal/Drawer before 0.8.2, it used a forwarded ref directly
16
+ as the hidden native select's ref, so passing a callback ref silently
17
+ skipped the synthetic `change` dispatch on selection — `onChange` (and
18
+ anything listening to the native event, e.g. form libraries) never fired,
19
+ while `onValueChange` kept working. The forwarded ref is now merged with
20
+ an internal one in both the searchable and `multiple` variants.
21
+
22
+ ## [0.8.2]
23
+
24
+ Brings the 0.8.1 `Modal` fixes to `Drawer`. No API changes.
25
+
26
+ ### Fixed
27
+
28
+ - **`Drawer` no longer closes when a text-selection drag ends on the
29
+ backdrop**, and its **focus trap works with callback refs** — the same
30
+ two fixes `Modal` received in 0.8.1 (see below for the details); Drawer
31
+ had identical backdrop-click and forwarded-ref handling.
32
+
33
+ ## [0.8.1]
34
+
35
+ Modal fixes and tooling updates. No API changes.
36
+
37
+ ### Fixed
38
+
39
+ - **`Modal` no longer closes when a text-selection drag ends on the
40
+ backdrop.** It closed on backdrop `click`, but a click's target is the
41
+ common ancestor of where the press started and ended — so selecting text
42
+ inside the dialog and releasing over the backdrop counted as a backdrop
43
+ click. It now closes on `mouseup` only when the press both started and
44
+ ended on the backdrop itself; this also means a press that starts on the
45
+ backdrop and is released inside the dialog no longer closes it.
46
+ - **`Modal` focus trap works with callback refs.** It used the forwarded
47
+ ref directly as the focus-trap ref when one was provided, so passing a
48
+ callback ref silently disabled the trap (and initial focus). The
49
+ forwarded ref is now merged with an internal one, matching the other
50
+ ref-forwarding components.
51
+
52
+ ### Changed
53
+
54
+ - Internal tooling updates (nx 22.7.7, vite). No consumer-facing changes.
55
+
7
56
  ## [0.8.0]
8
57
 
9
58
  Bundle-size release: the package now tree-shakes properly. No API changes.
@@ -1,26 +1,26 @@
1
- import { jsx as l, jsxs as W } from "react/jsx-runtime";
2
- import { forwardRef as z, useRef as K, useId as q, useState as n, useEffect as p, useMemo as G, createContext as J, useContext as v } from "react";
3
- import { createPortal as Q } from "react-dom";
4
- import i from "clsx";
5
- import { useFocusTrap as U } from "../../hooks/useFocusTrap.js";
6
- import { useKeyboard as V } from "../../hooks/useKeyboard.js";
7
- import r from "./Drawer.module.scss.js";
8
- const u = J({ classes: {}, titleId: "" }), D = ({ children: e, className: o, style: a, onClose: t }) => {
9
- const { classes: c, titleId: f } = v(u);
10
- return /* @__PURE__ */ W(
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";
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(
11
11
  "div",
12
12
  {
13
- id: f,
14
- className: i(r.header, t && r.headerWithClose, c.header, o),
15
- style: a,
13
+ id: y,
14
+ className: l(t.header, o && t.headerWithClose, i.header, a),
15
+ style: s,
16
16
  children: [
17
17
  e,
18
- t && /* @__PURE__ */ l(
18
+ o && /* @__PURE__ */ d(
19
19
  "button",
20
20
  {
21
21
  type: "button",
22
- className: i(r.closeButton, c.closeButton),
23
- onClick: t,
22
+ className: l(t.closeButton, i.closeButton),
23
+ onClick: o,
24
24
  "aria-label": "Close",
25
25
  children: "×"
26
26
  }
@@ -29,86 +29,91 @@ const u = J({ classes: {}, titleId: "" }), D = ({ children: e, className: o, sty
29
29
  }
30
30
  );
31
31
  };
32
- D.displayName = "Drawer.Header";
33
- const R = ({ children: e, className: o, style: a }) => {
34
- const { classes: t } = v(u);
35
- return /* @__PURE__ */ l("div", { className: i(r.body, t.body, o), style: a, children: e });
32
+ M.displayName = "Drawer.Header";
33
+ const R = ({ children: e, className: a, style: s }) => {
34
+ const { classes: o } = h(m);
35
+ return /* @__PURE__ */ d("div", { className: l(t.body, o.body, a), style: s, children: e });
36
36
  };
37
37
  R.displayName = "Drawer.Body";
38
- const S = ({ children: e, className: o, style: a }) => {
39
- const { classes: t } = v(u);
40
- return /* @__PURE__ */ l("div", { className: i(r.footer, t.footer, o), style: a, children: e });
38
+ const _ = ({ children: e, className: a, style: s }) => {
39
+ const { classes: o } = h(m);
40
+ return /* @__PURE__ */ d("div", { className: l(t.footer, o.footer, a), style: s, children: e });
41
41
  };
42
- S.displayName = "Drawer.Footer";
43
- const X = 340, m = z(
42
+ _.displayName = "Drawer.Footer";
43
+ const Z = 340, f = q(
44
44
  ({
45
45
  open: e,
46
- onClose: o,
47
- side: a = "right",
48
- size: t = "md",
49
- variant: c = "temporary",
50
- closeOnBackdrop: f = !0,
51
- closeOnEscape: w = !0,
52
- classes: y,
53
- className: T,
54
- style: C,
55
- children: _,
56
- "aria-label": h,
57
- "aria-labelledby": $
58
- }, A) => {
59
- const F = K(null), N = A ?? F, H = q(), k = $ ?? `${H}-title`, b = c === "temporary", [s, B] = n(e), [I, g] = n(!1), [x, M] = n(a), [j, E] = n(t);
60
- p(() => {
61
- e && (B(!0), g(!1), M(a), E(t));
62
- }, [e, a, t]), p(() => {
63
- if (e || !s) return;
64
- g(!0);
65
- const d = setTimeout(() => B(!1), X);
66
- return () => clearTimeout(d);
67
- }, [e, s]), U(N, s && e && b);
68
- const O = G(
69
- () => ({ Escape: () => w && o() }),
70
- [w, o]
46
+ onClose: a,
47
+ side: s = "right",
48
+ size: o = "md",
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
58
+ }, n) => {
59
+ const B = x(null), H = (r) => {
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);
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);
68
+ return () => clearTimeout(r);
69
+ }, [e, c]), X(B, c && e && b);
70
+ const U = J(
71
+ () => ({ Escape: () => N && a() }),
72
+ [N, a]
71
73
  );
72
- V(O, e), p(() => {
73
- if (!s) return;
74
- const d = document.body.style.overflow;
74
+ Y(U, e), w(() => {
75
+ if (!c) return;
76
+ const r = document.body.style.overflow;
75
77
  return document.body.style.overflow = "hidden", () => {
76
- document.body.style.overflow = d;
78
+ document.body.style.overflow = r;
77
79
  };
78
- }, [s]);
79
- const P = (d) => {
80
- f && d.target === d.currentTarget && o();
80
+ }, [c]);
81
+ const v = x(!1), W = (r) => {
82
+ v.current = r.target === r.currentTarget;
83
+ }, z = (r) => {
84
+ y && v.current && r.target === r.currentTarget && a(), v.current = !1;
81
85
  };
82
- return s ? Q(
83
- /* @__PURE__ */ l(
86
+ return c ? V(
87
+ /* @__PURE__ */ d(
84
88
  "div",
85
89
  {
86
- className: i(
87
- r.backdrop,
88
- I && r.backdropClosing,
89
- !b && r.backdropBare,
90
- y?.backdrop
90
+ className: l(
91
+ t.backdrop,
92
+ I && t.backdropClosing,
93
+ !b && t.backdropBare,
94
+ p?.backdrop
91
95
  ),
92
- onClick: P,
96
+ onMouseDown: W,
97
+ onMouseUp: z,
93
98
  role: "presentation",
94
- children: /* @__PURE__ */ l(
99
+ children: /* @__PURE__ */ d(
95
100
  "div",
96
101
  {
97
- ref: N,
98
- className: i(
99
- r.drawer,
100
- r[`side_${x}`],
101
- r[`size_${j}`],
102
- r[`${I ? "slideOut" : "slideIn"}_${x}`],
103
- y?.drawer,
104
- T
102
+ ref: H,
103
+ className: l(
104
+ t.drawer,
105
+ t[`side_${T}`],
106
+ t[`size_${E}`],
107
+ t[`${I ? "slideOut" : "slideIn"}_${T}`],
108
+ p?.drawer,
109
+ $
105
110
  ),
106
- style: C,
111
+ style: A,
107
112
  role: "dialog",
108
113
  "aria-modal": b ? "true" : void 0,
109
- "aria-label": h,
110
- "aria-labelledby": h ? void 0 : k,
111
- children: /* @__PURE__ */ l(u.Provider, { value: { classes: y ?? {}, titleId: k }, children: _ })
114
+ "aria-label": k,
115
+ "aria-labelledby": k ? void 0 : g,
116
+ children: /* @__PURE__ */ d(m.Provider, { value: { classes: p ?? {}, titleId: g }, children: C })
112
117
  }
113
118
  )
114
119
  }
@@ -117,10 +122,10 @@ const X = 340, m = z(
117
122
  ) : null;
118
123
  }
119
124
  );
120
- m.displayName = "Drawer";
121
- m.Header = D;
122
- m.Body = R;
123
- m.Footer = S;
125
+ f.displayName = "Drawer";
126
+ f.Header = M;
127
+ f.Body = R;
128
+ f.Footer = _;
124
129
  export {
125
- m as Drawer
130
+ f as Drawer
126
131
  };
@@ -1,18 +1,18 @@
1
- import { jsx as o, jsxs as P, Fragment as me } from "react/jsx-runtime";
2
- import { forwardRef as ne, useState as Q, useRef as w, useId as le, useCallback as S, useMemo as ae, useEffect as q } from "react";
1
+ import { jsx as s, jsxs as P, Fragment as me } from "react/jsx-runtime";
2
+ import { forwardRef as ne, useState as U, useRef as w, useId as le, useCallback as S, useMemo as ae, useEffect as $ } from "react";
3
3
  import { createPortal as ie } from "react-dom";
4
4
  import f from "clsx";
5
5
  import e from "./Select.module.scss.js";
6
- import { usePortalPosition as oe } from "../../../hooks/usePortalPosition.js";
7
- const se = ne(
6
+ import { usePortalPosition as se } from "../../../hooks/usePortalPosition.js";
7
+ const oe = ne(
8
8
  ({
9
9
  inputSize: h = "md",
10
10
  error: b = !1,
11
11
  options: p,
12
- placeholder: H,
12
+ placeholder: q,
13
13
  classes: u,
14
- className: F,
15
- style: U,
14
+ className: W,
15
+ style: B,
16
16
  children: y,
17
17
  searchable: g,
18
18
  searchPlaceholder: ee,
@@ -20,37 +20,37 @@ const se = ne(
20
20
  onValueChange: v,
21
21
  ...L
22
22
  }, N) => {
23
- const W = te || v ? (s) => {
24
- te?.(s), v?.(s.target.value);
23
+ const M = te || v ? (o) => {
24
+ te?.(o), v?.(o.target.value);
25
25
  } : void 0;
26
- return /* @__PURE__ */ P("div", { className: f(e.wrapper, e[h], b && e.error, u?.wrapper, F), style: U, children: [
26
+ return /* @__PURE__ */ P("div", { className: f(e.wrapper, e[h], b && e.error, u?.wrapper, W), style: B, children: [
27
27
  /* @__PURE__ */ P(
28
28
  "select",
29
29
  {
30
30
  ref: N,
31
31
  className: f(e.root, e[h], b && e.error, u?.root),
32
- onChange: W,
32
+ onChange: M,
33
33
  ...L,
34
34
  children: [
35
- H && /* @__PURE__ */ o("option", { value: "", disabled: !0, children: H }),
36
- p ? p.map((s) => /* @__PURE__ */ o("option", { value: s.value, disabled: s.disabled, children: s.label }, s.value)) : y
35
+ q && /* @__PURE__ */ s("option", { value: "", disabled: !0, children: q }),
36
+ p ? p.map((o) => /* @__PURE__ */ s("option", { value: o.value, disabled: o.disabled, children: o.label }, o.value)) : y
37
37
  ]
38
38
  }
39
39
  ),
40
- /* @__PURE__ */ o("span", { className: f(e.arrow, u?.arrow) })
40
+ /* @__PURE__ */ s("span", { className: f(e.arrow, u?.arrow) })
41
41
  ] });
42
42
  }
43
43
  );
44
- se.displayName = "NativeSelect";
44
+ oe.displayName = "NativeSelect";
45
45
  const ce = ne(
46
46
  ({
47
47
  inputSize: h = "md",
48
48
  error: b = !1,
49
49
  options: p = [],
50
- placeholder: H = "Select...",
50
+ placeholder: q = "Select...",
51
51
  classes: u,
52
- className: F,
53
- style: U,
52
+ className: W,
53
+ style: B,
54
54
  value: y,
55
55
  disabled: g,
56
56
  id: ee,
@@ -58,77 +58,79 @@ const ce = ne(
58
58
  onChange: v,
59
59
  onValueChange: L,
60
60
  portal: N = !0
61
- }, W) => {
62
- const [s, B] = Q(!1), [M, X] = Q(""), [c, d] = Q(0), K = w(null), I = w(null), A = w(null), R = w(null), k = w(null), $ = le(), O = oe(K, s && N), re = w(null), T = W ?? re, z = w(!1);
63
- q(() => {
64
- z.current && !s && A.current?.focus(), z.current = s;
65
- }, [s]);
61
+ }, M) => {
62
+ const [o, X] = U(!1), [A, T] = U(""), [c, d] = U(0), j = w(null), I = w(null), _ = w(null), R = w(null), k = w(null), Q = le(), K = se(j, o && N), H = w(null), re = (r) => {
63
+ H.current = r, typeof M == "function" ? M(r) : M && (M.current = r);
64
+ }, z = w(!1);
65
+ $(() => {
66
+ z.current && !o && _.current?.focus(), z.current = o;
67
+ }, [o]);
66
68
  const C = S(() => {
67
- B(!1), X(""), d(0);
69
+ X(!1), T(""), d(0);
68
70
  }, []), G = S(() => {
69
- g || (B(!0), X(""), d(0), setTimeout(() => I.current?.focus(), 0));
71
+ g || (X(!0), T(""), d(0), setTimeout(() => I.current?.focus(), 0));
70
72
  }, [g]), J = S(
71
- (n) => {
72
- if (L?.(n), T.current) {
73
+ (r) => {
74
+ if (L?.(r), H.current) {
73
75
  Object.getOwnPropertyDescriptor(
74
76
  HTMLSelectElement.prototype,
75
77
  "value"
76
- )?.set?.call(T.current, n);
77
- const r = new Event("change", { bubbles: !0 });
78
- T.current.dispatchEvent(r), v?.(r);
78
+ )?.set?.call(H.current, r);
79
+ const n = new Event("change", { bubbles: !0 });
80
+ H.current.dispatchEvent(n), v?.(n);
79
81
  }
80
82
  C();
81
83
  },
82
- [L, v, T, C]
84
+ [L, v, H, C]
83
85
  ), x = ae(() => {
84
- if (!M) return p;
85
- const n = M.toLowerCase();
86
- return p.filter((a) => a.label.toLowerCase().includes(n));
87
- }, [p, M]);
88
- q(() => {
89
- const n = x.findIndex((a) => !a.disabled);
90
- d(n >= 0 ? n : 0);
91
- }, [x]), q(() => {
92
- if (!s) return;
93
- const n = k.current;
94
- if (!n) return;
95
- n.querySelectorAll('[role="option"]')[c]?.scrollIntoView?.({ block: "nearest" });
96
- }, [c, s]);
86
+ if (!A) return p;
87
+ const r = A.toLowerCase();
88
+ return p.filter((a) => a.label.toLowerCase().includes(r));
89
+ }, [p, A]);
90
+ $(() => {
91
+ const r = x.findIndex((a) => !a.disabled);
92
+ d(r >= 0 ? r : 0);
93
+ }, [x]), $(() => {
94
+ if (!o) return;
95
+ const r = k.current;
96
+ if (!r) return;
97
+ r.querySelectorAll('[role="option"]')[c]?.scrollIntoView?.({ block: "nearest" });
98
+ }, [c, o]);
97
99
  const E = S(
98
- (n) => {
99
- const a = x.map((r, m) => r.disabled ? -1 : m).filter((r) => r >= 0);
100
+ (r) => {
101
+ const a = x.map((n, m) => n.disabled ? -1 : m).filter((n) => n >= 0);
100
102
  if (a.length !== 0)
101
- if (n.key === "ArrowDown")
102
- n.preventDefault(), d((r) => {
103
- const m = a.indexOf(r);
103
+ if (r.key === "ArrowDown")
104
+ r.preventDefault(), d((n) => {
105
+ const m = a.indexOf(n);
104
106
  return m < a.length - 1 ? a[m + 1] : a[0];
105
107
  });
106
- else if (n.key === "ArrowUp")
107
- n.preventDefault(), d((r) => {
108
- const m = a.indexOf(r);
108
+ else if (r.key === "ArrowUp")
109
+ r.preventDefault(), d((n) => {
110
+ const m = a.indexOf(n);
109
111
  return m > 0 ? a[m - 1] : a[a.length - 1];
110
112
  });
111
- else if (n.key === "Enter") {
112
- n.preventDefault();
113
- const r = x[c];
114
- r && !r.disabled && J(r.value);
115
- } else n.key === "Escape" && (n.preventDefault(), C());
113
+ else if (r.key === "Enter") {
114
+ r.preventDefault();
115
+ const n = x[c];
116
+ n && !n.disabled && J(n.value);
117
+ } else r.key === "Escape" && (r.preventDefault(), C());
116
118
  },
117
119
  [x, c, J, C]
118
120
  );
119
- q(() => {
120
- if (!s) return;
121
- const n = (a) => {
122
- const r = a.target;
123
- K.current?.contains(r) || R.current?.contains(r) || C();
121
+ $(() => {
122
+ if (!o) return;
123
+ const r = (a) => {
124
+ const n = a.target;
125
+ j.current?.contains(n) || R.current?.contains(n) || C();
124
126
  };
125
- return document.addEventListener("mousedown", n), () => document.removeEventListener("mousedown", n);
126
- }, [s, C]);
127
- const _ = p.find((n) => n.value === y)?.label, Y = x.filter((n) => !n.disabled);
127
+ return document.addEventListener("mousedown", r), () => document.removeEventListener("mousedown", r);
128
+ }, [o, C]);
129
+ const O = p.find((r) => r.value === y)?.label, Y = x.filter((r) => !r.disabled);
128
130
  return /* @__PURE__ */ P(
129
131
  "div",
130
132
  {
131
- ref: K,
133
+ ref: j,
132
134
  className: f(
133
135
  e.wrapper,
134
136
  e.searchableWrapper,
@@ -136,14 +138,14 @@ const ce = ne(
136
138
  b && e.error,
137
139
  g && e.disabled,
138
140
  u?.wrapper,
139
- F
141
+ W
140
142
  ),
141
- style: U,
143
+ style: B,
142
144
  children: [
143
- /* @__PURE__ */ o(
145
+ /* @__PURE__ */ s(
144
146
  "select",
145
147
  {
146
- ref: T,
148
+ ref: re,
147
149
  className: e.hiddenSelect,
148
150
  value: y ?? "",
149
151
  disabled: g,
@@ -151,36 +153,36 @@ const ce = ne(
151
153
  "aria-hidden": "true",
152
154
  onChange: () => {
153
155
  },
154
- children: p.map((n) => /* @__PURE__ */ o("option", { value: n.value, children: n.label }, n.value))
156
+ children: p.map((r) => /* @__PURE__ */ s("option", { value: r.value, children: r.label }, r.value))
155
157
  }
156
158
  ),
157
159
  /* @__PURE__ */ P(
158
160
  "button",
159
161
  {
160
- ref: A,
162
+ ref: _,
161
163
  id: ee,
162
164
  type: "button",
163
165
  className: f(
164
166
  e.root,
165
167
  e.searchableTrigger,
166
168
  e[h],
167
- s && e.triggerOpen,
169
+ o && e.triggerOpen,
168
170
  b && e.error,
169
- s && e.visuallyHidden,
171
+ o && e.visuallyHidden,
170
172
  u?.root
171
173
  ),
172
174
  onClick: G,
173
175
  disabled: g,
174
- "aria-expanded": s,
176
+ "aria-expanded": o,
175
177
  "aria-haspopup": "listbox",
176
- "aria-controls": s ? $ : void 0,
178
+ "aria-controls": o ? Q : void 0,
177
179
  children: [
178
- /* @__PURE__ */ o("span", { className: f(e.triggerLabel, !_ && e.placeholder), children: _ || H }),
179
- /* @__PURE__ */ o("span", { className: f(e.arrow, e.arrowInline, u?.arrow) })
180
+ /* @__PURE__ */ s("span", { className: f(e.triggerLabel, !O && e.placeholder), children: O || q }),
181
+ /* @__PURE__ */ s("span", { className: f(e.arrow, e.arrowInline, u?.arrow) })
180
182
  ]
181
183
  }
182
184
  ),
183
- s && /* @__PURE__ */ o(
185
+ o && /* @__PURE__ */ s(
184
186
  "input",
185
187
  {
186
188
  ref: I,
@@ -195,52 +197,52 @@ const ce = ne(
195
197
  u?.root,
196
198
  u?.search
197
199
  ),
198
- placeholder: _ || H,
199
- value: M,
200
- onChange: (n) => X(n.target.value),
200
+ placeholder: O || q,
201
+ value: A,
202
+ onChange: (r) => T(r.target.value),
201
203
  onKeyDown: E,
202
204
  "aria-expanded": !0,
203
205
  "aria-haspopup": "listbox",
204
- "aria-controls": $,
206
+ "aria-controls": Q,
205
207
  "aria-activedescendant": Y.length > 0 ? `select-option-${x[c]?.value}` : void 0
206
208
  }
207
209
  ),
208
- s && (() => {
209
- const n = N ? {
210
+ o && (() => {
211
+ const r = N ? {
210
212
  position: "fixed",
211
- top: O.top + 4,
212
- left: O.left,
213
+ top: K.top + 4,
214
+ left: K.left,
213
215
  right: "auto",
214
- width: O.width,
216
+ width: K.width,
215
217
  zIndex: "var(--crk-z-floating)"
216
- } : void 0, a = /* @__PURE__ */ o(
218
+ } : void 0, a = /* @__PURE__ */ s(
217
219
  "div",
218
220
  {
219
- id: $,
221
+ id: Q,
220
222
  ref: R,
221
223
  className: f(e.menu, u?.menu),
222
- style: n,
224
+ style: r,
223
225
  role: "listbox",
224
- children: /* @__PURE__ */ o("div", { className: e.menuItems, ref: k, children: x.length === 0 ? /* @__PURE__ */ o("div", { className: e.noResults, children: "No results" }) : x.map((r, m) => /* @__PURE__ */ o(
226
+ children: /* @__PURE__ */ s("div", { className: e.menuItems, ref: k, children: x.length === 0 ? /* @__PURE__ */ s("div", { className: e.noResults, children: "No results" }) : x.map((n, m) => /* @__PURE__ */ s(
225
227
  "button",
226
228
  {
227
- id: `select-option-${r.value}`,
229
+ id: `select-option-${n.value}`,
228
230
  type: "button",
229
231
  role: "option",
230
- "aria-selected": r.value === y,
232
+ "aria-selected": n.value === y,
231
233
  className: f(
232
234
  e.item,
233
- r.disabled && e.itemDisabled,
234
- r.value === y && e.itemSelected,
235
+ n.disabled && e.itemDisabled,
236
+ n.value === y && e.itemSelected,
235
237
  m === c && e.itemHighlighted,
236
238
  u?.item
237
239
  ),
238
- disabled: r.disabled,
239
- onClick: () => J(r.value),
240
+ disabled: n.disabled,
241
+ onClick: () => J(n.value),
240
242
  onMouseEnter: () => d(m),
241
- children: r.content ?? r.label
243
+ children: n.content ?? n.label
242
244
  },
243
- r.value
245
+ n.value
244
246
  )) })
245
247
  }
246
248
  );
@@ -257,10 +259,10 @@ const ue = ne(
257
259
  inputSize: h = "md",
258
260
  error: b = !1,
259
261
  options: p = [],
260
- placeholder: H = "Select...",
262
+ placeholder: q = "Select...",
261
263
  classes: u,
262
- className: F,
263
- style: U,
264
+ className: W,
265
+ style: B,
264
266
  value: y,
265
267
  disabled: g,
266
268
  id: ee,
@@ -268,22 +270,24 @@ const ue = ne(
268
270
  onValuesChange: v,
269
271
  clearSearchOnSelect: L = !0,
270
272
  closeOnSelect: N = !0,
271
- allowCreate: W = !1,
272
- onCreate: s,
273
- createLabel: B,
274
- portal: M = !0
275
- }, X) => {
276
- const c = Array.isArray(y) ? y : y ? [y] : [], [d, K] = Q(!1), [I, A] = Q(""), [R, k] = Q(0), $ = w(null), O = w(null), re = w(null), T = w(null), z = w(null), C = le(), G = oe(z, d && M), J = w(null), x = X ?? J, E = S(() => {
277
- K(!1), A(""), k(0);
278
- }, []), _ = S(() => {
279
- g || (K(!0), A(""), k(0), setTimeout(() => O.current?.focus(), 0));
273
+ allowCreate: M = !1,
274
+ onCreate: o,
275
+ createLabel: X,
276
+ portal: A = !0
277
+ }, T) => {
278
+ const c = Array.isArray(y) ? y : y ? [y] : [], [d, j] = U(!1), [I, _] = U(""), [R, k] = U(0), Q = w(null), K = w(null), H = w(null), re = w(null), z = w(null), C = le(), G = se(z, d && A), J = w(null), x = (t) => {
279
+ J.current = t, typeof T == "function" ? T(t) : T && (T.current = t);
280
+ }, E = S(() => {
281
+ j(!1), _(""), k(0);
282
+ }, []), O = S(() => {
283
+ g || (j(!0), _(""), k(0), setTimeout(() => K.current?.focus(), 0));
280
284
  }, [g]), Y = S(
281
285
  (t) => {
282
286
  const i = c.includes(t) ? c.filter((l) => l !== t) : [...c, t];
283
- v?.(i), N ? E() : L && A("");
287
+ v?.(i), N ? E() : L && _("");
284
288
  },
285
289
  [c, v, N, E, L]
286
- ), n = S(
290
+ ), r = S(
287
291
  (t, i) => {
288
292
  i.stopPropagation(), v?.(c.filter((l) => l !== t));
289
293
  },
@@ -292,17 +296,17 @@ const ue = ne(
292
296
  if (!I) return p;
293
297
  const t = I.toLowerCase();
294
298
  return p.filter((i) => i.label.toLowerCase().includes(t));
295
- }, [p, I]), r = I.trim(), m = W && r.length > 0 && !p.some(
296
- (t) => t.label.toLowerCase() === r.toLowerCase() || t.value === r
297
- ) && !c.includes(r), j = S(() => {
298
- r && (c.includes(r) || (s?.(r), v?.([...c, r]), N ? E() : L && A("")));
299
- }, [r, c, s, v, N, E, L]);
300
- q(() => {
299
+ }, [p, I]), n = I.trim(), m = M && n.length > 0 && !p.some(
300
+ (t) => t.label.toLowerCase() === n.toLowerCase() || t.value === n
301
+ ) && !c.includes(n), F = S(() => {
302
+ n && (c.includes(n) || (o?.(n), v?.([...c, n]), N ? E() : L && _("")));
303
+ }, [n, c, o, v, N, E, L]);
304
+ $(() => {
301
305
  const t = a.findIndex((i) => !i.disabled);
302
306
  k(t >= 0 ? t : 0);
303
- }, [a]), q(() => {
307
+ }, [a]), $(() => {
304
308
  if (!d) return;
305
- const t = T.current;
309
+ const t = re.current;
306
310
  if (!t) return;
307
311
  t.querySelectorAll('[role="option"]')[R]?.scrollIntoView?.({ block: "nearest" });
308
312
  }, [R, d]);
@@ -316,7 +320,7 @@ const ue = ne(
316
320
  if (i.length !== 0)
317
321
  if (t.key === "ArrowDown") {
318
322
  if (t.preventDefault(), !d) {
319
- _();
323
+ O();
320
324
  return;
321
325
  }
322
326
  k((l) => {
@@ -330,20 +334,20 @@ const ue = ne(
330
334
  });
331
335
  else if (t.key === "Enter") {
332
336
  if (t.preventDefault(), m && R === Z) {
333
- j();
337
+ F();
334
338
  return;
335
339
  }
336
340
  const l = a[R];
337
- l && !l.disabled ? Y(l.value) : m && j();
341
+ l && !l.disabled ? Y(l.value) : m && F();
338
342
  } else t.key === "Escape" && (t.preventDefault(), E());
339
343
  },
340
- [a, R, Y, E, I, c, v, d, _, m, j, Z]
344
+ [a, R, Y, E, I, c, v, d, O, m, F, Z]
341
345
  );
342
- q(() => {
346
+ $(() => {
343
347
  if (!d) return;
344
348
  const t = (i) => {
345
349
  const l = i.target;
346
- $.current?.contains(l) || re.current?.contains(l) || E();
350
+ Q.current?.contains(l) || H.current?.contains(l) || E();
347
351
  };
348
352
  return document.addEventListener("mousedown", t), () => document.removeEventListener("mousedown", t);
349
353
  }, [d, E]);
@@ -351,7 +355,7 @@ const ue = ne(
351
355
  return /* @__PURE__ */ P(
352
356
  "div",
353
357
  {
354
- ref: $,
358
+ ref: Q,
355
359
  className: f(
356
360
  e.wrapper,
357
361
  e.searchableWrapper,
@@ -359,11 +363,11 @@ const ue = ne(
359
363
  b && e.error,
360
364
  g && e.disabled,
361
365
  u?.wrapper,
362
- F
366
+ W
363
367
  ),
364
- style: U,
368
+ style: B,
365
369
  children: [
366
- /* @__PURE__ */ o(
370
+ /* @__PURE__ */ s(
367
371
  "select",
368
372
  {
369
373
  ref: x,
@@ -375,7 +379,7 @@ const ue = ne(
375
379
  "aria-hidden": "true",
376
380
  onChange: () => {
377
381
  },
378
- children: p.map((t) => /* @__PURE__ */ o("option", { value: t.value, children: t.label }, t.value))
382
+ children: p.map((t) => /* @__PURE__ */ s("option", { value: t.value, children: t.label }, t.value))
379
383
  }
380
384
  ),
381
385
  /* @__PURE__ */ P(
@@ -391,7 +395,7 @@ const ue = ne(
391
395
  u?.root
392
396
  ),
393
397
  onClick: () => {
394
- d ? O.current?.focus() : _();
398
+ d ? K.current?.focus() : O();
395
399
  },
396
400
  role: "combobox",
397
401
  "aria-expanded": d,
@@ -399,59 +403,59 @@ const ue = ne(
399
403
  "aria-controls": d ? C : void 0,
400
404
  children: [
401
405
  fe.map((t) => /* @__PURE__ */ P("span", { className: f(e.chip, u?.chip), children: [
402
- /* @__PURE__ */ o("span", { className: e.chipLabel, children: t.content ?? t.label }),
403
- /* @__PURE__ */ o(
406
+ /* @__PURE__ */ s("span", { className: e.chipLabel, children: t.content ?? t.label }),
407
+ /* @__PURE__ */ s(
404
408
  "button",
405
409
  {
406
410
  type: "button",
407
411
  className: f(e.chipRemove, u?.chipRemove),
408
- onClick: (i) => n(t.value, i),
412
+ onClick: (i) => r(t.value, i),
409
413
  "aria-label": `Remove ${t.label}`,
410
414
  tabIndex: -1,
411
415
  children: "×"
412
416
  }
413
417
  )
414
418
  ] }, t.value)),
415
- /* @__PURE__ */ o(
419
+ /* @__PURE__ */ s(
416
420
  "input",
417
421
  {
418
- ref: O,
422
+ ref: K,
419
423
  id: ee,
420
424
  type: "text",
421
425
  className: e.multiSearch,
422
- placeholder: c.length === 0 ? H : "",
426
+ placeholder: c.length === 0 ? q : "",
423
427
  value: I,
424
428
  onChange: (t) => {
425
- A(t.target.value), d || _();
429
+ _(t.target.value), d || O();
426
430
  },
427
431
  onKeyDown: de,
428
432
  disabled: g,
429
433
  "aria-label": "Search options"
430
434
  }
431
435
  ),
432
- /* @__PURE__ */ o("span", { className: f(e.arrow, e.arrowMulti, u?.arrow) })
436
+ /* @__PURE__ */ s("span", { className: f(e.arrow, e.arrowMulti, u?.arrow) })
433
437
  ]
434
438
  }
435
439
  ),
436
440
  d && (() => {
437
- const t = M ? {
441
+ const t = A ? {
438
442
  position: "fixed",
439
443
  top: G.top + 4,
440
444
  left: G.left,
441
445
  right: "auto",
442
446
  width: G.width,
443
447
  zIndex: "var(--crk-z-floating)"
444
- } : void 0, i = /* @__PURE__ */ o(
448
+ } : void 0, i = /* @__PURE__ */ s(
445
449
  "div",
446
450
  {
447
451
  id: C,
448
- ref: re,
452
+ ref: H,
449
453
  className: f(e.menu, u?.menu),
450
454
  style: t,
451
455
  role: "listbox",
452
456
  "aria-multiselectable": "true",
453
- children: /* @__PURE__ */ P("div", { className: e.menuItems, ref: T, children: [
454
- a.length === 0 && !m && /* @__PURE__ */ o("div", { className: e.noResults, children: "No results" }),
457
+ children: /* @__PURE__ */ P("div", { className: e.menuItems, ref: re, children: [
458
+ a.length === 0 && !m && /* @__PURE__ */ s("div", { className: e.noResults, children: "No results" }),
455
459
  a.map((l, D) => {
456
460
  const V = c.includes(l.value);
457
461
  return /* @__PURE__ */ P(
@@ -472,14 +476,14 @@ const ue = ne(
472
476
  onClick: () => Y(l.value),
473
477
  onMouseEnter: () => k(D),
474
478
  children: [
475
- V && /* @__PURE__ */ o("span", { className: e.itemCheck, "aria-hidden": "true" }),
479
+ V && /* @__PURE__ */ s("span", { className: e.itemCheck, "aria-hidden": "true" }),
476
480
  l.content ?? l.label
477
481
  ]
478
482
  },
479
483
  l.value
480
484
  );
481
485
  }),
482
- m && /* @__PURE__ */ o(
486
+ m && /* @__PURE__ */ s(
483
487
  "button",
484
488
  {
485
489
  type: "button",
@@ -490,11 +494,11 @@ const ue = ne(
490
494
  R === Z && e.itemHighlighted,
491
495
  u?.item
492
496
  ),
493
- onClick: j,
497
+ onClick: F,
494
498
  onMouseEnter: () => k(Z),
495
- children: B ? B(r) : /* @__PURE__ */ P(me, { children: [
499
+ children: X ? X(n) : /* @__PURE__ */ P(me, { children: [
496
500
  "Create “",
497
- /* @__PURE__ */ o("strong", { children: r }),
501
+ /* @__PURE__ */ s("strong", { children: n }),
498
502
  "”"
499
503
  ] })
500
504
  },
@@ -503,7 +507,7 @@ const ue = ne(
503
507
  ] })
504
508
  }
505
509
  );
506
- return M && typeof document < "u" ? ie(i, document.body) : i;
510
+ return A && typeof document < "u" ? ie(i, document.body) : i;
507
511
  })()
508
512
  ]
509
513
  }
@@ -512,7 +516,7 @@ const ue = ne(
512
516
  );
513
517
  ue.displayName = "MultiSelect";
514
518
  const he = ne(
515
- (h, b) => h.multiple ? /* @__PURE__ */ o(ue, { ref: b, ...h }) : h.searchable ? /* @__PURE__ */ o(ce, { ref: b, ...h }) : /* @__PURE__ */ o(se, { ref: b, ...h })
519
+ (h, b) => h.multiple ? /* @__PURE__ */ s(ue, { ref: b, ...h }) : h.searchable ? /* @__PURE__ */ s(ce, { ref: b, ...h }) : /* @__PURE__ */ s(oe, { ref: b, ...h })
516
520
  );
517
521
  he.displayName = "Select";
518
522
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overdoser/react-toolkit",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",