# All files / src/PageLayout PageLayout.utils.ts

87.8% Statements 36/41
60% Branches 9/15
88.88% Functions 8/9
86.48% Lines 32/37

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    695x
    5x

    5x
    19x

    5x
    2x

    5x
    8x

    5x

    2x
    2x
    2x
    2x
    2x
    2x

    2x

    2x

    2x

    5x
    8x
    8x
    8x
    8x

    5x
    8x
    8x
    8x

    5x
    16x
    16x

    16x

    5x

     import { breakpointRawMinWidthValues } from '../Grid/Grid.constants'
    import { adjustMaxWidth } from './PageLayout.styles'

    export const getSmallScreenBreakpointValue = () =>
      `(max-width: ${adjustMaxWidth(breakpointRawMinWidthValues.tabletMd)}px)`

    export const getIsUsingSmallScreen = () => {
      return globalThis.matchMedia?.(getSmallScreenBreakpointValue()).matches
    }

    export const wait = (ms: number) =>
      new Promise<void>((resolve) => setTimeout(resolve, ms))

    export function getBottomOffsetForFooterUseCase(
      footerEl: HTMLDivElement,
      globalBottomOffset: number
    ) {
      const viewportHeight = document.documentElement.clientHeight
      const footerRect = footerEl.getBoundingClientRect()
      const footerTop = footerRect.y ?? footerRect.top
      const footerHeight = footerRect.height
      const isSmallScreen = getIsUsingSmallScreen()
      const isPageFooterSticky = footerEl.dataset.sticky === 'sticky'

      Iif (isSmallScreen) {
        Iif (isPageFooterSticky) {
          return globalBottomOffset + viewportHeight - footerTop
        }

        return globalBottomOffset + footerHeight
      }

      Iif (isPageFooterSticky) {
        // align with the sticky footer in the rest of use cases
        return viewportHeight - footerRect.bottom
      }

      return null
    }

    export function getGlobalBottomOffset(containerEl: HTMLDivElement) {
      const lowerBoundary = containerEl.getBoundingClientRect()
      const lowerBoundaryTopOffset = lowerBoundary.bottom
      const viewportHeight = document.documentElement.clientHeight
      return Math.max(viewportHeight - lowerBoundaryTopOffset, 0)
    }

    export function getGlobalTopOffset(containerEl: HTMLDivElement) {
      const upperBoundary = containerEl.getBoundingClientRect()
      const upperBoundaryTopOffset = upperBoundary.y ?? upperBoundary.top
      return Math.max(upperBoundaryTopOffset, 0)
    }

    export function getRightOffset(containerEl: HTMLDivElement) {
      const containerRight = containerEl.getBoundingClientRect().right
      const viewportWidth = document.documentElement.clientWidth

      return viewportWidth - containerRight
    }

    export function getIsIntersectingVertically(
      upperEl: HTMLElement,
      lowerEl: HTMLElement
    ) {
      return (
        upperEl.getBoundingClientRect().bottom > lowerEl.getBoundingClientRect().top
      )
    }