@weser/hooks 0.0.1 → 0.0.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/README.md +1 -1
- package/dist/useBreakpoint.d.ts +1 -0
- package/dist/useBreakpoint.js +19 -0
- package/dist/useScrollBlocking.js +3 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @weser/hooks
|
|
2
2
|
|
|
3
|
-
<img alt="npm version" src="https://badge.fury.io/js/@weser
|
|
3
|
+
<img alt="npm version" src="https://badge.fury.io/js/@weser%2Fhooks.svg"> <img alt="npm downloads" src="https://img.shields.io/npm/dm/@weser/hooks.svg"> <a href="https://bundlephobia.com/result?p=@weser/hooks@latest"><img alt="Bundlephobia" src="https://img.shields.io/bundlephobia/minzip/@weser/hooks.svg"></a>
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useBreakpoint(breakpoint: string, delay?: number): boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
function debounce(handler, delay) {
|
|
3
|
+
let timeout;
|
|
4
|
+
return () => {
|
|
5
|
+
clearTimeout(timeout);
|
|
6
|
+
timeout = setTimeout(handler, delay);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export default function useBreakpoint(breakpoint, delay = 250) {
|
|
10
|
+
const [isMatching, setMatching] = useState(false);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const handleResize = debounce(() => setMatching(window.matchMedia(breakpoint).matches), delay);
|
|
13
|
+
// initial check
|
|
14
|
+
handleResize();
|
|
15
|
+
window.addEventListener('resize', handleResize);
|
|
16
|
+
return () => window.removeEventListener('resize', handleResize);
|
|
17
|
+
}, []);
|
|
18
|
+
return isMatching;
|
|
19
|
+
}
|
|
@@ -8,6 +8,9 @@ function blockScrolling(scrollElement) {
|
|
|
8
8
|
scrollElement.style.top = -scrollTop + 'px';
|
|
9
9
|
}
|
|
10
10
|
function enableScrolling(scrollElement) {
|
|
11
|
+
if (scrollElement.style.position !== 'fixed') {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
11
14
|
scrollElement.style.removeProperty('position');
|
|
12
15
|
scrollElement.style.removeProperty('overflow');
|
|
13
16
|
scrollElement.style.removeProperty('top');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weser/hooks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "React hooks for building apps",
|
|
5
5
|
"author": "Robin Weser <robin@weser.io>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"rimraf": "^3.0.2",
|
|
53
53
|
"typescript": "^5.4.5"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "b99c2c249851b240ee199254de4765c97dc0bc76"
|
|
56
56
|
}
|