# All files / src/list getListItemHeight.ts

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

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
    731x
    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
    353x
    353x
    353x
    353x
    353x
    353x
    353x
    353x
    353x
    353x
    353x
    353x
    8x
    8x
    345x
    345x
    353x
    315x
    353x
    353x
    343x
    353x
    353x
    38x
    339x
    175x
    353x
    353x
    353x
    19x
    19x
    326x
    353x
    4x
    4x
    322x
    353x
    193x
    193x
    129x
    129x
    129x
     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}
       * @defaultValue `"auto"`
       */
      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 = "auto",
        leftAddon,
        leftAddonType = "icon",
        rightAddon,
        rightAddonType = "icon",
        secondaryText,
      } = options;

      if (height !== "auto") {
        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";
    }