# All files / list ListItemChildren.tsx

100% Statements 120/120
88.88% Branches 8/9
100% Functions 1/1
100% Lines 120/120

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
    1211x
    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
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    887x
    887x
    887x
    887x
    887x
    887x
    887x
    887x
    887x
    887x
    887x
    887x
    887x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
    891x
     import { type ReactElement } from "react";
    import { ListItemAddon } from "./ListItemAddon.js";
    import { ListItemText } from "./ListItemText.js";
    import { type ListItemChildrenProps } from "./types.js";

    /**
     * **Server Component**
     *
     * The `ListItemChildren` component is used to create a styled list item that
     * can have optional addons to the left or right of the children in the form of
     * icons, avatars, or media. The `children` can be replaced by the `primaryText`
     * and `secondaryText` props to create stacked text spanning two or more lines
     * with the default behavior of using `line-clamp` at three lines.
     *
     * Note: This will return a `React.Fragment` of the children and does not wrap
     * in a DOM node for styling. The parent component should normally have
     * `display: flex` for the styling to work.
     *
     * @example
     * Custom Component Usage
     * ```tsx
     * import { ListItemChildren } from "@react-md/core";
     * import FavoriteIcon from "@react-md/material-icons/FavoriteIcon";
     * import type { ReactElement } from "react";
     *
     * function Example(): ReactElement {
     *   return (
     *     <div style={{ display: "flex" }}>
     *       <ListItemChildren
     *         leftAddon={<FavoriteIcon />}
     *         rightAddon={<img alt="" src="/some-image.png" />}
     *         rightAddonType="media"
     *         secondaryText={<span>Some <strong>additional</strong> content.</span>}
     *       >
     *         Content
     *       </ListItemChildren>
     *     </div>
     *   );
     * }
     * ```
     */
    export function ListItemChildren(props: ListItemChildrenProps): ReactElement {
      const {
        multiline,
        textProps,
        textClassName,
        secondaryTextClassName,
        disableTextChildren,
        primaryText,
        secondaryText,
        secondaryTextProps,
        leftAddon,
        leftAddonType = "icon",
        leftAddonPosition = "middle",
        leftAddonClassName,
        leftAddonForceWrap,
        disableLeftAddonSpacing,
        disableLeftAddonCenteredMedia,
        rightAddon,
        rightAddonType = "icon",
        rightAddonPosition = "middle",
        rightAddonClassName,
        rightAddonForceWrap,
        disableRightAddonCenteredMedia,
        children: propChildren,
      } = props;

      const stringifiedChildren =
        typeof propChildren === "number" ? `${propChildren}` : propChildren;

      let children = stringifiedChildren;
      if (primaryText || secondaryText || !disableTextChildren) {
        children = (
          <ListItemText
            {...textProps}
            className={textClassName}
            secondaryText={secondaryText}
            secondaryTextProps={secondaryTextProps}
            secondaryTextClamped={multiline}
            secondaryTextClassName={secondaryTextClassName}
          >
            {(!disableTextChildren && children) || primaryText}
          </ListItemText>
        );
      }

      children = (
        <ListItemAddon
          addon={leftAddon}
          type={leftAddonType}
          position={leftAddonPosition}
          className={leftAddonClassName}
          forceAddonWrap={leftAddonForceWrap}
          disableBeforeSpacing={disableLeftAddonSpacing}
          disableCenteredMedia={disableLeftAddonCenteredMedia}
        >
          {children}
        </ListItemAddon>
      );
      children = (
        <ListItemAddon
          addon={rightAddon}
          addonAfter
          type={rightAddonType}
          position={rightAddonPosition}
          className={rightAddonClassName}
          forceAddonWrap={rightAddonForceWrap}
          disableCenteredMedia={disableRightAddonCenteredMedia}
        >
          {children}
        </ListItemAddon>
      );

      return (
        <>
          {children}
          {(primaryText && stringifiedChildren) || null}
        </>
      );
    }