# All files / src/list listItemStyles.ts

100% Statements 206/206
100% Branches 9/9
100% Functions 3/3
100% Lines 206/206

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
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    2071x
    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
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    899x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    907x
    907x
    907x
    907x
    907x
    907x
    907x
    907x
    907x
    907x
    907x
    907x
    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
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
    1798x
     import { cnb } from "cnbuilder";
    import { cssUtils } from "../cssUtils.js";
    import { bem } from "../utils/bem.js";
    import type {
      ListItemAddonPosition,
      ListItemAddonType,
      ListItemHeight,
    } from "./types.js";

    const styles = bem("rmd-list-item");

    /** @remarks \@since 6.0.0 */
    export interface ListItemClassNameOptions {
      className?: string;
      /**
       * @see {@link ListItemHeight}
       * @defaultValue `"auto"`
       */
      height?: ListItemHeight;

      /**
       * @defaultValue `false`
       */
      multiline?: boolean;

      /**
       * @defaultValue `false`
       */
      disabled?: boolean;

      /**
       * Note: This does nothing if the `disabled` prop is not enabled.
       *
       * @defaultValue `false`
       * @remarks \@since 2.4.3
       */
      disabledOpacity?: boolean;

      /**
       * Set this to `false` if the list item should not gain the interaction
       * states: hover, focus, press, etc. This is kind of like being disabled
       * without the disabled styles being applied.
       *
       * @defaultValue `true`
       */
      clickable?: boolean;
    }

    /** @remarks \@since 6.0.0 */
    export interface InternalListItemClassNameOptions
      extends ListItemClassNameOptions {
      /**
       * @defaultValue `false`
       */
      link?: boolean;

      /**
       * This is prop is used internally when integrating with the
       * {@link useElementInteraction} hook.
       */
      pressedClassName?: string;
    }

    /**
     * @remarks \@since 6.0.0
     */
    export function listItem(
      options: InternalListItemClassNameOptions = {}
    ): string {
      const {
        className,
        link = false,
        height = "auto",
        clickable = true,
        multiline = false,
        disabled = false,
        disabledOpacity = false,
        pressedClassName,
      } = options;

      return cnb(
        styles({
          link,
          [height]: height !== "auto",
          multiline,
          "disabled-color": disabled && !disabledOpacity,
          "disabled-opacity": disabled && disabledOpacity,
        }),
        cssUtils({ surface: clickable }),
        pressedClassName,
        className
      );
    }

    /** @remarks \@since 6.0.0 */
    export interface ListItemTextClassNameOptions {
      className?: string;
      /**
       * @defaultValue `false`
       */
      clamped?: boolean;

      /**
       * @defaultValue `false`
       */
      secondary?: boolean;
    }

    /**
     * @remarks \@since 6.0.0
     */
    export function listItemText(
      options: ListItemTextClassNameOptions = {}
    ): string {
      const { className, secondary = false, clamped = false } = options;

      return cnb(
        styles("text", {
          clamped: secondary && clamped,
          secondary,
        }),
        className
      );
    }

    /** @remarks \@since 6.0.0 */
    export interface ListItemAddonClassNameOptions {
      className?: string;

      /**
       * The addon type that is used to adjust the spacing styles.
       *
       * @defaultValue `"icon"`
       */
      type?: ListItemAddonType;

      /**
       * The vertical position to use for the addon.
       *
       * @defaultValue `"middle"`
       */
      position?: ListItemAddonPosition;

      /**
       * Boolean if the addon should appear after the `children`.
       *
       * @defaultValue `false`
       */
      addonAfter?: boolean;

      /**
       * The media items are centered by default using:
       * ```scss
       * align-items: center;
       * display: flex;
       * justify-content: center;
       * ```
       *
       * When this is set to `true`, the flex styles will not be applied.
       *
       * @defaultValue `false`
       * @remarks \@since 6.0.0
       */
      disableCenteredMedia?: boolean;

      /**
       * Set this to `true` to disable the additional spacing applied to the addons
       * that appear before the `children` and the normal `--rmd-text-icon-spacing`
       * value is used instead.
       *
       * @defaultValue `false`
       */
      disableBeforeSpacing?: boolean;
    }

    /**
     *
     * @remarks \@since 6.0.0
     */
    export function listItemAddon(
      options: ListItemAddonClassNameOptions = {}
    ): string {
      const {
        type = "icon",
        position = "middle",
        className,
        addonAfter = false,
        disableCenteredMedia = false,
        disableBeforeSpacing = false,
      } = options;

      const isMedia = type === "media" || type === "large-media";
      const isAvatar = type === "avatar";

      return cnb(
        styles("addon", {
          [position]: position !== "middle",
          before: !disableBeforeSpacing && !addonAfter,
          "avatar-before": !disableBeforeSpacing && !addonAfter && isAvatar,
          media: isMedia,
          "media-large": type === "large-media",
          "media-centered": isMedia && !disableCenteredMedia,
        }),
        className
      );
    }