@procore/core-react
Version:
React library of Procore Design Guidelines
59 lines • 2.76 kB
JavaScript
import { breakpointRawMinWidthValues } from '../Grid/Grid.constants';
var adjustMaxWidth = function adjustMaxWidth(breakpointMinWidth) {
return breakpointMinWidth - 0.02;
};
export var mediaBreakpointsDown = {
tabletMd: "(max-width: ".concat(adjustMaxWidth(breakpointRawMinWidthValues.tabletMd), "px)"),
tabletLg: "(max-width: ".concat(adjustMaxWidth(breakpointRawMinWidthValues.tabletLg), "px)"),
desktopMd: "(max-width: ".concat(adjustMaxWidth(breakpointRawMinWidthValues.desktopMd), "px)")
};
export var getIsUsingSmallScreen = function getIsUsingSmallScreen() {
var _globalThis$matchMedi;
return (_globalThis$matchMedi = globalThis.matchMedia) === null || _globalThis$matchMedi === void 0 ? void 0 : _globalThis$matchMedi.call(globalThis, mediaBreakpointsDown.tabletMd).matches;
};
export var wait = function wait(ms) {
return new Promise(function (resolve) {
return setTimeout(resolve, ms);
});
};
export function getBottomOffsetForFooterUseCase(footerEl, globalBottomOffset) {
var _footerRect$y;
var viewportHeight = globalThis.innerHeight;
var footerRect = footerEl.getBoundingClientRect();
var footerTop = (_footerRect$y = footerRect.y) !== null && _footerRect$y !== void 0 ? _footerRect$y : footerRect.top;
var footerHeight = footerRect.height;
var isSmallScreen = getIsUsingSmallScreen();
var isPageFooterSticky = footerEl.dataset.sticky === 'sticky';
if (isSmallScreen) {
if (isPageFooterSticky) {
return globalBottomOffset + viewportHeight - footerTop;
}
return globalBottomOffset + footerHeight;
}
if (isPageFooterSticky) {
// align with the sticky footer in the rest of use cases
return viewportHeight - footerRect.bottom;
}
return null;
}
export function getGlobalBottomOffset(containerEl) {
var lowerBoundary = containerEl.getBoundingClientRect();
var lowerBoundaryTopOffset = lowerBoundary.bottom;
var viewportHeight = document.documentElement.clientHeight;
return Math.max(viewportHeight - lowerBoundaryTopOffset, 0);
}
export function getGlobalTopOffset(containerEl) {
var _upperBoundary$y;
var upperBoundary = containerEl.getBoundingClientRect();
var upperBoundaryTopOffset = (_upperBoundary$y = upperBoundary.y) !== null && _upperBoundary$y !== void 0 ? _upperBoundary$y : upperBoundary.top;
return Math.max(upperBoundaryTopOffset, 0);
}
export function getRightOffset(containerEl) {
var containerRight = containerEl.getBoundingClientRect().right;
var viewportWidth = document.documentElement.clientWidth;
return viewportWidth - containerRight;
}
export function getIsIntersectingVertically(upperEl, lowerEl) {
return upperEl.getBoundingClientRect().bottom > lowerEl.getBoundingClientRect().top;
}
//# sourceMappingURL=PageLayout.utils.js.map