@thecb/components 7.7.8-beta.8 → 7.7.8-beta.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "7.7.8-beta.8",
3
+ "version": "7.7.8-beta.9",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -1,4 +1,4 @@
1
- import { useLayoutEffect } from "react";
1
+ import { useEffect, useLayoutEffect, useState } from "react";
2
2
 
3
3
  /*
4
4
  Hook that determines whether every element in an array of DOM selectors is fully present
@@ -24,10 +24,34 @@ import { useLayoutEffect } from "react";
24
24
 
25
25
  const useCheckElementsInViewport = (elements = []) => {
26
26
  let elementsVisible = true;
27
- const viewportWidth =
28
- window.innerWidth || document.documentElement.clientWidth;
29
- const viewportHeight =
30
- window.innerHeight || document.documentElement.clientHeight;
27
+ let timeoutID = false;
28
+ let delay = 250;
29
+ const [viewportWidth, setViewportWidth] = useState(
30
+ window.innerWidth || document.documentElement.clientWidth
31
+ );
32
+ const [viewportHeight, setViewportHeight] = useState(
33
+ window.innerHeight || document.documentElement.clientHeight
34
+ );
35
+ const updateViewportValues = () => {
36
+ clearTimeout(timeoutID);
37
+
38
+ timeoutID = setTimeout(() => {
39
+ setViewportWidth(
40
+ window.innerWidth || document.documentElement.clientWidth
41
+ );
42
+ setViewportHeight(
43
+ window.innerHeight || document.documentElement.clientHeight
44
+ );
45
+ }, delay);
46
+ };
47
+
48
+ useEffect(() => {
49
+ window.addEventListener("resize", updateViewportValues);
50
+
51
+ return () => {
52
+ clearTimeout(timeoutID);
53
+ };
54
+ }, []);
31
55
 
32
56
  useLayoutEffect(() => {
33
57
  elements.forEach(element => {