@overdoser/react-toolkit 0.17.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.
package/AGENTS.md CHANGED
@@ -89,7 +89,7 @@ For exhaustive component reference (every prop, every variant, every signature),
89
89
 
90
90
  - **Need an inline status message?** → `<Alert variant="info|success|warning|danger">`. Add `title` for a heading, `onClose` to make it dismissible. For *transient* feedback prefer Toast; use Alert for persistent, in-flow messaging.
91
91
 
92
- - **Need a status pill / count / tag?** → `<Badge>`. For loading states: `<Spinner>` (indeterminate activity, inherits text color) and `<Skeleton>` (content placeholder — `variant="text|circle|rect"`, `lines` for multi-line text).
92
+ - **Need a status pill / count / tag?** → `<Badge>`. For loading states: `<Loader>` (page / container loading — wrap content to overlay it without a height jump, `mode="overlay"` drop-in, or `mode="fullscreen"`; variants `dots|pulse|spinner|grid|morph`), `<Spinner>` (small inline indicator for buttons and text, inherits text color) and `<Skeleton>` (content placeholder — `variant="text|circle|rect"`, `lines` for multi-line text).
93
93
 
94
94
  - **Need a data table?** → `<Table>`.
95
95
  - All data in memory → don't pass `onSort`; pass `pagination` (without `totalRows`) for client-side paging.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,26 @@ 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.18.0]
8
+
9
+ A loader for pages and containers.
10
+
11
+ ### Added
12
+
13
+ - **`Loader`** — loading indicator for pages and containers, in five variants:
14
+ `dots` (the `Button` loading bounce at scale), `pulse` (the same dots
15
+ swelling and fading in place), `spinner`, `grid` (3×3 cells
16
+ in a diagonal wave) and `morph` (a gradient shape that morphs and turns).
17
+ Needs no CSS on the surrounding elements: wrap content
18
+ (`<Loader loading={busy}>…</Loader>`) and it overlays it while the content
19
+ keeps its height; drop `mode="overlay"` into any container and it covers it,
20
+ positioning a static parent itself; `mode="fullscreen"` covers the viewport;
21
+ with no children and no mode it is a centered block. Over a container taller
22
+ than the screen the indicator stays centred in the visible part. `delay` avoids flashing
23
+ on fast responses, `backdrop` is `dim` / `blur` / `none`, covered content is
24
+ `inert` unless `interactive`, and size, color, speed and the dot geometry are
25
+ CSS variables (`--crk-loader-*`). Honors `prefers-reduced-motion`.
26
+
7
27
  ## [0.17.0]
8
28
 
9
29
  A correctness pass over charts, inputs and overlays. Mostly fixes, but a few
