@thecb/components 7.7.8-beta.2 → 7.7.8-beta.4

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.2",
3
+ "version": "7.7.8-beta.4",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -4,23 +4,28 @@ import { useEffect, useState } from "react";
4
4
  Hook that determines whether every element in an array of DOM selectors is fully present
5
5
  within the user's current viewport.
6
6
 
7
- (elements: Array<String>) => Boolean;
7
+ (elements: Array<String>, Function) => undefined;
8
8
 
9
9
  Takes an array of strings that correspond to DOM selectors. Examples:
10
10
  "#submit-button", ".module-small", "h2.alert-title"
11
11
 
12
+ Also takes a handler function (such as a useState updater) to receive the Boolean
13
+ that the hook generates
14
+
12
15
  The document query function will return the *first* element in the document that matches
13
16
  the string given.
14
17
 
15
- A combination string of multiple selectors can also be provided, e.g.:
18
+ A combination string of multiple selectors can also be provided as an item in the array, e.g.:
16
19
  ".alert-info, .alert-warning, .alert-error"
17
20
 
18
21
  This will return the first element that matches *any* of the provided selectors
19
22
 
20
23
  If every element in the array is fully within the viewport, function returns true
24
+
25
+ Calls the provided handler function with the Boolean result
21
26
  */
22
27
 
23
- const useCheckElementsInViewport = (elements = []) => {
28
+ const useCheckElementsInViewport = (elements = [], handler) => {
24
29
  const [elementsVisible, setElementsVisible] = useState(false);
25
30
  const viewportWidth =
26
31
  window.innerWidth || document.documentElement.clientWidth;
@@ -41,9 +46,9 @@ const useCheckElementsInViewport = (elements = []) => {
41
46
  setElementsVisible(true);
42
47
  }
43
48
  });
44
- }, [elements]);
49
+ }, [elements, viewportWidth, viewportHeight]);
45
50
 
46
- return elementsVisible;
51
+ handler(elementsVisible);
47
52
  };
48
53
 
49
54
  export default useCheckElementsInViewport;