@adamjanicki/ui 1.4.1 → 1.4.2
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 -1
- package/hooks/index.js +1 -1
- package/hooks/useScroll.d.ts +9 -0
- package/hooks/useScroll.js +23 -0
- package/package.json +1 -1
- package/hooks/useWatchScroll.d.ts +0 -7
- package/hooks/useWatchScroll.js +0 -13
package/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { default as useScrollLock } from "./useScrollLock";
|
|
2
2
|
export { default as useMediaQuery } from "./useMediaQuery";
|
|
3
|
-
export { default as
|
|
3
|
+
export { default as useScroll } from "./useScroll";
|
|
4
4
|
export { default as useFocusTrap } from "./useFocusTrap";
|
|
5
5
|
export { default as useScrollToHash } from "./useScrollToHash";
|
|
6
6
|
export { default as useWindowResize } from "./useWindowResize";
|
package/hooks/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { default as useScrollLock } from "./useScrollLock";
|
|
2
2
|
export { default as useMediaQuery } from "./useMediaQuery";
|
|
3
|
-
export { default as
|
|
3
|
+
export { default as useScroll } from "./useScroll";
|
|
4
4
|
export { default as useFocusTrap } from "./useFocusTrap";
|
|
5
5
|
export { default as useScrollToHash } from "./useScrollToHash";
|
|
6
6
|
export { default as useWindowResize } from "./useWindowResize";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A hook getting the current scroll position of the window.
|
|
4
|
+
* @returns an object containing the current scroll position of the window.
|
|
5
|
+
*/
|
|
6
|
+
var useScroll = function () {
|
|
7
|
+
var _a = useState({
|
|
8
|
+
scrollX: window.scrollX,
|
|
9
|
+
scrollY: window.scrollY,
|
|
10
|
+
}), scroll = _a[0], setScroll = _a[1];
|
|
11
|
+
useEffect(function () {
|
|
12
|
+
var onScroll = function () {
|
|
13
|
+
setScroll({
|
|
14
|
+
scrollX: window.scrollX,
|
|
15
|
+
scrollY: window.scrollY,
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
window.addEventListener("scroll", onScroll);
|
|
19
|
+
return function () { return window.removeEventListener("scroll", onScroll); };
|
|
20
|
+
}, []);
|
|
21
|
+
return scroll;
|
|
22
|
+
};
|
|
23
|
+
export default useScroll;
|
package/package.json
CHANGED
package/hooks/useWatchScroll.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
/**
|
|
3
|
-
* A hook for watching the window scroll.
|
|
4
|
-
*
|
|
5
|
-
* @param onScroll the callback for when the window is scrolled
|
|
6
|
-
*/
|
|
7
|
-
var useWatchScroll = function (onScroll) {
|
|
8
|
-
useEffect(function () {
|
|
9
|
-
window.addEventListener("scroll", onScroll);
|
|
10
|
-
return function () { return window.removeEventListener("scroll", onScroll); };
|
|
11
|
-
}, [onScroll]);
|
|
12
|
-
};
|
|
13
|
-
export default useWatchScroll;
|