@koine/react 1.1.3 → 1.1.5
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/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useScrollThreshold.d.ts +2 -0
- package/hooks/useScrollThreshold.js +28 -0
- package/hooks/useSmoothScroll.d.ts +1 -1
- package/hooks/useSmoothScroll.js +3 -3
- package/node/hooks/index.js +1 -0
- package/node/hooks/useScrollThreshold.js +32 -0
- package/node/hooks/useSmoothScroll.js +3 -3
- package/package.json +21 -1
package/hooks/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from "./useNavigateAway";
|
|
|
14
14
|
export * from "./usePrevious";
|
|
15
15
|
export * from "./usePreviousRef";
|
|
16
16
|
export * from "./useScrollPosition";
|
|
17
|
+
export * from "./useScrollThreshold";
|
|
17
18
|
export * from "./useSmoothScroll";
|
|
18
19
|
export * from "./useTraceUpdate";
|
|
19
20
|
export * from "./useUpdateEffect";
|
package/hooks/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export * from "./useNavigateAway";
|
|
|
14
14
|
export * from "./usePrevious";
|
|
15
15
|
export * from "./usePreviousRef";
|
|
16
16
|
export * from "./useScrollPosition";
|
|
17
|
+
export * from "./useScrollThreshold";
|
|
17
18
|
// export * from "./useScrollTo";
|
|
18
19
|
export * from "./useSmoothScroll";
|
|
19
20
|
export * from "./useTraceUpdate";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { noop } from "@koine/utils";
|
|
3
|
+
import { /* listenScroll, */ on } from "@koine/dom";
|
|
4
|
+
export var useScrollThreshold = function (threshold, callback) {
|
|
5
|
+
var _a = useState(false), isBelow = _a[0], setIsBelow = _a[1];
|
|
6
|
+
var handler = useCallback(function () {
|
|
7
|
+
if (threshold) {
|
|
8
|
+
var posY = window.scrollY; // * -1;
|
|
9
|
+
var isAbove = posY < threshold;
|
|
10
|
+
var isBelow_1 = posY > threshold;
|
|
11
|
+
// console.log("useScrollThreshold setIsBelow", isBelow, posY, threshold);
|
|
12
|
+
setIsBelow(isBelow_1);
|
|
13
|
+
if (callback)
|
|
14
|
+
callback(isAbove, isBelow_1);
|
|
15
|
+
}
|
|
16
|
+
}, [threshold, callback]);
|
|
17
|
+
useEffect(function () {
|
|
18
|
+
if (threshold) {
|
|
19
|
+
// const listener = listenScroll(handler, 50);
|
|
20
|
+
var listener = on(window, "scroll", handler, { passive: true });
|
|
21
|
+
handler();
|
|
22
|
+
return listener;
|
|
23
|
+
}
|
|
24
|
+
return noop;
|
|
25
|
+
}, [threshold, handler]);
|
|
26
|
+
return isBelow;
|
|
27
|
+
};
|
|
28
|
+
export default useScrollThreshold;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function useSmoothScroll(): (to?: number | string, offset?: number, callback?: () => void, fallbackTimeout?: number, behavior?: ScrollBehavior) => void;
|
|
1
|
+
export declare function useSmoothScroll(disregardFixedOffset?: boolean): (to?: number | string, offset?: number, callback?: () => void, fallbackTimeout?: number, behavior?: ScrollBehavior) => void;
|
|
2
2
|
export default useSmoothScroll;
|
package/hooks/useSmoothScroll.js
CHANGED
|
@@ -2,7 +2,7 @@ import { useCallback } from "react";
|
|
|
2
2
|
import { isNumber } from "@koine/utils";
|
|
3
3
|
import { scrollTo } from "@koine/dom";
|
|
4
4
|
import { useFixedOffset } from "./useFixedOffset";
|
|
5
|
-
export function useSmoothScroll() {
|
|
5
|
+
export function useSmoothScroll(disregardFixedOffset) {
|
|
6
6
|
var fixedOffset = useFixedOffset();
|
|
7
7
|
var scroll = useCallback(function (to, offset, callback, fallbackTimeout, behavior) {
|
|
8
8
|
if (offset === void 0) { offset = 0; }
|
|
@@ -17,10 +17,10 @@ export function useSmoothScroll() {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
if (isNumber(top)) {
|
|
20
|
-
top = top +
|
|
20
|
+
top = top + offset + (disregardFixedOffset ? 0 : fixedOffset.current);
|
|
21
21
|
scrollTo(top, callback, fallbackTimeout, behavior);
|
|
22
22
|
}
|
|
23
|
-
}, [fixedOffset]);
|
|
23
|
+
}, [disregardFixedOffset, fixedOffset]);
|
|
24
24
|
return scroll;
|
|
25
25
|
}
|
|
26
26
|
export default useSmoothScroll;
|
package/node/hooks/index.js
CHANGED
|
@@ -17,6 +17,7 @@ tslib_1.__exportStar(require("./useNavigateAway"), exports);
|
|
|
17
17
|
tslib_1.__exportStar(require("./usePrevious"), exports);
|
|
18
18
|
tslib_1.__exportStar(require("./usePreviousRef"), exports);
|
|
19
19
|
tslib_1.__exportStar(require("./useScrollPosition"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./useScrollThreshold"), exports);
|
|
20
21
|
// export * from "./useScrollTo";
|
|
21
22
|
tslib_1.__exportStar(require("./useSmoothScroll"), exports);
|
|
22
23
|
tslib_1.__exportStar(require("./useTraceUpdate"), exports);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useScrollThreshold = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var utils_1 = require("@koine/utils");
|
|
6
|
+
var dom_1 = require("@koine/dom");
|
|
7
|
+
var useScrollThreshold = function (threshold, callback) {
|
|
8
|
+
var _a = (0, react_1.useState)(false), isBelow = _a[0], setIsBelow = _a[1];
|
|
9
|
+
var handler = (0, react_1.useCallback)(function () {
|
|
10
|
+
if (threshold) {
|
|
11
|
+
var posY = window.scrollY; // * -1;
|
|
12
|
+
var isAbove = posY < threshold;
|
|
13
|
+
var isBelow_1 = posY > threshold;
|
|
14
|
+
// console.log("useScrollThreshold setIsBelow", isBelow, posY, threshold);
|
|
15
|
+
setIsBelow(isBelow_1);
|
|
16
|
+
if (callback)
|
|
17
|
+
callback(isAbove, isBelow_1);
|
|
18
|
+
}
|
|
19
|
+
}, [threshold, callback]);
|
|
20
|
+
(0, react_1.useEffect)(function () {
|
|
21
|
+
if (threshold) {
|
|
22
|
+
// const listener = listenScroll(handler, 50);
|
|
23
|
+
var listener = (0, dom_1.on)(window, "scroll", handler, { passive: true });
|
|
24
|
+
handler();
|
|
25
|
+
return listener;
|
|
26
|
+
}
|
|
27
|
+
return utils_1.noop;
|
|
28
|
+
}, [threshold, handler]);
|
|
29
|
+
return isBelow;
|
|
30
|
+
};
|
|
31
|
+
exports.useScrollThreshold = useScrollThreshold;
|
|
32
|
+
exports.default = exports.useScrollThreshold;
|
|
@@ -5,7 +5,7 @@ var react_1 = require("react");
|
|
|
5
5
|
var utils_1 = require("@koine/utils");
|
|
6
6
|
var dom_1 = require("@koine/dom");
|
|
7
7
|
var useFixedOffset_1 = require("./useFixedOffset");
|
|
8
|
-
function useSmoothScroll() {
|
|
8
|
+
function useSmoothScroll(disregardFixedOffset) {
|
|
9
9
|
var fixedOffset = (0, useFixedOffset_1.useFixedOffset)();
|
|
10
10
|
var scroll = (0, react_1.useCallback)(function (to, offset, callback, fallbackTimeout, behavior) {
|
|
11
11
|
if (offset === void 0) { offset = 0; }
|
|
@@ -20,10 +20,10 @@ function useSmoothScroll() {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
if ((0, utils_1.isNumber)(top)) {
|
|
23
|
-
top = top +
|
|
23
|
+
top = top + offset + (disregardFixedOffset ? 0 : fixedOffset.current);
|
|
24
24
|
(0, dom_1.scrollTo)(top, callback, fallbackTimeout, behavior);
|
|
25
25
|
}
|
|
26
|
-
}, [fixedOffset]);
|
|
26
|
+
}, [disregardFixedOffset, fixedOffset]);
|
|
27
27
|
return scroll;
|
|
28
28
|
}
|
|
29
29
|
exports.useSmoothScroll = useSmoothScroll;
|
package/package.json
CHANGED
|
@@ -44,6 +44,26 @@
|
|
|
44
44
|
},
|
|
45
45
|
"main": "./node/index.js",
|
|
46
46
|
"types": "./index.d.ts",
|
|
47
|
-
"
|
|
47
|
+
"dependencies": {},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"styled-components": "5.3.6",
|
|
50
|
+
"framer-motion": "8.5.5",
|
|
51
|
+
"react": "18.2.0",
|
|
52
|
+
"@mui/base": "5.0.0-alpha.115",
|
|
53
|
+
"@koine/utils": "1.1.5",
|
|
54
|
+
"ts-debounce": "4.0.0",
|
|
55
|
+
"type-fest": "3.5.3",
|
|
56
|
+
"react-icons": "4.7.1",
|
|
57
|
+
"date-fns": "2.29.3",
|
|
58
|
+
"react-swipeable": "7.0.0",
|
|
59
|
+
"@tiptap/react": "2.0.0-beta.209",
|
|
60
|
+
"@tiptap/starter-kit": "2.0.0-beta.209",
|
|
61
|
+
"@kuus/yup": "1.0.0-beta.7",
|
|
62
|
+
"react-hook-form": "7.42.1",
|
|
63
|
+
"@koine/dom": "1.1.5",
|
|
64
|
+
"react-popper": "2.3.0",
|
|
65
|
+
"tslib": "2.5.0"
|
|
66
|
+
},
|
|
67
|
+
"version": "1.1.5",
|
|
48
68
|
"module": "./index.js"
|
|
49
69
|
}
|