# All files / src/tree styles.ts

100% Statements 151/151
100% Branches 8/8
100% Functions 5/5
100% Lines 151/151

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
    1521x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    73x
    73x
    73x
    73x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    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
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    567x
    567x
    567x
    567x
    567x
    567x
    567x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    672x
    672x
    672x
    672x
     import { cnb } from "cnbuilder";
    import type { InternalListItemClassNameOptions } from "../list/listItemStyles.js";
    import { listItem } from "../list/listItemStyles.js";
    import { bem } from "../utils/bem.js";

    const treeStyles = bem("rmd-tree");
    const treeItemStyles = bem("rmd-tree-item");
    const treeGroupStyles = bem("rmd-tree-group");

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

    /**
     * Apply the `className`s for a tree component. This will be type-safe if using
     * typescript.
     *
     * @remarks \@since 6.0.0
     */
    export function tree(options: TreeClassNameOptions = {}): string {
      const { className } = options;

      return cnb(treeStyles(), className);
    }

    /** @remarks \@since 6.0.0 */
    export interface TreeItemClassNameOptions {
      className?: string;
      expander?: boolean;

      /**
       * Settings this to `true` will update the styles for the expander icon within
       * the tree item to rotate `down -> right` instead of `down -> left`.
       *
       * @defaultValue `false`
       */
      expanderLeft?: boolean;
    }

    /**
     * Apply the `className`s for a tree item component. This will be type-safe if
     * using typescript.
     *
     * @remarks \@since 6.0.0
     */
    export function treeItem(options: TreeItemClassNameOptions = {}): string {
      const { className, expander = false, expanderLeft = false } = options;

      return cnb(
        treeItemStyles({
          "expander-left": expander && expanderLeft,
          "expander-right": expander && !expanderLeft,
        }),
        className
      );
    }

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

      /**
       * Set this to `true` when the tree item is the current keyboard focus with
       * `aria-activedescendant`. This will apply the focus styles only while the
       * parent tree component is focused and the user is in keyboard mode.
       *
       *
       * @defaultValue `false`
       */
      focused?: boolean;

      /**
       * Set this to `true` hen the tree item has been selected by the user. The
       * default styles just
       *
       * @defaultValue `false`
       */
      selected?: boolean;
    }

    /**
     * @remarks \@since 6.0.0
     */
    export function treeItemContent(
      options: TreeItemContentClassNameOptions = {}
    ): string {
      const {
        className,
        link = false,
        focused,
        selected,
        disabled = false,
        ...remaining
      } = options;

      return cnb(
        treeItemStyles("content", {
          link,
          focused,
          selected,
          disabled,
        }),
        listItem({
          className,
          disabled,
          ...remaining,
        })
      );
    }

    /**
     * @remarks \@since 6.0.0
     */
    export interface TreeItemMediaClassNameOptions {
      className?: string;
      isLeafNode: boolean;
      isMediaLeftAddon: boolean;
    }

    /**
     * @remarks \@since 6.0.0
     */
    export function treeItemMedia(options: TreeItemMediaClassNameOptions): string {
      const { isLeafNode, isMediaLeftAddon, className } = options;

      return cnb(
        isMediaLeftAddon && treeItemStyles("media", { single: isLeafNode }),
        className
      );
    }

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

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

      return cnb(treeGroupStyles(), className);
    }