@thecb/components 7.7.8-beta.7 → 7.7.8-beta.8
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 +11 -14
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +11 -14
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/util/useCheckElementsInViewport.js +17 -14
package/dist/index.esm.js
CHANGED
|
@@ -24467,32 +24467,29 @@ var useOutsideClickHook = function useOutsideClickHook(handler) {
|
|
|
24467
24467
|
the string given.
|
|
24468
24468
|
|
|
24469
24469
|
A combination string of multiple selectors can also be provided as an item in the array, e.g.:
|
|
24470
|
-
".alert-info, .alert-warning, .alert-error"
|
|
24470
|
+
".alert-info, .alert-warning, .alert-error". This will return the first element that matches *any* of the provided selectors.
|
|
24471
24471
|
|
|
24472
|
-
|
|
24472
|
+
If the element is present in the DOM (domEL !== null), the function examines the element's bounding box
|
|
24473
|
+
to determine if the element is within the viewport. If any portion of the element is outside of
|
|
24474
|
+
the viewport, the function returns false.
|
|
24473
24475
|
|
|
24474
|
-
If
|
|
24476
|
+
If all elements that exist are within the viewport, the function returns true.
|
|
24475
24477
|
*/
|
|
24476
24478
|
|
|
24477
24479
|
var useCheckElementsInViewport = function useCheckElementsInViewport() {
|
|
24478
24480
|
var elements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
24479
|
-
|
|
24480
|
-
var _useState = useState(false),
|
|
24481
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
24482
|
-
elementsVisible = _useState2[0],
|
|
24483
|
-
setElementsVisible = _useState2[1];
|
|
24484
|
-
|
|
24481
|
+
var elementsVisible = true;
|
|
24485
24482
|
var viewportWidth = window.innerWidth || document.documentElement.clientWidth;
|
|
24486
24483
|
var viewportHeight = window.innerHeight || document.documentElement.clientHeight;
|
|
24487
24484
|
useLayoutEffect(function () {
|
|
24488
24485
|
elements.forEach(function (element) {
|
|
24489
|
-
console.log("element is", element);
|
|
24490
24486
|
var domEl = document.querySelector(element);
|
|
24491
|
-
|
|
24492
|
-
var boundingBox = domEl === null || domEl === void 0 ? void 0 : domEl.getBoundingClientRect();
|
|
24487
|
+
var boundingBox = domEl === null || domEl === void 0 ? void 0 : domEl.getBoundingClientRect(); // Skip any elements not in the DOM
|
|
24493
24488
|
|
|
24494
|
-
if (
|
|
24495
|
-
|
|
24489
|
+
if (domEl !== null) {
|
|
24490
|
+
if (boundingBox.top < 0 || boundingBox.left < 0 || boundingBox.right > viewportWidth || boundingBox.bottom > viewportHeight) {
|
|
24491
|
+
elementsVisible = false;
|
|
24492
|
+
}
|
|
24496
24493
|
}
|
|
24497
24494
|
});
|
|
24498
24495
|
}, [elements, viewportWidth, viewportHeight]);
|