@thecb/components 7.7.8-beta.3 → 7.7.8-beta.5
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
|
@@ -4,14 +4,11 @@ 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
|
|
7
|
+
(elements: Array<String>) => Boolean;
|
|
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
|
-
|
|
15
12
|
The document query function will return the *first* element in the document that matches
|
|
16
13
|
the string given.
|
|
17
14
|
|
|
@@ -21,11 +18,9 @@ import { useEffect, useState } from "react";
|
|
|
21
18
|
This will return the first element that matches *any* of the provided selectors
|
|
22
19
|
|
|
23
20
|
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
|
|
26
21
|
*/
|
|
27
22
|
|
|
28
|
-
const useCheckElementsInViewport = (elements = []
|
|
23
|
+
const useCheckElementsInViewport = (elements = []) => {
|
|
29
24
|
const [elementsVisible, setElementsVisible] = useState(false);
|
|
30
25
|
const viewportWidth =
|
|
31
26
|
window.innerWidth || document.documentElement.clientWidth;
|
|
@@ -46,9 +41,9 @@ const useCheckElementsInViewport = (elements = [], handler) => {
|
|
|
46
41
|
setElementsVisible(true);
|
|
47
42
|
}
|
|
48
43
|
});
|
|
49
|
-
}, [elements]);
|
|
44
|
+
}, [elements, viewportWidth, viewportHeight]);
|
|
50
45
|
|
|
51
|
-
|
|
46
|
+
return elementsVisible;
|
|
52
47
|
};
|
|
53
48
|
|
|
54
49
|
export default useCheckElementsInViewport;
|