@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 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 useWatchScroll } from "./useWatchScroll";
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 useWatchScroll } from "./useWatchScroll";
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,9 @@
1
+ /**
2
+ * A hook getting the current scroll position of the window.
3
+ * @returns an object containing the current scroll position of the window.
4
+ */
5
+ declare const useScroll: () => {
6
+ scrollX: number;
7
+ scrollY: number;
8
+ };
9
+ export default useScroll;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamjanicki/ui",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "Basic UI components and hooks for React in TypeScript",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -1,7 +0,0 @@
1
- /**
2
- * A hook for watching the window scroll.
3
- *
4
- * @param onScroll the callback for when the window is scrolled
5
- */
6
- declare const useWatchScroll: (onScroll: () => void) => void;
7
- export default useWatchScroll;
@@ -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;