UNPKG

5.75 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 { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13const 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};
28const 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});
69const ListItemText = /*#__PURE__*/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 = /*#__PURE__*/_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 = /*#__PURE__*/_jsx(Typography, {
110 variant: "body2",
111 className: classes.secondary,
112 color: "textSecondary",
113 ...secondaryTypographyProps,
114 children: secondary
115 });
116 }
117 return /*#__PURE__*/_jsxs(ListItemTextRoot, {
118 className: clsx(classes.root, className),
119 ownerState: ownerState,
120 ref: ref,
121 ...other,
122 children: [primary, secondary]
123 });
124});
125process.env.NODE_ENV !== "production" ? ListItemText.propTypes /* remove-proptypes */ = {
126 // ┌────────────────────────────── Warning ──────────────────────────────┐
127 // │ These PropTypes are generated from the TypeScript type definitions. │
128 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
129 // └─────────────────────────────────────────────────────────────────────┘
130 /**
131 * Alias for the `primary` prop.
132 */
133 children: PropTypes.node,
134 /**
135 * Override or extend the styles applied to the component.
136 */
137 classes: PropTypes.object,
138 /**
139 * @ignore
140 */
141 className: PropTypes.string,
142 /**
143 * If `true`, the children won't be wrapped by a Typography component.
144 * This can be useful to render an alternative Typography variant by wrapping
145 * the `children` (or `primary`) text, and optional `secondary` text
146 * with the Typography component.
147 * @default false
148 */
149 disableTypography: PropTypes.bool,
150 /**
151 * If `true`, the children are indented.
152 * This should be used if there is no left avatar or left icon.
153 * @default false
154 */
155 inset: PropTypes.bool,
156 /**
157 * The main content element.
158 */
159 primary: PropTypes.node,
160 /**
161 * These props will be forwarded to the primary typography component
162 * (as long as disableTypography is not `true`).
163 */
164 primaryTypographyProps: PropTypes.object,
165 /**
166 * The secondary content element.
167 */
168 secondary: PropTypes.node,
169 /**
170 * These props will be forwarded to the secondary typography component
171 * (as long as disableTypography is not `true`).
172 */
173 secondaryTypographyProps: PropTypes.object,
174 /**
175 * The system prop that allows defining system overrides as well as additional CSS styles.
176 */
177 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
178} : void 0;
179export default ListItemText;
\No newline at end of file