@weser/hooks 0.0.1 → 0.0.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @weser/hooks
2
2
 
3
- <img alt="npm version" src="https://badge.fury.io/js/@weser/hooks.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>
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
 
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
+ export { default as useBreakpoint } from './useBreakpoint.js';
1
2
  export { default as useClickAway } from './useClickAway.js';
2
3
  export { default as useClientOnly } from './useClientOnly.js';
3
4
  export { default as useDisclosure } from './useDisclosure.js';
4
5
  export { default as useFocusTrap } from './useFocusTrap.js';
5
6
  export { default as useKeyDown } from './useKeyDown.js';
7
+ export { default as useRerender } from './useRerender.js';
6
8
  export { default as useRouteChange } from './useRouteChange.js';
7
9
  export { default as useScrollBlocking } from './useScrollBlocking.js';
8
10
  export { default as useTrigger } from './useTrigger.js';
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
+ export { default as useBreakpoint } from './useBreakpoint.js';
1
2
  export { default as useClickAway } from './useClickAway.js';
2
3
  export { default as useClientOnly } from './useClientOnly.js';
3
4
  export { default as useDisclosure } from './useDisclosure.js';
4
5
  export { default as useFocusTrap } from './useFocusTrap.js';
5
6
  export { default as useKeyDown } from './useKeyDown.js';
7
+ export { default as useRerender } from './useRerender.js';
6
8
  export { default as useRouteChange } from './useRouteChange.js';
7
9
  export { default as useScrollBlocking } from './useScrollBlocking.js';
8
10
  export { default as useTrigger } from './useTrigger.js';
@@ -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
+ }
@@ -0,0 +1 @@
1
+ export default function useRerender(updateInterval?: number): Date;
@@ -0,0 +1,11 @@
1
+ import { useEffect, useState } from 'react';
2
+ export default function useRerender(updateInterval = 60 * 1000) {
3
+ const [time, setTime] = useState(new Date());
4
+ useEffect(() => {
5
+ const interval = setInterval(() => {
6
+ setTime(new Date());
7
+ }, updateInterval);
8
+ return () => clearInterval(interval);
9
+ }, []);
10
+ return time;
11
+ }
@@ -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.1",
3
+ "version": "0.0.3",
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": "f8cd929768ab80c7c441f66770df2a95c33318a7"
55
+ "gitHead": "de1f00e9f6100c1e0ccfdb8145af827e027c280a"
56
56
  }