UNPKG

7.09 kBJavaScriptView Raw
1'use client';
2
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import composeClasses from '@mui/utils/composeClasses';
7import Typography, { typographyClasses } from "../Typography/index.js";
8import ListContext from "../List/ListContext.js";
9import { styled } from "../zero-styled/index.js";
10import { useDefaultProps } from "../DefaultPropsProvider/index.js";
11import listItemTextClasses, { getListItemTextUtilityClass } from "./listItemTextClasses.js";
12import useSlot from "../utils/useSlot.js";
13import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14const 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};
29const 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});
70const ListItemText = /*#__PURE__*/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 = /*#__PURE__*/_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 = /*#__PURE__*/_jsx(SecondarySlot, {
132 variant: "body2",
133 color: "textSecondary",
134 ...secondarySlotProps,
135 children: secondary
136 });
137 }
138 return /*#__PURE__*/_jsxs(ListItemTextRoot, {
139 className: clsx(classes.root, className),
140 ownerState: ownerState,
141 ref: ref,
142 ...other,
143 children: [primary, secondary]
144 });
145});
146process.env.NODE_ENV !== "production" ? ListItemText.propTypes /* remove-proptypes */ = {
147 // ┌────────────────────────────── Warning ──────────────────────────────┐
148 // │ These PropTypes are generated from the TypeScript type definitions. │
149 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
150 // └─────────────────────────────────────────────────────────────────────┘
151 /**
152 * Alias for the `primary` prop.
153 */
154 children: PropTypes.node,
155 /**
156 * Override or extend the styles applied to the component.
157 */
158 classes: PropTypes.object,
159 /**
160 * @ignore
161 */
162 className: PropTypes.string,
163 /**
164 * If `true`, the children won't be wrapped by a Typography component.
165 * This can be useful to render an alternative Typography variant by wrapping
166 * the `children` (or `primary`) text, and optional `secondary` text
167 * with the Typography component.
168 * @default false
169 */
170 disableTypography: PropTypes.bool,
171 /**
172 * If `true`, the children are indented.
173 * This should be used if there is no left avatar or left icon.
174 * @default false
175 */
176 inset: PropTypes.bool,
177 /**
178 * The main content element.
179 */
180 primary: PropTypes.node,
181 /**
182 * These props will be forwarded to the primary typography component
183 * (as long as disableTypography is not `true`).
184 * @deprecated Use `slotProps.primary` instead. This prop will be removed in v7. See [Migrating from deprecated APIs](/material-ui/migration/migrating-from-deprecated-apis/) for more details.
185 */
186 primaryTypographyProps: PropTypes.object,
187 /**
188 * The secondary content element.
189 */
190 secondary: PropTypes.node,
191 /**
192 * These props will be forwarded to the secondary typography component
193 * (as long as disableTypography is not `true`).
194 * @deprecated Use `slotProps.secondary` instead. This prop will be removed in v7. See [Migrating from deprecated APIs](/material-ui/migration/migrating-from-deprecated-apis/) for more details.
195 */
196 secondaryTypographyProps: PropTypes.object,
197 /**
198 * The props used for each slot inside.
199 * @default {}
200 */
201 slotProps: PropTypes.shape({
202 primary: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
203 secondary: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
204 }),
205 /**
206 * The components used for each slot inside.
207 * @default {}
208 */
209 slots: PropTypes.shape({
210 primary: PropTypes.elementType,
211 secondary: PropTypes.elementType
212 }),
213 /**
214 * The system prop that allows defining system overrides as well as additional CSS styles.
215 */
216 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
217} : void 0;
218export default ListItemText;
\No newline at end of file