@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,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
  };
@@ -0,0 +1,104 @@
1
+ import { ComponentPropsWithRef, ReactNode } from 'react';
2
+ export interface LoaderClasses {
3
+ root: string;
4
+ /** Wrapper around `children` (wrap mode only). */
5
+ content: string;
6
+ /** The layer covering the container / viewport. */
7
+ overlay: string;
8
+ /** The `role="status"` element holding the animation and label. */
9
+ indicator: string;
10
+ /** The animated shape itself. */
11
+ glyph: string;
12
+ label: string;
13
+ }
14
+ export interface LoaderProps extends Omit<ComponentPropsWithRef<'div'>, 'color'> {
15
+ /**
16
+ * Animation style.
17
+ * - `'dots'`: three bouncing dots (the `Button` loading animation, scaled up).
18
+ * - `'pulse'`: the same three dots, swelling and fading in turn without moving.
19
+ * - `'spinner'`: arc turning on a faint track.
20
+ * - `'grid'`: 3×3 cells lighting up in a diagonal wave.
21
+ * - `'morph'`: a gradient shape that morphs and turns.
22
+ * @default 'dots'
23
+ */
24
+ variant?: 'dots' | 'pulse' | 'spinner' | 'grid' | 'morph';
25
+ /** Toolkit size scale. Fine-tune with `--crk-loader-size`. @default 'md' */
26
+ size?: 'sm' | 'md' | 'lg';
27
+ /**
28
+ * Where the loader goes when it has no `children`.
29
+ * - `'inline'`: a centered block in the normal flow (e.g. an empty page section).
30
+ * - `'overlay'`: covers the element it is rendered into. No CSS needed on
31
+ * that element: a statically positioned parent is made `position: relative`
32
+ * while the loader is shown, and restored afterwards.
33
+ * - `'fullscreen'`: covers the viewport (portaled to `document.body`).
34
+ *
35
+ * With `children`, the loader wraps them and overlays them instead
36
+ * (`'fullscreen'` still covers the viewport).
37
+ * @default 'inline'
38
+ */
39
+ mode?: 'inline' | 'overlay' | 'fullscreen';
40
+ /**
41
+ * Whether the loader is shown. With `children`, the content stays mounted and
42
+ * keeps its size while this is `true`, so the layout doesn't jump. @default true
43
+ */
44
+ loading?: boolean;
45
+ /**
46
+ * Content to cover while loading. The loader renders a wrapper around it and
47
+ * overlays it — the content keeps its height, nothing else to set up.
48
+ */
49
+ children?: ReactNode;
50
+ /**
51
+ * Wait this many milliseconds before showing, so fast responses never flash
52
+ * a loader. @default 0
53
+ */
54
+ delay?: number;
55
+ /**
56
+ * What the overlay puts between the loader and the covered content.
57
+ * @default 'dim'
58
+ */
59
+ backdrop?: 'dim' | 'blur' | 'none';
60
+ /**
61
+ * Keep the covered content usable (focusable, clickable) while loading. By
62
+ * default it is made `inert`; turn this on when the covered area contains
63
+ * the control that triggered the load, e.g. a filter-as-you-type input.
64
+ * @default false
65
+ */
66
+ interactive?: boolean;
67
+ /** Indicator color. Defaults to `--crk-color-primary`; also settable via `--crk-loader-color`. */
68
+ color?: string;
69
+ /** Accessible label; visually hidden unless `showLabel` is set. @default 'Loading' */
70
+ label?: string;
71
+ /** Render `label` as visible text under the animation. @default false */
72
+ showLabel?: boolean;
73
+ /**
74
+ * Minimum height of the inline block, or of the wrapper while loading (so an
75
+ * empty container still has room for the loader). Number → px.
76
+ */
77
+ minHeight?: number | string;
78
+ /** Override class names on internal elements. */
79
+ classes?: Partial<LoaderClasses>;
80
+ }
81
+ /**
82
+ * Loading indicator for pages and containers. Drop it in as a centered block,
83
+ * wrap content to overlay it without changing its height, or cover the
84
+ * viewport — none of which needs CSS on the surrounding elements. Over a
85
+ * container taller than the screen, the indicator is centred in the part of
86
+ * it that is visible and follows scrolling.
87
+ *
88
+ * Sizing, colors and timing are CSS variables (`--crk-loader-size`,
89
+ * `--crk-loader-color`, `--crk-loader-speed`, `--crk-loader-dot-size`,
90
+ * `--crk-loader-dot-gap`, `--crk-loader-dot-bounce`, `--crk-loader-dot-pulse`,
91
+ * `--crk-loader-backdrop`,
92
+ * `--crk-loader-blur`).
93
+ *
94
+ * @example
95
+ * // Results keep their height while a new filter runs
96
+ * <Loader loading={isFetching} delay={150}>
97
+ * <ResultList items={results} />
98
+ * </Loader>
99
+ *
100
+ * @example
101
+ * // Initial page load, nothing to show yet
102
+ * <Loader mode="fullscreen" variant="morph" label="Loading dashboard" showLabel />
103
+ */
104
+ export declare const Loader: import('react').ForwardRefExoticComponent<Omit<LoaderProps, "ref"> & import('react').RefAttributes<HTMLDivElement>>;