@overdoser/react-toolkit 0.16.0 → 0.18.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,40 +1,40 @@
1
1
  import { jsxs as N, jsx as r } from "react/jsx-runtime";
2
- import { forwardRef as X, useState as Y, useRef as S, useId as Z, useEffect as q, useCallback as F } from "react";
3
- import { createPortal as $ } from "react-dom";
2
+ import { forwardRef as Y, useState as Z, useRef as L, useId as $, useEffect as q, useCallback as F } from "react";
3
+ import { createPortal as ee } from "react-dom";
4
4
  import i from "clsx";
5
5
  import t from "./SplitButton.module.scss.js";
6
6
  import h from "../Button/Button.module.scss.js";
7
- import { useKeyboard as ee } from "../../hooks/useKeyboard.js";
8
- import { usePortalPosition as te } from "../../hooks/usePortalPosition.js";
9
- const ne = X(
7
+ import { useEscapeLayer as te, EscapeLayerProvider as ne } from "../../hooks/useEscapeLayer.js";
8
+ import { usePortalPosition as re } from "../../hooks/usePortalPosition.js";
9
+ const oe = Y(
10
10
  ({
11
11
  actions: g,
12
12
  variant: b = "secondary",
13
- size: O = "md",
14
- disabled: w = !1,
13
+ size: S = "md",
14
+ disabled: O = !1,
15
15
  align: v = "right",
16
- portal: k = !0,
17
- menuLabel: K = "More actions",
18
- maxWidth: y,
19
- className: G,
20
- style: x,
21
- id: I,
22
- onOpen: L,
16
+ portal: y = !0,
17
+ menuLabel: G = "More actions",
18
+ maxWidth: k,
19
+ className: H,
20
+ style: w,
21
+ id: x,
22
+ onOpen: I,
23
23
  onClose: c,
24
24
  classes: s
25
- }, H) => {
26
- const [n, R] = Y(!1), C = S(null), u = S(null), E = S(null), M = Z();
25
+ }, J) => {
26
+ const [n, E] = Z(!1), C = L(null), u = L(null), R = L(null), M = $();
27
27
  q(() => {
28
28
  n && u.current && u.current.querySelector('[role="menuitem"]:not([disabled])')?.focus();
29
29
  }, [n]);
30
30
  const f = F(() => {
31
- R(!1), c?.(), E.current?.focus();
32
- }, [c]), J = F(() => {
33
- R((e) => {
31
+ E(!1), c?.(), R.current?.focus();
32
+ }, [c]), K = F(() => {
33
+ E((e) => {
34
34
  const l = !e;
35
- return l ? L?.() : c?.(), l;
35
+ return l ? I?.() : c?.(), l;
36
36
  });
37
- }, [L, c]);
37
+ }, [I, c]);
38
38
  q(() => {
39
39
  if (!n) return;
40
40
  const e = (l) => {
@@ -42,27 +42,22 @@ const ne = X(
42
42
  C.current?.contains(m) || u.current?.contains(m) || f();
43
43
  };
44
44
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
45
- }, [n, f]), ee(
46
- {
47
- Escape: () => f()
48
- },
49
- n
50
- );
51
- const d = te(C, n && k);
45
+ }, [n, f]);
46
+ const Q = te(f, n), d = re(C, n && y);
52
47
  if (g.length === 0) return null;
53
- const [o, ...z] = g, a = z.length > 0, B = w || o.disabled, P = i(h.root, h[b], h[O]), Q = b === "secondary" ? t.overlapOutline : b === "ghost" ? t.dividerSubtle : t.dividerOnFill, j = i(
54
- P,
48
+ const [o, ...P] = g, a = P.length > 0, z = O || o.disabled, B = i(h.root, h[b], h[S]), T = b === "secondary" ? t.overlapOutline : b === "ghost" ? t.dividerSubtle : t.dividerOnFill, j = i(
49
+ B,
55
50
  t.main,
56
51
  a && t.mainAttached,
57
52
  a && n && t.mainOpen,
58
53
  s?.main
59
- ), p = (e) => y !== void 0 && (typeof e == "string" || typeof e == "number") ? String(e) : void 0, D = /* @__PURE__ */ N("span", { className: t.mainContent, children: [
54
+ ), p = (e) => k !== void 0 && (typeof e == "string" || typeof e == "number") ? String(e) : void 0, D = /* @__PURE__ */ N("span", { className: t.mainContent, children: [
60
55
  /* @__PURE__ */ r("span", { className: t.mainLabel, children: o.label }),
61
56
  a && /* @__PURE__ */ r("span", { className: t.sizer, "aria-hidden": "true", children: g.map((e, l) => /* @__PURE__ */ r("span", { className: t.sizerItem, children: e.label }, l)) })
62
- ] }), T = o.href && !B ? /* @__PURE__ */ r(
57
+ ] }), U = o.href && !z ? /* @__PURE__ */ r(
63
58
  "a",
64
59
  {
65
- id: I,
60
+ id: x,
66
61
  className: j,
67
62
  href: o.href,
68
63
  target: o.target,
@@ -74,22 +69,22 @@ const ne = X(
74
69
  ) : /* @__PURE__ */ r(
75
70
  "button",
76
71
  {
77
- id: I,
72
+ id: x,
78
73
  type: "button",
79
74
  className: j,
80
- disabled: B,
75
+ disabled: z,
81
76
  title: p(o.label),
82
77
  onClick: o.onClick,
83
78
  children: D
84
79
  }
85
- ), U = z.map((e, l) => {
80
+ ), V = P.map((e, l) => {
86
81
  const m = i(
87
82
  t.item,
88
83
  e.disabled && t.itemDisabled,
89
84
  e.danger && t.itemDanger,
90
85
  s?.item
91
- ), _ = (W) => {
92
- e.onClick?.(W), f();
86
+ ), _ = (X) => {
87
+ e.onClick?.(X), f();
93
88
  };
94
89
  return e.href && !e.disabled ? /* @__PURE__ */ r(
95
90
  "a",
@@ -117,51 +112,51 @@ const ne = X(
117
112
  },
118
113
  l
119
114
  );
120
- }), V = { sm: t.menuSm, md: t.menuMd, lg: t.menuLg }[O], A = (e) => /* @__PURE__ */ r(
115
+ }), W = { sm: t.menuSm, md: t.menuMd, lg: t.menuLg }[S], A = (e) => /* @__PURE__ */ r(
121
116
  "div",
122
117
  {
123
118
  ref: u,
124
119
  id: M,
125
120
  className: i(
126
121
  t.menu,
127
- V,
122
+ W,
128
123
  n && t.menuOpen,
129
124
  v === "left" ? t.alignLeft : t.alignRight,
130
125
  s?.menu
131
126
  ),
132
127
  style: e,
133
128
  role: "menu",
134
- children: U
129
+ children: /* @__PURE__ */ r(ne, { value: Q, children: V })
135
130
  }
136
131
  );
137
132
  return /* @__PURE__ */ N(
138
133
  "div",
139
134
  {
140
- ref: H,
141
- className: i(t.root, s?.root, G),
142
- style: y !== void 0 ? { maxWidth: y, ...x } : x,
135
+ ref: J,
136
+ className: i(t.root, s?.root, H),
137
+ style: k !== void 0 ? { maxWidth: k, ...w } : w,
143
138
  children: [
144
139
  /* @__PURE__ */ N("div", { ref: C, className: i(t.group, s?.group), children: [
145
- T,
140
+ U,
146
141
  a && /* @__PURE__ */ r(
147
142
  "button",
148
143
  {
149
- ref: E,
144
+ ref: R,
150
145
  type: "button",
151
146
  className: i(
152
- P,
147
+ B,
153
148
  h.iconOnly,
154
149
  t.toggle,
155
150
  n && t.toggleOpen,
156
- Q,
151
+ T,
157
152
  s?.toggle
158
153
  ),
159
- disabled: w,
160
- onClick: J,
154
+ disabled: O,
155
+ onClick: K,
161
156
  "aria-haspopup": "menu",
162
157
  "aria-expanded": n,
163
158
  "aria-controls": n ? M : void 0,
164
- "aria-label": K,
159
+ "aria-label": G,
165
160
  children: /* @__PURE__ */ r(
166
161
  "svg",
167
162
  {
@@ -174,8 +169,8 @@ const ne = X(
174
169
  }
175
170
  )
176
171
  ] }),
177
- a && !k && A(),
178
- a && k && n && typeof document < "u" && $(
172
+ a && !y && A(),
173
+ a && y && n && typeof document < "u" && ee(
179
174
  A({
180
175
  position: "fixed",
181
176
  top: d.top,
@@ -195,7 +190,7 @@ const ne = X(
195
190
  );
196
191
  }
197
192
  );
198
- ne.displayName = "SplitButton";
193
+ oe.displayName = "SplitButton";
199
194
  export {
200
- ne as SplitButton
195
+ oe as SplitButton
201
196
  };
@@ -1,130 +1,136 @@
1
- import { jsx as r, jsxs as j } from "react/jsx-runtime";
2
- import { forwardRef as ee, useState as d, useRef as K, useMemo as m, useCallback as s } from "react";
1
+ import { jsx as n, jsxs as F } from "react/jsx-runtime";
2
+ import { forwardRef as ee, useState as m, useRef as j, useMemo as y, useCallback as s } from "react";
3
3
  import { createPortal as te } from "react-dom";
4
- import y from "clsx";
4
+ import D from "clsx";
5
5
  import { useClickOutside as oe } from "../../../hooks/useClickOutside.js";
6
- import { usePortalPosition as re } from "../../../hooks/usePortalPosition.js";
6
+ import { usePortalPosition as ne } from "../../../hooks/usePortalPosition.js";
7
7
  import t from "./DatePicker.module.scss.js";
8
- import { CalendarPanel as ne } from "./CalendarPanel.js";
8
+ import { CalendarPanel as re } from "./CalendarPanel.js";
9
9
  import { startOfMonth as V, startOfDay as l } from "./dateUtils.js";
10
10
  const ae = ee(
11
11
  ({
12
- value: b,
12
+ value: P,
13
13
  defaultValue: q,
14
- onChange: O,
15
- min: D,
16
- max: h,
17
- disabledDate: P,
14
+ onChange: b,
15
+ min: v,
16
+ max: w,
17
+ disabledDate: O,
18
18
  weekStartsOn: A = 0,
19
- locale: v,
19
+ locale: h,
20
20
  format: g,
21
21
  placeholder: B = "Select date",
22
22
  inputSize: L = "md",
23
- error: M = !1,
24
- disabled: n = !1,
23
+ error: K = !1,
24
+ disabled: r = !1,
25
25
  portal: c = !0,
26
26
  classes: a,
27
27
  className: T,
28
28
  style: W,
29
29
  "aria-label": z
30
30
  }, G) => {
31
- const w = b !== void 0, [H, J] = d(q ?? null), o = w ? b ?? null : H, [i, u] = d(!1), [Q, N] = d(() => V(o ?? /* @__PURE__ */ new Date())), [U, S] = d(() => l(o ?? /* @__PURE__ */ new Date())), k = K(null), I = K(null), R = re(k, i && c), X = m(() => l(/* @__PURE__ */ new Date()), []), Y = m(
32
- () => g ?? ((e) => new Intl.DateTimeFormat(v, { year: "numeric", month: "short", day: "numeric" }).format(e)),
33
- [g, v]
34
- ), f = m(() => D ? l(D) : void 0, [D]), p = m(() => h ? l(h) : void 0, [h]), Z = s(
35
- (e) => f && e < f || p && e > p ? !0 : P?.(e) ?? !1,
36
- [f, p, P]
37
- ), E = s(
31
+ const k = P !== void 0, [H, J] = m(q ?? null), o = k ? P ?? null : H, [i, f] = m(!1), [Q, M] = m(() => V(o ?? /* @__PURE__ */ new Date())), [U, N] = m(() => l(o ?? /* @__PURE__ */ new Date())), C = j(null), S = j(null), E = ne(C, i && c), X = y(() => l(/* @__PURE__ */ new Date()), []), Y = y(
32
+ () => g ?? ((e) => new Intl.DateTimeFormat(h, { year: "numeric", month: "short", day: "numeric" }).format(e)),
33
+ [g, h]
34
+ ), u = y(() => v ? l(v) : void 0, [v]), p = y(() => w ? l(w) : void 0, [w]), Z = s(
35
+ (e) => u && e < u || p && e > p ? !0 : O?.(e) ?? !1,
36
+ [u, p, O]
37
+ ), I = s(
38
38
  (e) => {
39
- w || J(e), O?.(e);
39
+ k || J(e), b?.(e);
40
40
  },
41
- [w, O]
42
- ), C = s(() => {
43
- if (n) return;
41
+ [k, b]
42
+ ), x = s(() => {
43
+ if (r) return;
44
44
  const e = l(o ?? /* @__PURE__ */ new Date());
45
- N(V(e)), S(e), u(!0);
46
- }, [n, o]), x = s((e = !0) => {
47
- u(!1), e && k.current?.querySelector("input")?.focus();
45
+ M(V(e)), N(e), f(!0);
46
+ }, [r, o]), d = s((e = !0) => {
47
+ f(!1), e && C.current?.querySelector("input")?.focus();
48
48
  }, []), _ = s(
49
49
  (e) => {
50
- E(e), x();
50
+ I(e), d();
51
51
  },
52
- [E, x]
52
+ [I, d]
53
53
  );
54
- oe(I, () => u(!1), i);
54
+ oe(S, () => f(!1), i);
55
55
  const $ = (e) => {
56
- e.key === "ArrowDown" || e.key === "Enter" ? (e.preventDefault(), C()) : e.key === "Escape" && i && u(!1);
57
- }, F = /* @__PURE__ */ r(
58
- "div",
59
- {
60
- ref: I,
61
- className: y(t.popover, c && t.portalled, a?.popover),
62
- style: c ? { position: "fixed", top: R.top + 4, left: R.left } : void 0,
63
- role: "dialog",
64
- "aria-modal": "false",
65
- "aria-label": "Choose date",
66
- children: /* @__PURE__ */ r(
67
- ne,
68
- {
69
- viewDate: Q,
70
- focusedDate: U,
71
- selected: o,
72
- today: X,
73
- minDay: f,
74
- maxDay: p,
75
- locale: v,
76
- weekStartsOn: A,
77
- isDisabledDay: Z,
78
- onSelect: _,
79
- onViewDateChange: N,
80
- onFocusedDateChange: S,
81
- onEscape: x,
82
- classes: a
83
- }
84
- )
85
- }
56
+ e.key === "ArrowDown" || e.key === "Enter" ? (e.preventDefault(), x()) : e.key === "Escape" && i && (e.preventDefault(), f(!1));
57
+ }, R = (
58
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
59
+ /* @__PURE__ */ n(
60
+ "div",
61
+ {
62
+ ref: S,
63
+ onKeyDown: (e) => {
64
+ e.key === "Escape" && !e.defaultPrevented && (e.preventDefault(), d());
65
+ },
66
+ className: D(t.popover, c && t.portalled, a?.popover),
67
+ style: c ? { position: "fixed", top: E.top + 4, left: E.left } : void 0,
68
+ role: "dialog",
69
+ "aria-modal": "false",
70
+ "aria-label": "Choose date",
71
+ children: /* @__PURE__ */ n(
72
+ re,
73
+ {
74
+ viewDate: Q,
75
+ focusedDate: U,
76
+ selected: o,
77
+ today: X,
78
+ minDay: u,
79
+ maxDay: p,
80
+ locale: h,
81
+ weekStartsOn: A,
82
+ isDisabledDay: Z,
83
+ onSelect: _,
84
+ onViewDateChange: M,
85
+ onFocusedDateChange: N,
86
+ onEscape: d,
87
+ classes: a
88
+ }
89
+ )
90
+ }
91
+ )
86
92
  );
87
- return /* @__PURE__ */ j(
93
+ return /* @__PURE__ */ F(
88
94
  "div",
89
95
  {
90
- ref: k,
91
- className: y(t.root, t[L], M && t.error, n && t.disabled, a?.root, T),
96
+ ref: C,
97
+ className: D(t.root, t[L], K && t.error, r && t.disabled, a?.root, T),
92
98
  style: W,
93
99
  children: [
94
- /* @__PURE__ */ r(
100
+ /* @__PURE__ */ n(
95
101
  "input",
96
102
  {
97
103
  ref: G,
98
104
  type: "text",
99
105
  readOnly: !0,
100
- className: y(t.input, a?.input),
106
+ className: D(t.input, a?.input),
101
107
  value: o ? Y(o) : "",
102
108
  placeholder: B,
103
- disabled: n,
109
+ disabled: r,
104
110
  "aria-label": z,
105
111
  "aria-haspopup": "dialog",
106
112
  "aria-expanded": i,
107
- "aria-invalid": M || void 0,
108
- onClick: C,
113
+ "aria-invalid": K || void 0,
114
+ onClick: x,
109
115
  onKeyDown: $
110
116
  }
111
117
  ),
112
- /* @__PURE__ */ r(
118
+ /* @__PURE__ */ n(
113
119
  "button",
114
120
  {
115
121
  type: "button",
116
122
  tabIndex: -1,
117
- className: y(t.icon, a?.icon),
118
- onClick: C,
119
- disabled: n,
123
+ className: D(t.icon, a?.icon),
124
+ onClick: x,
125
+ disabled: r,
120
126
  "aria-label": "Open calendar",
121
- children: /* @__PURE__ */ j("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.5", "aria-hidden": "true", children: [
122
- /* @__PURE__ */ r("rect", { x: "3", y: "4", width: "14", height: "13", rx: "2" }),
123
- /* @__PURE__ */ r("path", { d: "M3 8h14M7 2v3M13 2v3", strokeLinecap: "round" })
127
+ children: /* @__PURE__ */ F("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.5", "aria-hidden": "true", children: [
128
+ /* @__PURE__ */ n("rect", { x: "3", y: "4", width: "14", height: "13", rx: "2" }),
129
+ /* @__PURE__ */ n("path", { d: "M3 8h14M7 2v3M13 2v3", strokeLinecap: "round" })
124
130
  ] })
125
131
  }
126
132
  ),
127
- i && (c ? typeof document < "u" && te(F, document.body) : F)
133
+ i && (c ? typeof document < "u" && te(R, document.body) : R)
128
134
  ]
129
135
  }
130
136
  );
@@ -85,7 +85,7 @@ const Ve = { hour: 0, minute: 0, second: 0 }, Le = Pe(
85
85
  );
86
86
  Ze(oe, () => C(!1), v);
87
87
  const we = (e) => {
88
- e.key === "ArrowDown" || e.key === "Enter" ? (e.preventDefault(), x()) : e.key === "Escape" && v && C(!1);
88
+ e.key === "ArrowDown" || e.key === "Enter" ? (e.preventDefault(), x()) : e.key === "Escape" && v && (e.preventDefault(), C(!1));
89
89
  }, be = (e) => {
90
90
  e.key === "Escape" && !e.defaultPrevented && (e.preventDefault(), F());
91
91
  }, re = (
@@ -188,7 +188,9 @@ const Ve = { hour: 0, minute: 0, second: 0 }, Le = Pe(
188
188
  onChange: Te,
189
189
  onClear: () => q(null),
190
190
  onOpenRequest: x,
191
- onEscape: () => v && C(!1),
191
+ onEscape: (e) => {
192
+ v && (e.preventDefault(), C(!1));
193
+ },
192
194
  suffix: g,
193
195
  suffixTitle: j,
194
196
  suffixClassName: n?.timeZone,
@@ -1,3 +1,4 @@
1
+ import { KeyboardEvent } from 'react';
1
2
  import { WallClock } from './timeZoneUtils';
2
3
  export type SegmentType = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'dayPeriod';
3
4
  export interface DateTimeSegmentsClasses {
@@ -24,7 +25,7 @@ export interface DateTimeSegmentsProps {
24
25
  onClear: () => void;
25
26
  /** Alt+ArrowDown — the user asked for the popover. */
26
27
  onOpenRequest: () => void;
27
- onEscape: () => void;
28
+ onEscape: (e: KeyboardEvent<HTMLElement>) => void;
28
29
  /** Plain trailing label (the zone name) rendered after the last segment. */
29
30
  suffix?: string | null;
30
31
  suffixTitle?: string;
@@ -184,7 +184,7 @@ const de = /* @__PURE__ */ new Set(["year", "month", "day", "hour", "minute", "s
184
184
  e.preventDefault(), c(""), G();
185
185
  return;
186
186
  case "Escape":
187
- Q();
187
+ Q(e);
188
188
  return;
189
189
  }
190
190
  if (t === "dayPeriod") {