1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import composeClasses from '@mui/utils/composeClasses';
|
7 | import Typography, { typographyClasses } from "../Typography/index.js";
|
8 | import ListContext from "../List/ListContext.js";
|
9 | import { styled } from "../zero-styled/index.js";
|
10 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
11 | import listItemTextClasses, { getListItemTextUtilityClass } from "./listItemTextClasses.js";
|
12 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
13 | const useUtilityClasses = ownerState => {
|
14 | const {
|
15 | classes,
|
16 | inset,
|
17 | primary,
|
18 | secondary,
|
19 | dense
|
20 | } = ownerState;
|
21 | const slots = {
|
22 | root: ['root', inset && 'inset', dense && 'dense', primary && secondary && 'multiline'],
|
23 | primary: ['primary'],
|
24 | secondary: ['secondary']
|
25 | };
|
26 | return composeClasses(slots, getListItemTextUtilityClass, classes);
|
27 | };
|
28 | const ListItemTextRoot = styled('div', {
|
29 | name: 'MuiListItemText',
|
30 | slot: 'Root',
|
31 | overridesResolver: (props, styles) => {
|
32 | const {
|
33 | ownerState
|
34 | } = props;
|
35 | return [{
|
36 | [`& .${listItemTextClasses.primary}`]: styles.primary
|
37 | }, {
|
38 | [`& .${listItemTextClasses.secondary}`]: styles.secondary
|
39 | }, styles.root, ownerState.inset && styles.inset, ownerState.primary && ownerState.secondary && styles.multiline, ownerState.dense && styles.dense];
|
40 | }
|
41 | })({
|
42 | flex: '1 1 auto',
|
43 | minWidth: 0,
|
44 | marginTop: 4,
|
45 | marginBottom: 4,
|
46 | [`.${typographyClasses.root}:where(& .${listItemTextClasses.primary})`]: {
|
47 | display: 'block'
|
48 | },
|
49 | [`.${typographyClasses.root}:where(& .${listItemTextClasses.secondary})`]: {
|
50 | display: 'block'
|
51 | },
|
52 | variants: [{
|
53 | props: ({
|
54 | ownerState
|
55 | }) => ownerState.primary && ownerState.secondary,
|
56 | style: {
|
57 | marginTop: 6,
|
58 | marginBottom: 6
|
59 | }
|
60 | }, {
|
61 | props: ({
|
62 | ownerState
|
63 | }) => ownerState.inset,
|
64 | style: {
|
65 | paddingLeft: 56
|
66 | }
|
67 | }]
|
68 | });
|
69 | const ListItemText = React.forwardRef(function ListItemText(inProps, ref) {
|
70 | const props = useDefaultProps({
|
71 | props: inProps,
|
72 | name: 'MuiListItemText'
|
73 | });
|
74 | const {
|
75 | children,
|
76 | className,
|
77 | disableTypography = false,
|
78 | inset = false,
|
79 | primary: primaryProp,
|
80 | primaryTypographyProps,
|
81 | secondary: secondaryProp,
|
82 | secondaryTypographyProps,
|
83 | ...other
|
84 | } = props;
|
85 | const {
|
86 | dense
|
87 | } = React.useContext(ListContext);
|
88 | let primary = primaryProp != null ? primaryProp : children;
|
89 | let secondary = secondaryProp;
|
90 | const ownerState = {
|
91 | ...props,
|
92 | disableTypography,
|
93 | inset,
|
94 | primary: !!primary,
|
95 | secondary: !!secondary,
|
96 | dense
|
97 | };
|
98 | const classes = useUtilityClasses(ownerState);
|
99 | if (primary != null && primary.type !== Typography && !disableTypography) {
|
100 | primary = _jsx(Typography, {
|
101 | variant: dense ? 'body2' : 'body1',
|
102 | className: classes.primary,
|
103 | component: primaryTypographyProps?.variant ? undefined : 'span',
|
104 | ...primaryTypographyProps,
|
105 | children: primary
|
106 | });
|
107 | }
|
108 | if (secondary != null && secondary.type !== Typography && !disableTypography) {
|
109 | secondary = _jsx(Typography, {
|
110 | variant: "body2",
|
111 | className: classes.secondary,
|
112 | color: "textSecondary",
|
113 | ...secondaryTypographyProps,
|
114 | children: secondary
|
115 | });
|
116 | }
|
117 | return _jsxs(ListItemTextRoot, {
|
118 | className: clsx(classes.root, className),
|
119 | ownerState: ownerState,
|
120 | ref: ref,
|
121 | ...other,
|
122 | children: [primary, secondary]
|
123 | });
|
124 | });
|
125 | process.env.NODE_ENV !== "production" ? ListItemText.propTypes = {
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | |
131 |
|
132 |
|
133 | children: PropTypes.node,
|
134 | |
135 |
|
136 |
|
137 | classes: PropTypes.object,
|
138 | |
139 |
|
140 |
|
141 | className: PropTypes.string,
|
142 | |
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 | disableTypography: PropTypes.bool,
|
150 | |
151 |
|
152 |
|
153 |
|
154 |
|
155 | inset: PropTypes.bool,
|
156 | |
157 |
|
158 |
|
159 | primary: PropTypes.node,
|
160 | |
161 |
|
162 |
|
163 |
|
164 | primaryTypographyProps: PropTypes.object,
|
165 | |
166 |
|
167 |
|
168 | secondary: PropTypes.node,
|
169 | |
170 |
|
171 |
|
172 |
|
173 | secondaryTypographyProps: PropTypes.object,
|
174 | |
175 |
|
176 |
|
177 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
178 | } : void 0;
|
179 | export default ListItemText; |
\ | No newline at end of file |