@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.esm.js
CHANGED
|
@@ -24467,32 +24467,54 @@ 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] : [];
|
|
24481
|
+
var elementsVisible = true;
|
|
24482
|
+
var timeoutID = false;
|
|
24483
|
+
var delay = 250;
|
|
24479
24484
|
|
|
24480
|
-
var _useState = useState(
|
|
24485
|
+
var _useState = useState(window.innerWidth || document.documentElement.clientWidth),
|
|
24481
24486
|
_useState2 = _slicedToArray(_useState, 2),
|
|
24482
|
-
|
|
24483
|
-
|
|
24487
|
+
viewportWidth = _useState2[0],
|
|
24488
|
+
setViewportWidth = _useState2[1];
|
|
24484
24489
|
|
|
24485
|
-
var
|
|
24486
|
-
|
|
24490
|
+
var _useState3 = useState(window.innerHeight || document.documentElement.clientHeight),
|
|
24491
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
24492
|
+
viewportHeight = _useState4[0],
|
|
24493
|
+
setViewportHeight = _useState4[1];
|
|
24494
|
+
|
|
24495
|
+
var updateViewportValues = function updateViewportValues() {
|
|
24496
|
+
clearTimeout(timeoutID);
|
|
24497
|
+
timeoutID = setTimeout(function () {
|
|
24498
|
+
setViewportWidth(window.innerWidth || document.documentElement.clientWidth);
|
|
24499
|
+
setViewportHeight(window.innerHeight || document.documentElement.clientHeight);
|
|
24500
|
+
}, delay);
|
|
24501
|
+
};
|
|
24502
|
+
|
|
24503
|
+
useEffect$1(function () {
|
|
24504
|
+
window.addEventListener("resize", updateViewportValues);
|
|
24505
|
+
return function () {
|
|
24506
|
+
clearTimeout(timeoutID);
|
|
24507
|
+
};
|
|
24508
|
+
}, []);
|
|
24487
24509
|
useLayoutEffect(function () {
|
|
24488
24510
|
elements.forEach(function (element) {
|
|
24489
|
-
console.log("element is", element);
|
|
24490
24511
|
var domEl = document.querySelector(element);
|
|
24491
|
-
|
|
24492
|
-
var boundingBox = domEl === null || domEl === void 0 ? void 0 : domEl.getBoundingClientRect();
|
|
24512
|
+
var boundingBox = domEl === null || domEl === void 0 ? void 0 : domEl.getBoundingClientRect(); // Skip any elements not in the DOM
|
|
24493
24513
|
|
|
24494
|
-
if (
|
|
24495
|
-
|
|
24514
|
+
if (domEl !== null) {
|
|
24515
|
+
if (boundingBox.top < 0 || boundingBox.left < 0 || boundingBox.right > viewportWidth || boundingBox.bottom > viewportHeight) {
|
|
24516
|
+
elementsVisible = false;
|
|
24517
|
+
}
|
|
24496
24518
|
}
|
|
24497
24519
|
});
|
|
24498
24520
|
}, [elements, viewportWidth, viewportHeight]);
|