@thecb/components 7.7.7 → 7.7.8-beta.1
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/dist/index.cjs.js +105 -90
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +105 -90
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/.DS_Store +0 -0
- package/src/components/atoms/.DS_Store +0 -0
- package/src/components/atoms/icons/{ExternalLinkIcon.js → ExternalLinkicon.js} +0 -0
- package/src/components/molecules/highlight-tab-row/HighlightTabRow.js +1 -0
- package/src/util/index.js +9 -1
- package/src/util/useCheckElementsInViewport.js +49 -0
package/package.json
CHANGED
package/src/.DS_Store
ADDED
|
Binary file
|
|
Binary file
|
|
File without changes
|
package/src/util/index.js
CHANGED
|
@@ -3,5 +3,13 @@ import * as general from "./general";
|
|
|
3
3
|
import * as theme from "./themeUtils";
|
|
4
4
|
import useFocusInvalidInput from "./focusFirstInvalidInputHook";
|
|
5
5
|
import useOutsideClick from "./useOutsideClick";
|
|
6
|
+
import useCheckElementsInViewport from "./useCheckElementsInViewport";
|
|
6
7
|
|
|
7
|
-
export {
|
|
8
|
+
export {
|
|
9
|
+
formats,
|
|
10
|
+
general,
|
|
11
|
+
theme,
|
|
12
|
+
useFocusInvalidInput,
|
|
13
|
+
useOutsideClick,
|
|
14
|
+
useCheckElementsInViewport
|
|
15
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Hook that determines whether every element in an array of DOM selectors is fully present
|
|
5
|
+
within the user's current viewport.
|
|
6
|
+
|
|
7
|
+
(elements: Array<String>) => Boolean;
|
|
8
|
+
|
|
9
|
+
Takes an array of strings that correspond to DOM selectors. Examples:
|
|
10
|
+
"#submit-button", ".module-small", "h2.alert-title"
|
|
11
|
+
|
|
12
|
+
The document query function will return the *first* element in the document that matches
|
|
13
|
+
the string given.
|
|
14
|
+
|
|
15
|
+
A combination string of multiple selectors can also be provided, e.g.:
|
|
16
|
+
".alert-info, .alert-warning, .alert-error"
|
|
17
|
+
|
|
18
|
+
This will return the first element that matches *any* of the provided selectors
|
|
19
|
+
|
|
20
|
+
If every element in the array is fully within the viewport, function returns true
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const useCheckElementsInViewport = (elements = []) => {
|
|
24
|
+
const [elementsVisible, setElementsVisible] = useState(false);
|
|
25
|
+
const viewportWidth =
|
|
26
|
+
window.innerWidth || document.documentElement.clientWidth;
|
|
27
|
+
const viewportHeight =
|
|
28
|
+
window.innerHeight || document.documentElement.clientHeight;
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
elements.forEach(element => {
|
|
32
|
+
const domEl = document.querySelector(element);
|
|
33
|
+
const boundingBox = domEl.getBoundingClientRect();
|
|
34
|
+
|
|
35
|
+
if (
|
|
36
|
+
boundingBox.top >= 0 &&
|
|
37
|
+
boundingBox.left >= 0 &&
|
|
38
|
+
boundingBox.right <= viewportWidth &&
|
|
39
|
+
boundingBox.bottom <= viewportHeight
|
|
40
|
+
) {
|
|
41
|
+
setElementsVisible(true);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}, [elements]);
|
|
45
|
+
|
|
46
|
+
return elementsVisible;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default useCheckElementsInViewport;
|