# All files styles.ts

100% Statements 124/124
100% Branches 9/9
100% Functions 2/2
100% Lines 124/124

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
    1251x
    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
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    42x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    41x
    41x
    41x
    41x
     import { cnb } from "cnbuilder";
    import { type BackgroundColor, cssUtils } from "../cssUtils.js";
    import { bem } from "../utils/bem.js";

    const styles = bem("rmd-chip");

    /**
     * @remarks \@since 6.0.0
     *
     * Note for the future: Once Firefox supports the `:has` selector, the
     * `leftAddon` and `rightAddon` can be removed. The styles would automatically
     * apply the padding instead:
     *
     * ```scss
     * &:has(.rmd-icon:first-child, .rmd-avatar:first-child) {
     *   @include core.auto-rtl(
     *     padding-left,
     *     $addon-left-padding,
     *     $horizontal-padding
     *   );
     * }
     *
     * $index: if(
     *   not core.$interaction-mode or core.$interaction-mode == press,
     *   1,
     *   2 // last child is always the `.rmd-ripple-container`
     * );
     * &:has(.rmd-icon:nth-last-child(#{$index})) {
     *   @include core.auto-rtl(
     *     padding-right,
     *     $addon-right-padding,
     *     $horizontal-padding
     *   );
     * }
     * ```
     */
    export interface ChipClassNameOptions {
      className?: string;
      selectedClassName?: string;

      /** @defaultValue `"solid"` */
      theme?: "outline" | "solid";

      backgroundColor?: BackgroundColor;

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

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

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

      /** @defaultValue `true` */
      noninteractive?: boolean;

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

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

      /** @defaultValue `false` */
      pressed?: boolean;
      pressedClassName?: string;
    }

    /**
     * @remarks \@since 6.0.0
     */
    export function chip(options: ChipClassNameOptions = {}): string {
      const {
        className,
        theme = "solid",
        pressed = false,
        disabled = false,
        selected = false,
        selectedThemed = false,
        selectedClassName,
        noninteractive = true,
        pressedClassName,
        leftAddon = false,
        rightAddon = false,
        backgroundColor,
      } = options;

      return cnb(
        styles({
          themed: !disabled && selected && selectedThemed,
          selected: !disabled && selected && !selectedThemed,
          solid: theme === "solid",
          outline: theme === "outline",
          disabled,
          "left-addon": leftAddon,
          "right-addon": rightAddon,
          pressed,
        }),
        selected && selectedClassName,
        pressedClassName,
        cssUtils({
          surface: !noninteractive,
          textColor: disabled ? "text-disabled" : undefined,
          backgroundColor,
        }),
        className
      );
    }

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

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

      return cnb(styles("content"), className);
    }