# All files getListItemHeight.ts

100% Statements 71/71
100% Branches 21/21
100% Functions 1/1
100% Lines 71/71

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
    721x
    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
    353x
    353x
    353x
    353x
    353x
    353x
    353x
    353x
    353x
    353x
    353x
    353x
    9x
    9x
    344x
    344x
    353x
    314x
    353x
    353x
    342x
    353x
    353x
    38x
    338x
    175x
    353x
    353x
    353x
    19x
    19x
    325x
    353x
    4x
    4x
    321x
    353x
    193x
    193x
    128x
    128x
    128x
     import type { ListItemChildrenProps, ListItemHeight } from "./types.js";

    /**
     * @remarks \@since 6.0.0
     * @internal
     */
    export interface ListItemHeightOptions
      extends Pick<
        ListItemChildrenProps,
        | "leftAddon"
        | "rightAddon"
        | "leftAddonType"
        | "rightAddonType"
        | "secondaryText"
      > {
      /**
       * @see {@link ListItemHeight}
       */
      height?: ListItemHeight;
    }

    /**
     * Gets the expected height for the `ListItem` or `SimpleListItem` based on the
     * addons and `secondaryText` props.
     *
     * @see {@link ListItemHeight}
     * @internal
     */
    export function getListItemHeight(
      options: ListItemHeightOptions = {}
    ): ListItemHeight {
      const {
        height,
        leftAddon,
        leftAddonType = "icon",
        rightAddon,
        rightAddonType = "icon",
        secondaryText,
      } = options;

      if (height) {
        return height;
      }

      const isIcon =
        (leftAddon && leftAddonType === "icon") ||
        (rightAddon && rightAddonType === "icon");
      const isAvatar =
        (leftAddon && leftAddonType === "avatar") ||
        (rightAddon && rightAddonType === "avatar");
      const isGraphic =
        (leftAddon &&
          (leftAddonType === "media" || leftAddonType === "large-media")) ||
        (rightAddon &&
          (rightAddonType === "media" || rightAddonType === "large-media"));

      // secondary text will always be extra large due to the default `line-height`
      if (isGraphic || secondaryText) {
        return "extra-large";
      }

      if (isAvatar) {
        return "large";
      }

      if (isIcon) {
        return "medium";
      }

      return "normal";
    }