@adamjanicki/ui 1.2.1 → 1.2.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
@@ -3,3 +3,4 @@ export { default as useMediaQuery } from "./useMediaQuery";
3
3
  export { default as useWatchScroll } from "./useWatchScroll";
4
4
  export { default as useFocusTrap } from "./useFocusTrap";
5
5
  export { default as useScrollToHash } from "./useScrollToHash";
6
+ export { default as useWindowResize } from "./useWindowResize";
package/hooks/index.js CHANGED
@@ -3,3 +3,4 @@ export { default as useMediaQuery } from "./useMediaQuery";
3
3
  export { default as useWatchScroll } from "./useWatchScroll";
4
4
  export { default as useFocusTrap } from "./useFocusTrap";
5
5
  export { default as useScrollToHash } from "./useScrollToHash";
6
+ export { default as useWindowResize } from "./useWindowResize";
@@ -9,7 +9,7 @@ type ScrollLock = {
9
9
  unlock: () => void;
10
10
  };
11
11
  /**
12
- * Hook to lock and unlock the scroll position
12
+ * Hook to lock and unlock the scroll position.
13
13
  * @returns Object with lock and unlock functions to lock and unlock the scroll position
14
14
  */
15
15
  declare const useScrollLock: () => ScrollLock;
@@ -1,6 +1,6 @@
1
1
  import { useCallback } from "react";
2
2
  /**
3
- * Hook to lock and unlock the scroll position
3
+ * Hook to lock and unlock the scroll position.
4
4
  * @returns Object with lock and unlock functions to lock and unlock the scroll position
5
5
  */
6
6
  var useScrollLock = function () {
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A hook that listens for window resize events.
3
+ *
4
+ * @param callback the callback function fired when the window is resized.
5
+ */
6
+ declare const useWindowResize: (callback: (event?: UIEvent) => void) => void;
7
+ export default useWindowResize;
@@ -0,0 +1,13 @@
1
+ import { useEffect } from "react";
2
+ /**
3
+ * A hook that listens for window resize events.
4
+ *
5
+ * @param callback the callback function fired when the window is resized.
6
+ */
7
+ var useWindowResize = function (callback) {
8
+ useEffect(function () {
9
+ window.addEventListener("resize", callback);
10
+ return function () { return window.removeEventListener("resize", callback); };
11
+ }, [callback]);
12
+ };
13
+ export default useWindowResize;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamjanicki/ui",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Basic UI components and hooks for React in TypeScript",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",