# All files / src/card styles.ts

100% Statements 203/203
100% Branches 13/13
100% Functions 7/7
100% Lines 203/203

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
    2041x
    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
    89x
    89x
    89x
    89x
    89x
    89x
    89x
    89x
    89x
    89x
    89x
    89x
    89x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    5x
    5x
    5x
    5x
    5x
    5x
    5x
    5x
    5x
    5x
    5x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    5x
    5x
    5x
    5x
    5x
    5x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    4x
    4x
    4x
    4x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    4x
    4x
    4x
    4x
    4x
    4x
    4x
    4x
    4x
    4x
    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
    84x
    84x
    84x
    84x
    84x
    84x
    84x
    84x
    84x
    84x
    84x
    84x
    84x
    84x
    84x
    84x
    84x
    84x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    4x
    4x
    4x
    4x
     import { cnb } from "cnbuilder";
    import { bem } from "../utils/bem.js";
    import { cssUtils } from "../cssUtils.js";

    const cardStyles = bem("rmd-card");

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

      /**
       * Set this to `true` if the card should use apply an inset `border` instead
       * of `box-shadow`.
       *
       * @defaultValue `false`
       */
      bordered?: boolean;

      /**
       * Set this to `true` if the card should gain additional box shadow while
       * hovered.
       *
       * @defaultValue `false`
       */
      raisable?: boolean;

      /**
       * Update the card to have `display: block` and `width: 100%` instead of
       * `display: inline-block`.
       *
       * @defaultValue `false`
       */
      fullWidth?: boolean;

      /**
       * Set this to `true` if the card should gain the pointer cursor while
       * hovering and other interaction styles and not using the `ClickableCard`
       * component.
       *
       * @defaultValue `false`
       */
      interactable?: boolean;
    }

    /**
     * @remarks \@since 6.0.0
     */
    export function card(options: CardClassNameOptions = {}): string {
      const { className, bordered, raisable, fullWidth, interactable } = options;

      return cnb(
        cardStyles({
          bordered,
          shadowed: !bordered,
          raisable: !bordered && raisable,
          interactable,
          "full-width": fullWidth,
        }),
        className
      );
    }

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

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

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

    /**
     * @remarks \@since 6.0.0
     */
    export function cardHeader(options: CardHeaderClassNameOptions = {}): string {
      const { className, addonAfter = false, addonBefore = false } = options;

      return cnb(
        cardStyles("header", {
          "addon-after": addonAfter && !addonBefore,
          "addon-before": addonBefore && !addonAfter,
          surrounded: addonAfter && addonBefore,
        }),
        className
      );
    }

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

    /**
     * @remarks \@since 6.0.0
     */
    export function cardHeaderContent(
      options: CardHeaderContentClassNameOptions = {}
    ): string {
      const { className } = options;

      return cnb(cardStyles("header-content"), className);
    }

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

    /**
     * @remarks \@since 6.0.0
     */
    export function cardTitle(options: CardTitleClassNameOptions = {}): string {
      const { className } = options;

      return cnb(cardStyles("title"), className);
    }

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

    /**
     * @remarks \@since 6.0.0
     */
    export function cardSubtitle(
      options: CardSubtitleClassNameOptions = {}
    ): string {
      const { className } = options;

      return cnb(
        cardStyles("subtitle"),
        cssUtils({ textColor: "text-secondary" }),
        className
      );
    }

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

      /**
       * Set this to `true` to disable the card's padding.
       *
       * @defaultValue `false`
       */
      disablePadding?: boolean;

      /**
       * Set this to `true` to disable applying the `text-secondary-color`.
       *
       * @defaultValue `false`
       */
      disableSecondaryColor?: boolean;

      /**
       * Set this to `true` to disable applying extra `padding-bottom` if the
       * `CardContent` component is the last child.
       *
       * @defaultValue `false`
       * @remarks \@since 6.0.0 Renamed from `disableExtraPadding`
       */
      disableLastChildPadding?: boolean;
    }

    /**
     * @remarks \@since 6.0.0
     */
    export function cardContent(options: CardContentClassNameOptions = {}): string {
      const {
        className,
        disablePadding,
        disableSecondaryColor,
        disableLastChildPadding,
      } = options;

      return cnb(
        cardStyles("content", {
          padded: !disablePadding,
          "padding-bottom": !disableLastChildPadding,
        }),
        cssUtils({
          textColor: !disableSecondaryColor ? "text-secondary" : undefined,
        }),
        className
      );
    }

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

    /**
     * @remarks \@since 6.0.0
     */
    export function cardFooter(options: CardFooterClassNameOptions = {}): string {
      const { className } = options;

      return cnb(cardStyles("footer"), className);
    }