# All files / src/media-queries appSize.ts

100% Statements 120/120
100% Branches 0/0
100% Functions 0/0
100% Lines 120/120

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
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    1211x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
     export type QuerySize = number | `${number}${string}`;

    /** @defaultValue `47.9375em` */
    export const DEFAULT_PHONE_MAX_WIDTH = `${767 / 16}em` satisfies QuerySize;

    /** @defaultValue `48em` */
    export const DEFAULT_TABLET_MIN_WIDTH = `${768 / 16}em` satisfies QuerySize;

    /** @defaultValue `64em` */
    export const DEFAULT_TABLET_MAX_WIDTH = `${1024 / 16}em` satisfies QuerySize;

    /** @defaultValue `64.0625em` */
    export const DEFAULT_DESKTOP_MIN_WIDTH = `${1025 / 16}em` satisfies QuerySize;

    /** @defaultValue `80em` */
    export const DEFAULT_DESKTOP_LARGE_MIN_WIDTH = `${
      1280 / 16
    }em` satisfies QuerySize;

    export interface AppSizeQueries {
      /**
       * The max width to use for phones. This one is a max width unlike the others
       * since everything from 0 to this value will be considered a phone.
       *
       * @defaultValue `47.9375em`
       * @see {@link DEFAULT_PHONE_MAX_WIDTH}
       */
      phoneMaxWidth?: QuerySize;

      /**
       * The min width for a tablet device.
       *
       * @defaultValue `48em`
       * @see {@link DEFAULT_TABLET_MIN_WIDTH}
       */
      tabletMinWidth?: QuerySize;

      /**
       * The max width for a tablet device. This should normally be `1px` less than
       * the `desktopMinWidth`, but it can be any value if needed. The tablet has a
       * range of min to max so that you can have a bit more control.
       *
       * @defaultValue `64em`
       * @see {@link DEFAULT_TABLET_MAX_WIDTH}
       */
      tabletMaxWidth?: QuerySize;

      /**
       * The min width for a desktop screen.
       *
       * @defaultValue `64.0625em`
       * @see {@link DEFAULT_DESKTOP_MIN_WIDTH}
       */
      desktopMinWidth?: QuerySize;

      /**
       * The min width for a large (1440p, 4k, etc) desktop screen.
       *
       * @defaultValue `80em`
       * @see {@link DEFAULT_DESKTOP_LARGE_MIN_WIDTH}
       */
      desktopLargeMinWidth?: QuerySize;
    }

    export const DEFAULT_APP_SIZE_QUERIES: Readonly<AppSizeQueries> = {
      phoneMaxWidth: DEFAULT_PHONE_MAX_WIDTH,
      tabletMinWidth: DEFAULT_TABLET_MIN_WIDTH,
      tabletMaxWidth: DEFAULT_TABLET_MAX_WIDTH,
      desktopMinWidth: DEFAULT_DESKTOP_MIN_WIDTH,
      desktopLargeMinWidth: DEFAULT_DESKTOP_LARGE_MIN_WIDTH,
    };

    /**
     * The current size for your application. This should work both server side and
     * client side, but you will have much better results client side.
     */
    export interface AppSize {
      /**
       * Boolean if currently matching a phone by comparing the max width of the
       * device.
       */
      isPhone: boolean;

      /**
       * Boolean if currently matching a tablet by comparing the max width of the
       * device.
       */
      isTablet: boolean;

      /**
       * Boolean if currently matching a desktop screen by comparing the max width
       * of the device.
       */
      isDesktop: boolean;

      /**
       * Boolean if currently matching a large desktop screen by comparing the max
       * width of the device.
       */
      isLargeDesktop: boolean;

      /**
       * Boolean if the app is considered to be in landscape mode. This will just
       * verify that the window width is greater than the window height.
       *
       * NOTE: This might not be super accurate on Android devices since the soft
       * keyboard will change the dimensions of the viewport when it appears. It is
       * recommended to use the `useOrientation` hook as well if you'd like to get
       * the current orientation type.
       */
      isLandscape: boolean;
    }

    export const DEFAULT_APP_SIZE: AppSize = {
      isPhone: false,
      isTablet: false,
      isDesktop: true,
      isLargeDesktop: false,
      isLandscape: true,
    };