@@ -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>>;
@@ -0,0 +1,186 @@
1
+ import { jsxs as V, jsx as m } from "react/jsx-runtime";
2
+ import { forwardRef as D, useRef as P, useLayoutEffect as Y, useEffect as _, useState as $ } from "react";
3
+ import { createPortal as q } from "react-dom";
4
+ import c from "clsx";
5
+ import t from "./Loader.module.scss.js";
6
+ const G = {
7
+ dots: 3,
8
+ pulse: 3,
9
+ spinner: 1,
10
+ grid: 9,
11
+ morph: 2
12
+ };
13
+ function I(l) {
14
+ const o = l.getBoundingClientRect();
15
+ let e = Math.max(o.top, 0), r = Math.min(o.bottom, window.innerHeight);
16
+ for (let n = l.parentElement; n && n !== document.body; n = n.parentElement) {
17
+ const u = getComputedStyle(n).overflowY;
18
+ if (u === "visible" || u === "") continue;
19
+ const v = n.getBoundingClientRect();
20
+ e = Math.max(e, v.top), r = Math.min(r, v.bottom);
21
+ }
22
+ return { top: e, bottom: r };
23
+ }
24
+ function z(l, o) {
25
+ Y(() => {
26
+ const e = l.current;
27
+ if (!o || !e) return;
28
+ let r = 0;
29
+ const n = () => {
30
+ r = 0;
31
+ const f = e.getBoundingClientRect(), b = e.firstElementChild, { top: h, bottom: g } = I(e);
32
+ let d = 0;
33
+ if (g > h && f.height > 0) {
34
+ d = (h + g) / 2 - (f.top + f.bottom) / 2;
35
+ const i = Math.max(0, f.height / 2 - (b?.offsetHeight ?? 0) / 2 - 8);
36
+ d = Math.max(-i, Math.min(i, d));
37
+ }
38
+ e.style.setProperty("--_shift-y", `${Math.round(d)}px`);
39
+ }, u = () => {
40
+ r || (r = requestAnimationFrame(n));
41
+ };
42
+ n(), window.addEventListener("scroll", u, { capture: !0, passive: !0 }), window.addEventListener("resize", u);
43
+ const v = new ResizeObserver(u);
44
+ return v.observe(e), () => {
45
+ r && cancelAnimationFrame(r), window.removeEventListener("scroll", u, { capture: !0 }), window.removeEventListener("resize", u), v.disconnect();
46
+ };
47
+ }, [l, o]);
48
+ }
49
+ function J(l, o) {
50
+ const [e, r] = $(l && o <= 0);
51
+ return _(() => {
52
+ if (!l) {
53
+ r(!1);
54
+ return;
55
+ }
56
+ if (o <= 0) {
57
+ r(!0);
58
+ return;
59
+ }
60
+ const n = setTimeout(() => r(!0), o);
61
+ return () => clearTimeout(n);
62
+ }, [l, o]), l && e;
63
+ }
64
+ const K = D(
65
+ ({
66
+ variant: l = "dots",
67
+ size: o = "md",
68
+ mode: e = "inline",
69
+ loading: r = !0,
70
+ children: n,
71
+ delay: u = 0,
72
+ backdrop: v = "dim",
73
+ interactive: f = !1,
74
+ color: b,
75
+ label: h = "Loading",
76
+ showLabel: g = !1,
77
+ minHeight: d,
78
+ classes: i,
79
+ className: w,
80
+ style: x,
81
+ ...E
82
+ }, L) => {
83
+ const a = J(r, u), p = n != null, N = P(null), S = P(null), k = P(null), R = (s) => {
84
+ N.current = s, typeof L == "function" ? L(s) : L && (L.current = s);
85
+ }, H = !p && e === "overlay" && a;
86
+ Y(() => {
87
+ if (!H) return;
88
+ const s = N.current?.parentElement;
89
+ if (!s) return;
90
+ const M = s.getAttribute("aria-busy");
91
+ s.setAttribute("aria-busy", "true");
92
+ const F = getComputedStyle(s).position, O = F === "static" || F === "", j = s.style.position;
93
+ return O && (s.style.position = "relative"), () => {
94
+ O && (s.style.position = j), M === null ? s.removeAttribute("aria-busy") : s.setAttribute("aria-busy", M);
95
+ };
96
+ }, [H]), z(p ? k : N, a && e !== "fullscreen" && (p || e === "overlay")), _(() => {
97
+ S.current?.toggleAttribute("inert", a && !f);
98
+ }, [a, f]);
99
+ const y = b ? { "--crk-loader-color": b } : void 0, A = typeof d == "number" ? `${d}px` : d, C = /* @__PURE__ */ V(
100
+ "span",
101
+ {
102
+ role: "status",
103
+ "aria-live": "polite",
104
+ className: c(t.indicator, i?.indicator),
105
+ children: [
106
+ /* @__PURE__ */ m("span", { className: c(t.glyph, t[l], i?.glyph), "aria-hidden": "true", children: Array.from({ length: G[l] }, (s, M) => /* @__PURE__ */ m("span", {}, M)) }),
107
+ h ? /* @__PURE__ */ m("span", { className: c(g ? t.label : t.srLabel, i?.label), children: h }) : null
108
+ ]
109
+ }
110
+ ), B = {
111
+ dim: t.backdropDim,
112
+ blur: t.backdropBlur,
113
+ none: void 0
114
+ }[v], T = a && e === "fullscreen" && typeof document < "u" ? q(
115
+ /* @__PURE__ */ m(
116
+ "div",
117
+ {
118
+ ref: p ? void 0 : R,
119
+ className: c(
120
+ // Portaled out of the wrapper, so it carries the tokens itself.
121
+ t.root,
122
+ t[o],
123
+ t.overlay,
124
+ t.fullscreen,
125
+ B,
126
+ i?.overlay,
127
+ !p && [i?.root, w]
128
+ ),
129
+ style: p ? y : { ...y, ...x },
130
+ ...p ? {} : E,
131
+ children: C
132
+ }
133
+ ),
134
+ document.body
135
+ ) : null;
136
+ return p ? /* @__PURE__ */ V(
137
+ "div",
138
+ {
139
+ ref: R,
140
+ className: c(t.root, t[o], t.wrap, a && t.wrapBusy, i?.root, w),
141
+ style: { ...y, ...a && A ? { minHeight: A } : null, ...x },
142
+ "aria-busy": r || void 0,
143
+ ...E,
144
+ children: [
145
+ /* @__PURE__ */ m("div", { ref: S, className: c(t.content, i?.content), children: n }),
146
+ a && e !== "fullscreen" && /* @__PURE__ */ m(
147
+ "div",
148
+ {
149
+ ref: k,
150
+ className: c(
151
+ t.overlay,
152
+ B,
153
+ f && t.passThrough,
154
+ i?.overlay
155
+ ),
156
+ children: C
157
+ }
158
+ ),
159
+ T
160
+ ]
161
+ }
162
+ ) : a ? e === "fullscreen" ? T : e === "overlay" ? /* @__PURE__ */ m(
163
+ "div",
164
+ {
165
+ ref: R,
166
+ className: c(t.root, t[o], t.overlay, B, i?.root, i?.overlay, w),
167
+ style: { ...y, ...x },
168
+ ...E,
169
+ children: C
170
+ }
171
+ ) : /* @__PURE__ */ m(
172
+ "div",
173
+ {
174
+ ref: R,
175
+ className: c(t.root, t[o], t.inline, i?.root, w),
176
+ style: { ...y, ...A ? { minHeight: A } : null, ...x },
177
+ ...E,
178
+ children: C
179
+ }
180
+ ) : null;
181
+ }
182
+ );
183
+ K.displayName = "Loader";
184
+ export {
185
+ K as Loader
186
+ };
@@ -0,0 +1,70 @@
1
+ const r = "crk-root-u1D7u", o = "crk-sm-M6Sb3", c = "crk-md-5c9sz", e = "crk-lg-PaoKK", t = "crk-inline-neVjU", a = "crk-wrap-BaBNd", k = "crk-wrapBusy-a4D7Z", l = "crk-content-bw8zV", n = "crk-overlay-B-AIp", s = "crk-crk-loader-enter-VxXmo", d = "crk-indicator-LqmYc", p = "crk-fullscreen-BXAhh", h = "crk-backdropDim-JqArB", u = "crk-backdropBlur-wV2vo", i = "crk-passThrough-NCa9b", b = "crk-glyph-L8nf5", L = "crk-label-yMjMY", m = "crk-srLabel-PDGoC", B = "crk-dots-KfhUo", g = "crk-pulse-wPxve", y = "crk-crk-loader-dot-bounce-NtrLY", D = "crk-crk-loader-dot-pulse-AolCU", w = "crk-spinner-xG6h2", C = "crk-crk-loader-rotate-yVTPr", A = "crk-grid-5nFwV", V = "crk-crk-loader-cell-A7li4", v = "crk-morph-DAgji", x = "crk-crk-loader-morph-1hxzv", P = "crk-crk-loader-breathe-RCpGC", f = {
2
+ root: r,
3
+ sm: o,
4
+ md: c,
5
+ lg: e,
6
+ inline: t,
7
+ wrap: a,
8
+ wrapBusy: k,
9
+ content: l,
10
+ overlay: n,
11
+ "crk-loader-enter": "crk-crk-loader-enter-VxXmo",
12
+ crkLoaderEnter: s,
13
+ indicator: d,
14
+ fullscreen: p,
15
+ backdropDim: h,
16
+ backdropBlur: u,
17
+ passThrough: i,
18
+ glyph: b,
19
+ label: L,
20
+ srLabel: m,
21
+ dots: B,
22
+ pulse: g,
23
+ "crk-loader-dot-bounce": "crk-crk-loader-dot-bounce-NtrLY",
24
+ crkLoaderDotBounce: y,
25
+ "crk-loader-dot-pulse": "crk-crk-loader-dot-pulse-AolCU",
26
+ crkLoaderDotPulse: D,
27
+ spinner: w,
28
+ "crk-loader-rotate": "crk-crk-loader-rotate-yVTPr",
29
+ crkLoaderRotate: C,
30
+ grid: A,
31
+ "crk-loader-cell": "crk-crk-loader-cell-A7li4",
32
+ crkLoaderCell: V,
33
+ morph: v,
34
+ "crk-loader-morph": "crk-crk-loader-morph-1hxzv",
35
+ crkLoaderMorph: x,
36
+ "crk-loader-breathe": "crk-crk-loader-breathe-RCpGC",
37
+ crkLoaderBreathe: P
38
+ };
39
+ export {
40
+ u as backdropBlur,
41
+ h as backdropDim,
42
+ l as content,
43
+ P as crkLoaderBreathe,
44
+ V as crkLoaderCell,
45
+ y as crkLoaderDotBounce,
46
+ D as crkLoaderDotPulse,
47
+ s as crkLoaderEnter,
48
+ x as crkLoaderMorph,
49
+ C as crkLoaderRotate,
50
+ f as default,
51
+ B as dots,
52
+ p as fullscreen,
53
+ b as glyph,
54
+ A as grid,
55
+ d as indicator,
56
+ t as inline,
57
+ L as label,
58
+ e as lg,
59
+ c as md,
60
+ v as morph,
61
+ n as overlay,
62
+ i as passThrough,
63
+ g as pulse,
64
+ r as root,
65
+ o as sm,
66
+ w as spinner,
67
+ m as srLabel,
68
+ a as wrap,
69
+ k as wrapBusy
70
+ };
@@ -0,0 +1,2 @@
1
+ export { Loader } from './Loader';
2
+ export type { LoaderProps, LoaderClasses } from './Loader';