/
ListItemText.tsx
63 lines (56 loc) · 1.45 KB
/
ListItemText.tsx
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
import type { ReactElement, ReactNode } from "react";
import cn from "classnames";
import { bem } from "@react-md/utils";
export interface ListItemTextProps {
/**
* An optional `className` to apply to the `<span>` surrounding the `children`.
*/
className?: string;
/**
* An optional `className` to apply to the `<span>` surrounding the
* `secondaryText` if it was provided.
*/
secondaryTextClassName?: string;
/**
* The main text children to display. This will be stacked above the
* `secondaryText` if it was provided.
*/
children?: ReactNode;
/**
* Optional secondary text to display that will be stacked below the
* `children`. This also applies some styles to make the text less prominent
* than the `children`.
*/
secondaryText?: ReactNode;
}
const block = bem("rmd-list-item");
/**
* This component us used to create the one to three lines of text within a
* `ListItem` or `SimpleListItem`.
*/
export function ListItemText({
className,
secondaryTextClassName,
secondaryText,
children,
}: ListItemTextProps): ReactElement {
let secondaryContent: ReactNode;
if (secondaryText) {
secondaryContent = (
<span
className={cn(
block("text", { secondary: true }),
secondaryTextClassName
)}
>
{secondaryText}
</span>
);
}
return (
<span className={cn(block("text"), className)}>
{children}
{secondaryContent}
</span>
);
}