# All files / src/layout utils.ts

0% Statements 0/102
0% Branches 0/1
0% Functions 0/1
0% Lines 0/102

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
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103

     import type { AppSize } from "../AppSizeProvider";
    import {
      DEFAULT_DESKTOP_LAYOUT,
      DEFAULT_LANDSCAPE_TABLET_LAYOUT,
      DEFAULT_PHONE_LAYOUT,
      DEFAULT_TABLET_LAYOUT,
    } from "./constants";
    import type { LayoutConfiguration, SupportedWideLayout } from "./types";

    export interface GetLayoutOptions extends LayoutConfiguration {
      /**
       * The current app size which is used to determine which layout type to
       * return.
       */
      appSize: AppSize;
    }

    /**
     * Gets the current layout based on the app size and layout configuration.
     *
     * @returns The current layout type
     */
    export function getLayoutType(options: GetLayoutOptions): SupportedWideLayout {
      const {
        appSize,
        phoneLayout = DEFAULT_PHONE_LAYOUT,
        tabletLayout = DEFAULT_TABLET_LAYOUT,
        landscapeTabletLayout = DEFAULT_LANDSCAPE_TABLET_LAYOUT,
        desktopLayout = DEFAULT_DESKTOP_LAYOUT,
        largeDesktopLayout = desktopLayout,
      } = options;

      const { isPhone, isTablet, isLargeDesktop, isLandscape } = appSize;
      if (isPhone) {
        return phoneLayout;
      }

      if (isTablet) {
        return isLandscape ? landscapeTabletLayout : tabletLayout;
      }

      if (isLargeDesktop) {
        return largeDesktopLayout;
      }

      return desktopLayout;
    }

    /**
     * Checks if the current `layout` is one of the temporary types
     *
     * @param layout - The layout to check against
     * @returns true if the current layout has a temporary navigation.
     */
    export function isTemporaryLayout(layout: SupportedWideLayout): boolean {
      return layout === "temporary" || layout === "temporary-mini";
    }

    /**
     * Checks if the current `layout` is one of the toggleable types
     *
     * @param layout - The layout to check against
     * @returns true if the current layout is toggleable.
     */
    export function isToggleableLayout(layout: SupportedWideLayout): boolean {
      return layout === "toggleable" || layout === "toggleable-mini";
    }

    /**
     * Checks if the current `layout` is `"clipped"`, `"floating"`, or
     * `"full-height"`.
     *
     * @param layout - The layout to check against
     * @returns true if the current layout is persistent.
     */
    export function isPersistentLayout(layout: SupportedWideLayout): boolean {
      return (
        layout === "clipped" || layout === "floating" || layout === "full-height"
      );
    }

    /**
     * Checks if the current `layout` is the `"full-height"` variant.
     *
     * @param layout - The layout to check against
     * @returns true if the current layout is the full height variant.
     */
    export function isFullHeightLayout(layout: SupportedWideLayout): boolean {
      return layout === "full-height";
    }

    /**
     * Checks if the current `layout` is either `"temporary-mini"` or
     * `"toggleable-mini"`.
     *
     * @param layout - The layout to check against
     * @returns true if the current layout is the mini variant.
     * @remarks \@since 2.7.0
     */
    export function isMiniLayout(layout: SupportedWideLayout): boolean {
      return layout === "temporary-mini" || layout === "toggleable-mini";
    }