@thecb/components 7.7.8-beta.7 → 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/dist/index.cjs.js +35 -13
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +35 -13
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/util/useCheckElementsInViewport.js +45 -18
package/dist/index.cjs.js
CHANGED
|
@@ -24475,32 +24475,54 @@ var useOutsideClickHook = function useOutsideClickHook(handler) {
|
|
|
24475
24475
|
the string given.
|
|
24476
24476
|
|
|
24477
24477
|
A combination string of multiple selectors can also be provided as an item in the array, e.g.:
|
|
24478
|
-
".alert-info, .alert-warning, .alert-error"
|
|
24478
|
+
".alert-info, .alert-warning, .alert-error". This will return the first element that matches *any* of the provided selectors.
|
|
24479
24479
|
|
|
24480
|
-
|
|
24480
|
+
If the element is present in the DOM (domEL !== null), the function examines the element's bounding box
|
|
24481
|
+
to determine if the element is within the viewport. If any portion of the element is outside of
|
|
24482
|
+
the viewport, the function returns false.
|
|
24481
24483
|
|
|
24482
|
-
If
|
|
24484
|
+
If all elements that exist are within the viewport, the function returns true.
|
|
24483
24485
|
*/
|
|
24484
24486
|
|
|
24485
24487
|
var useCheckElementsInViewport = function useCheckElementsInViewport() {
|
|
24486
24488
|
var elements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
24489
|
+
var elementsVisible = true;
|
|
24490
|
+
var timeoutID = false;
|
|
24491
|
+
var delay = 250;
|
|
24487
24492
|
|
|
24488
|
-
var _useState = React.useState(
|
|
24493
|
+
var _useState = React.useState(window.innerWidth || document.documentElement.clientWidth),
|
|
24489
24494
|
_useState2 = _slicedToArray(_useState, 2),
|
|
24490
|
-
|
|
24491
|
-
|
|
24495
|
+
viewportWidth = _useState2[0],
|
|
24496
|
+
setViewportWidth = _useState2[1];
|
|
24492
24497
|
|
|
24493
|
-
var
|
|
24494
|
-
|
|
24498
|
+
var _useState3 = React.useState(window.innerHeight || document.documentElement.clientHeight),
|
|
24499
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
24500
|
+
viewportHeight = _useState4[0],
|
|
24501
|
+
setViewportHeight = _useState4[1];
|
|
24502
|
+
|
|
24503
|
+
var updateViewportValues = function updateViewportValues() {
|
|
24504
|
+
clearTimeout(timeoutID);
|
|
24505
|
+
timeoutID = setTimeout(function () {
|
|
24506
|
+
setViewportWidth(window.innerWidth || document.documentElement.clientWidth);
|
|
24507
|
+
setViewportHeight(window.innerHeight || document.documentElement.clientHeight);
|
|
24508
|
+
}, delay);
|
|
24509
|
+
};
|
|
24510
|
+
|
|
24511
|
+
React.useEffect(function () {
|
|
24512
|
+
window.addEventListener("resize", updateViewportValues);
|
|
24513
|
+
return function () {
|
|
24514
|
+
clearTimeout(timeoutID);
|
|
24515
|
+
};
|
|
24516
|
+
}, []);
|
|
24495
24517
|
React.useLayoutEffect(function () {
|
|
24496
24518
|
elements.forEach(function (element) {
|
|
24497
|
-
console.log("element is", element);
|
|
24498
24519
|
var domEl = document.querySelector(element);
|
|
24499
|
-
|
|
24500
|
-
var boundingBox = domEl === null || domEl === void 0 ? void 0 : domEl.getBoundingClientRect();
|
|
24520
|
+
var boundingBox = domEl === null || domEl === void 0 ? void 0 : domEl.getBoundingClientRect(); // Skip any elements not in the DOM
|
|
24501
24521
|
|
|
24502
|
-
if (
|
|
24503
|
-
|
|
24522
|
+
if (domEl !== null) {
|
|
24523
|
+
if (boundingBox.top < 0 || boundingBox.left < 0 || boundingBox.right > viewportWidth || boundingBox.bottom > viewportHeight) {
|
|
24524
|
+
elementsVisible = false;
|
|
24525
|
+
}
|
|
24504
24526
|
}
|
|
24505
24527
|
});
|
|
24506
24528
|
}, [elements, viewportWidth, viewportHeight]);
|