@qoretechnologies/reqore 0.74.2 → 0.74.3-pr.651.gfd5ecd9
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/dist/components/FadeScroller/index.d.ts.map +1 -1
- package/dist/components/FadeScroller/index.js +21 -38
- package/dist/components/FadeScroller/index.js.map +1 -1
- package/dist/components/NavRail/index.d.ts +72 -7
- package/dist/components/NavRail/index.d.ts.map +1 -1
- package/dist/components/NavRail/index.js +224 -38
- package/dist/components/NavRail/index.js.map +1 -1
- package/dist/hooks/useScrollFade.d.ts +61 -0
- package/dist/hooks/useScrollFade.d.ts.map +1 -0
- package/dist/hooks/useScrollFade.js +70 -0
- package/dist/hooks/useScrollFade.js.map +1 -0
- package/package.json +1 -1
- package/tests.json +0 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
export interface IReqoreScrollFadeMeasurement {
|
|
3
|
+
/** Content is scrolled out of view past the start edge (left / top). */
|
|
4
|
+
start: boolean;
|
|
5
|
+
/** Content is scrolled out of view past the end edge (right / bottom). */
|
|
6
|
+
end: boolean;
|
|
7
|
+
/** The content is wider / taller than the scroll box at all. */
|
|
8
|
+
overflows: boolean;
|
|
9
|
+
/** The scroll box that was measured. */
|
|
10
|
+
element: HTMLElement;
|
|
11
|
+
}
|
|
12
|
+
export interface IReqoreScrollFadeOptions {
|
|
13
|
+
/** The box that scrolls. */
|
|
14
|
+
scrollRef: RefObject<HTMLElement | null | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* The element that carries the edge classes — normally the overlay wrapper
|
|
17
|
+
* whose `::before` / `::after` paint the fades. Defaults to the scroll box.
|
|
18
|
+
*/
|
|
19
|
+
targetRef?: RefObject<HTMLElement | null | undefined>;
|
|
20
|
+
/**
|
|
21
|
+
* Which axis scrolls.
|
|
22
|
+
* @default x
|
|
23
|
+
*/
|
|
24
|
+
axis?: 'x' | 'y';
|
|
25
|
+
/** Class toggled on the target while content is hidden past the start edge (left / top). */
|
|
26
|
+
startClassName: string;
|
|
27
|
+
/** Class toggled on the target while content is hidden past the end edge (right / bottom). */
|
|
28
|
+
endClassName: string;
|
|
29
|
+
/**
|
|
30
|
+
* When `false` both classes are cleared regardless of the measurement (the
|
|
31
|
+
* fades are off). `onMeasure` still fires.
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
enabled?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Runs after every measurement with the raw result, for anything else that
|
|
37
|
+
* should follow the same pass (a drag cursor, a "more" hint) — so it can never
|
|
38
|
+
* disagree with the fades about whether the box overflows.
|
|
39
|
+
*/
|
|
40
|
+
onMeasure?: (measurement: IReqoreScrollFadeMeasurement) => void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Measures which edges of a scroll box still have content out of view and carries
|
|
44
|
+
* the answer as CLASSES on a target element — never as React state.
|
|
45
|
+
*
|
|
46
|
+
* A fade is a measurement. Routing a measurement through state means a layout
|
|
47
|
+
* effect that runs after every render and calls `setState`, guarded only by
|
|
48
|
+
* comparing booleans: correct while the measurement is stable, and an unbreakable
|
|
49
|
+
* render loop the moment it is not. Toggling a class cannot re-enter the render at
|
|
50
|
+
* all, and that is what lets the pass run after EVERY render — which it must,
|
|
51
|
+
* because children change size without the scroll box resizing (a label loads, an
|
|
52
|
+
* item is removed).
|
|
53
|
+
*
|
|
54
|
+
* Re-measures on scroll, on resize (`ResizeObserver`, degrading gracefully where it
|
|
55
|
+
* is unavailable) and after every render. Shared by `ReqoreFadeScroller` (x) and
|
|
56
|
+
* the expanded, scrolling `ReqoreNavRail` (y).
|
|
57
|
+
*
|
|
58
|
+
* @returns the measurement pass, for callers that need to trigger it by hand.
|
|
59
|
+
*/
|
|
60
|
+
export declare const useScrollFade: ({ scrollRef, targetRef, axis, startClassName, endClassName, enabled, onMeasure, }: IReqoreScrollFadeOptions) => (() => void);
|
|
61
|
+
//# sourceMappingURL=useScrollFade.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScrollFade.d.ts","sourceRoot":"","sources":["../../src/hooks/useScrollFade.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAmD,MAAM,OAAO,CAAC;AAEnF,MAAM,WAAW,4BAA4B;IAC3C,wEAAwE;IACxE,KAAK,EAAE,OAAO,CAAC;IACf,0EAA0E;IAC1E,GAAG,EAAE,OAAO,CAAC;IACb,gEAAgE;IAChE,SAAS,EAAE,OAAO,CAAC;IACnB,wCAAwC;IACxC,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,wBAAwB;IACvC,4BAA4B;IAC5B,SAAS,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACrD;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACtD;;;OAGG;IACH,IAAI,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC;IACjB,4FAA4F;IAC5F,cAAc,EAAE,MAAM,CAAC;IACvB,8FAA8F;IAC9F,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,WAAW,EAAE,4BAA4B,KAAK,IAAI,CAAC;CACjE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,aAAa,GAAI,mFAQ3B,wBAAwB,KAAG,CAAC,MAAM,IAAI,CAyDxC,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useScrollFade = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
/**
|
|
6
|
+
* Measures which edges of a scroll box still have content out of view and carries
|
|
7
|
+
* the answer as CLASSES on a target element — never as React state.
|
|
8
|
+
*
|
|
9
|
+
* A fade is a measurement. Routing a measurement through state means a layout
|
|
10
|
+
* effect that runs after every render and calls `setState`, guarded only by
|
|
11
|
+
* comparing booleans: correct while the measurement is stable, and an unbreakable
|
|
12
|
+
* render loop the moment it is not. Toggling a class cannot re-enter the render at
|
|
13
|
+
* all, and that is what lets the pass run after EVERY render — which it must,
|
|
14
|
+
* because children change size without the scroll box resizing (a label loads, an
|
|
15
|
+
* item is removed).
|
|
16
|
+
*
|
|
17
|
+
* Re-measures on scroll, on resize (`ResizeObserver`, degrading gracefully where it
|
|
18
|
+
* is unavailable) and after every render. Shared by `ReqoreFadeScroller` (x) and
|
|
19
|
+
* the expanded, scrolling `ReqoreNavRail` (y).
|
|
20
|
+
*
|
|
21
|
+
* @returns the measurement pass, for callers that need to trigger it by hand.
|
|
22
|
+
*/
|
|
23
|
+
var useScrollFade = function (_a) {
|
|
24
|
+
var scrollRef = _a.scrollRef, targetRef = _a.targetRef, _b = _a.axis, axis = _b === void 0 ? 'x' : _b, startClassName = _a.startClassName, endClassName = _a.endClassName, _c = _a.enabled, enabled = _c === void 0 ? true : _c, onMeasure = _a.onMeasure;
|
|
25
|
+
// Read inside `update`, which is deliberately dependency-free so it can be
|
|
26
|
+
// handed to listeners and observers once and never rebuilt.
|
|
27
|
+
var enabledRef = (0, react_1.useRef)(enabled);
|
|
28
|
+
enabledRef.current = enabled;
|
|
29
|
+
var onMeasureRef = (0, react_1.useRef)(onMeasure);
|
|
30
|
+
onMeasureRef.current = onMeasure;
|
|
31
|
+
var classNamesRef = (0, react_1.useRef)({ startClassName: startClassName, endClassName: endClassName });
|
|
32
|
+
classNamesRef.current = { startClassName: startClassName, endClassName: endClassName };
|
|
33
|
+
var update = (0, react_1.useCallback)(function () {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
var element = scrollRef.current;
|
|
36
|
+
if (!element) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
var vertical = axis === 'y';
|
|
40
|
+
var position = vertical ? element.scrollTop : element.scrollLeft;
|
|
41
|
+
var viewport = vertical ? element.clientHeight : element.clientWidth;
|
|
42
|
+
var total = vertical ? element.scrollHeight : element.scrollWidth;
|
|
43
|
+
var start = position > 1;
|
|
44
|
+
var end = position + viewport < total - 1;
|
|
45
|
+
var target = (_a = targetRef === null || targetRef === void 0 ? void 0 : targetRef.current) !== null && _a !== void 0 ? _a : element;
|
|
46
|
+
var on = enabledRef.current;
|
|
47
|
+
target.classList.toggle(classNamesRef.current.startClassName, on && start);
|
|
48
|
+
target.classList.toggle(classNamesRef.current.endClassName, on && end);
|
|
49
|
+
(_b = onMeasureRef.current) === null || _b === void 0 ? void 0 : _b.call(onMeasureRef, { start: start, end: end, overflows: total > viewport, element: element });
|
|
50
|
+
}, [scrollRef, targetRef, axis]);
|
|
51
|
+
// After every render: it only writes classes, so there is no state for it to
|
|
52
|
+
// feed back into and nothing to guard.
|
|
53
|
+
(0, react_1.useLayoutEffect)(update);
|
|
54
|
+
(0, react_1.useEffect)(function () {
|
|
55
|
+
var element = scrollRef.current;
|
|
56
|
+
if (!element) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
element.addEventListener('scroll', update, { passive: true });
|
|
60
|
+
var observer = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(update);
|
|
61
|
+
observer === null || observer === void 0 ? void 0 : observer.observe(element);
|
|
62
|
+
return function () {
|
|
63
|
+
element.removeEventListener('scroll', update);
|
|
64
|
+
observer === null || observer === void 0 ? void 0 : observer.disconnect();
|
|
65
|
+
};
|
|
66
|
+
}, [scrollRef, update]);
|
|
67
|
+
return update;
|
|
68
|
+
};
|
|
69
|
+
exports.useScrollFade = useScrollFade;
|
|
70
|
+
//# sourceMappingURL=useScrollFade.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScrollFade.js","sourceRoot":"","sources":["../../src/hooks/useScrollFade.ts"],"names":[],"mappings":";;;AAAA,+BAAmF;AA4Cn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