# All files / src/table tableCellStyles.ts

100% Statements 83/83
25% Branches 4/16
100% Functions 1/1
100% Lines 83/83

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
    841x
    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
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
    145x
     import { cnb } from "cnbuilder";
    import { cssUtils } from "../cssUtils.js";
    import {
      type TableCellHorizontalAlignment,
      type TableCellVerticalAlignment,
    } from "./TableConfigurationProvider.js";

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

      /**
       * Set this to `true` if the cell is rendered as a `<th>` so that the correct
       * sticky styles can be applied.
       */
      header: boolean;

      /**
       * Set this to true if the cell is rendered in a `<thead>` so that the correct
       * sticky styles can be applied.
       */
      isInTableHeader: boolean;

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

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

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

      hAlign?: TableCellHorizontalAlignment;
      vAlign?: TableCellVerticalAlignment;

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

      /**
       * @defaultValue `"horizontal"`
       */
      padding?: "horizontal" | "vertical" | "none";
    }

    /**
     * @remarks \@since 6.0.0
     */
    export function tableCell(options: TableCellClassNameOptions): string {
      const {
        grow,
        sticky,
        header,
        inputToggle,
        hAlign,
        vAlign,
        lineWrap = true,
        padding = "horizontal",
        isInTableHeader,
        className,
      } = options;

      // using `&&` instead of `bem` since the latest version of typescript does not
      // support setting the same object key (empty string)
      const p = "rmd-table-cell--";
      return cnb(
        "rmd-table-cell",
        grow && `${p}grow`,
        header && `${p}header`,
        sticky && `${p}sticky`,
        inputToggle && `${p}input-toggle`,
        sticky && (!isInTableHeader || inputToggle) && `${p}sticky-cell`,
        sticky && isInTableHeader && `${p}sticky-header`,
        sticky && isInTableHeader && inputToggle && `${p}header-cell`,
        vAlign && vAlign !== "middle" && `${p}${vAlign}`,
        !lineWrap && `${p}no-wrap`,
        padding === "vertical" && `${p}v-padding`,
        padding === "none" && `${p}no-padding`,
        cssUtils({
          textAlign: hAlign,
        }),
        className
      );
    }