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