UNPKG

6.45 kBJavaScriptView Raw
1'use client';
2
3import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4import _extends from "@babel/runtime/helpers/esm/extends";
5import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6import * as React from 'react';
7import PropTypes from 'prop-types';
8import clsx from 'clsx';
9import composeClasses from '@mui/utils/composeClasses';
10import Typography from '../Typography';
11import ListContext from '../List/ListContext';
12import { useDefaultProps } from '../DefaultPropsProvider';
13import styled from '../styles/styled';
14import listItemTextClasses, { getListItemTextUtilityClass } from './listItemTextClasses';
15import { jsx as _jsx } from "react/jsx-runtime";
16import { jsxs as _jsxs } from "react/jsx-runtime";
17var useUtilityClasses = function useUtilityClasses(ownerState) {
18 var classes = ownerState.classes,
19 inset = ownerState.inset,
20 primary = ownerState.primary,
21 secondary = ownerState.secondary,
22 dense = ownerState.dense;
23 var slots = {
24 root: ['root', inset && 'inset', dense && 'dense', primary && secondary && 'multiline'],
25 primary: ['primary'],
26 secondary: ['secondary']
27 };
28 return composeClasses(slots, getListItemTextUtilityClass, classes);
29};
30var ListItemTextRoot = styled('div', {
31 name: 'MuiListItemText',
32 slot: 'Root',
33 overridesResolver: function overridesResolver(props, styles) {
34 var ownerState = props.ownerState;
35 return [_defineProperty({}, "& .".concat(listItemTextClasses.primary), styles.primary), _defineProperty({}, "& .".concat(listItemTextClasses.secondary), styles.secondary), styles.root, ownerState.inset && styles.inset, ownerState.primary && ownerState.secondary && styles.multiline, ownerState.dense && styles.dense];
36 }
37})(function (_ref3) {
38 var ownerState = _ref3.ownerState;
39 return _extends({
40 flex: '1 1 auto',
41 minWidth: 0,
42 marginTop: 4,
43 marginBottom: 4
44 }, ownerState.primary && ownerState.secondary && {
45 marginTop: 6,
46 marginBottom: 6
47 }, ownerState.inset && {
48 paddingLeft: 56
49 });
50});
51var ListItemText = /*#__PURE__*/React.forwardRef(function ListItemText(inProps, ref) {
52 var props = useDefaultProps({
53 props: inProps,
54 name: 'MuiListItemText'
55 });
56 var children = props.children,
57 className = props.className,
58 _props$disableTypogra = props.disableTypography,
59 disableTypography = _props$disableTypogra === void 0 ? false : _props$disableTypogra,
60 _props$inset = props.inset,
61 inset = _props$inset === void 0 ? false : _props$inset,
62 primaryProp = props.primary,
63 primaryTypographyProps = props.primaryTypographyProps,
64 secondaryProp = props.secondary,
65 secondaryTypographyProps = props.secondaryTypographyProps,
66 other = _objectWithoutProperties(props, ["children", "className", "disableTypography", "inset", "primary", "primaryTypographyProps", "secondary", "secondaryTypographyProps"]);
67 var _React$useContext = React.useContext(ListContext),
68 dense = _React$useContext.dense;
69 var primary = primaryProp != null ? primaryProp : children;
70 var secondary = secondaryProp;
71 var ownerState = _extends({}, props, {
72 disableTypography: disableTypography,
73 inset: inset,
74 primary: !!primary,
75 secondary: !!secondary,
76 dense: dense
77 });
78 var classes = useUtilityClasses(ownerState);
79 if (primary != null && primary.type !== Typography && !disableTypography) {
80 primary = /*#__PURE__*/_jsx(Typography, _extends({
81 variant: dense ? 'body2' : 'body1',
82 className: classes.primary,
83 component: primaryTypographyProps != null && primaryTypographyProps.variant ? undefined : 'span',
84 display: "block"
85 }, primaryTypographyProps, {
86 children: primary
87 }));
88 }
89 if (secondary != null && secondary.type !== Typography && !disableTypography) {
90 secondary = /*#__PURE__*/_jsx(Typography, _extends({
91 variant: "body2",
92 className: classes.secondary,
93 color: "text.secondary",
94 display: "block"
95 }, secondaryTypographyProps, {
96 children: secondary
97 }));
98 }
99 return /*#__PURE__*/_jsxs(ListItemTextRoot, _extends({
100 className: clsx(classes.root, className),
101 ownerState: ownerState,
102 ref: ref
103 }, other, {
104 children: [primary, secondary]
105 }));
106});
107process.env.NODE_ENV !== "production" ? ListItemText.propTypes /* remove-proptypes */ = {
108 // ┌────────────────────────────── Warning ──────────────────────────────┐
109 // │ These PropTypes are generated from the TypeScript type definitions. │
110 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
111 // └─────────────────────────────────────────────────────────────────────┘
112 /**
113 * Alias for the `primary` prop.
114 */
115 children: PropTypes.node,
116 /**
117 * Override or extend the styles applied to the component.
118 */
119 classes: PropTypes.object,
120 /**
121 * @ignore
122 */
123 className: PropTypes.string,
124 /**
125 * If `true`, the children won't be wrapped by a Typography component.
126 * This can be useful to render an alternative Typography variant by wrapping
127 * the `children` (or `primary`) text, and optional `secondary` text
128 * with the Typography component.
129 * @default false
130 */
131 disableTypography: PropTypes.bool,
132 /**
133 * If `true`, the children are indented.
134 * This should be used if there is no left avatar or left icon.
135 * @default false
136 */
137 inset: PropTypes.bool,
138 /**
139 * The main content element.
140 */
141 primary: PropTypes.node,
142 /**
143 * These props will be forwarded to the primary typography component
144 * (as long as disableTypography is not `true`).
145 */
146 primaryTypographyProps: PropTypes.object,
147 /**
148 * The secondary content element.
149 */
150 secondary: PropTypes.node,
151 /**
152 * These props will be forwarded to the secondary typography component
153 * (as long as disableTypography is not `true`).
154 */
155 secondaryTypographyProps: PropTypes.object,
156 /**
157 * The system prop that allows defining system overrides as well as additional CSS styles.
158 */
159 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
160} : void 0;
161export default ListItemText;
\No newline at end of file