UNPKG

4.64 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import withStyles from '../styles/withStyles';
7import Typography from '../Typography';
8import ListContext from '../List/ListContext';
9export var styles = {
10 /* Styles applied to the root element. */
11 root: {
12 flex: '1 1 auto',
13 minWidth: 0,
14 marginTop: 4,
15 marginBottom: 4
16 },
17
18 /* Styles applied to the `Typography` components if primary and secondary are set. */
19 multiline: {
20 marginTop: 6,
21 marginBottom: 6
22 },
23
24 /* Styles applied to the `Typography` components if dense. */
25 dense: {},
26
27 /* Styles applied to the root element if `inset={true}`. */
28 inset: {
29 paddingLeft: 56
30 },
31
32 /* Styles applied to the primary `Typography` component. */
33 primary: {},
34
35 /* Styles applied to the secondary `Typography` component. */
36 secondary: {}
37};
38var ListItemText = /*#__PURE__*/React.forwardRef(function ListItemText(props, ref) {
39 var children = props.children,
40 classes = props.classes,
41 className = props.className,
42 _props$disableTypogra = props.disableTypography,
43 disableTypography = _props$disableTypogra === void 0 ? false : _props$disableTypogra,
44 _props$inset = props.inset,
45 inset = _props$inset === void 0 ? false : _props$inset,
46 primaryProp = props.primary,
47 primaryTypographyProps = props.primaryTypographyProps,
48 secondaryProp = props.secondary,
49 secondaryTypographyProps = props.secondaryTypographyProps,
50 other = _objectWithoutProperties(props, ["children", "classes", "className", "disableTypography", "inset", "primary", "primaryTypographyProps", "secondary", "secondaryTypographyProps"]);
51
52 var _React$useContext = React.useContext(ListContext),
53 dense = _React$useContext.dense;
54
55 var primary = primaryProp != null ? primaryProp : children;
56
57 if (primary != null && primary.type !== Typography && !disableTypography) {
58 primary = /*#__PURE__*/React.createElement(Typography, _extends({
59 variant: dense ? 'body2' : 'body1',
60 className: classes.primary,
61 component: "span",
62 display: "block"
63 }, primaryTypographyProps), primary);
64 }
65
66 var secondary = secondaryProp;
67
68 if (secondary != null && secondary.type !== Typography && !disableTypography) {
69 secondary = /*#__PURE__*/React.createElement(Typography, _extends({
70 variant: "body2",
71 className: classes.secondary,
72 color: "textSecondary",
73 display: "block"
74 }, secondaryTypographyProps), secondary);
75 }
76
77 return /*#__PURE__*/React.createElement("div", _extends({
78 className: clsx(classes.root, className, dense && classes.dense, inset && classes.inset, primary && secondary && classes.multiline),
79 ref: ref
80 }, other), primary, secondary);
81});
82process.env.NODE_ENV !== "production" ? ListItemText.propTypes = {
83 // ----------------------------- Warning --------------------------------
84 // | These PropTypes are generated from the TypeScript type definitions |
85 // | To update them edit the d.ts file and run "yarn proptypes" |
86 // ----------------------------------------------------------------------
87
88 /**
89 * Alias for the `primary` prop.
90 */
91 children: PropTypes.node,
92
93 /**
94 * Override or extend the styles applied to the component.
95 * See [CSS API](#css) below for more details.
96 */
97 classes: PropTypes.object,
98
99 /**
100 * @ignore
101 */
102 className: PropTypes.string,
103
104 /**
105 * If `true`, the children won't be wrapped by a Typography component.
106 * This can be useful to render an alternative Typography variant by wrapping
107 * the `children` (or `primary`) text, and optional `secondary` text
108 * with the Typography component.
109 */
110 disableTypography: PropTypes.bool,
111
112 /**
113 * If `true`, the children will be indented.
114 * This should be used if there is no left avatar or left icon.
115 */
116 inset: PropTypes.bool,
117
118 /**
119 * The main content element.
120 */
121 primary: PropTypes.node,
122
123 /**
124 * These props will be forwarded to the primary typography component
125 * (as long as disableTypography is not `true`).
126 */
127 primaryTypographyProps: PropTypes.object,
128
129 /**
130 * The secondary content element.
131 */
132 secondary: PropTypes.node,
133
134 /**
135 * These props will be forwarded to the secondary typography component
136 * (as long as disableTypography is not `true`).
137 */
138 secondaryTypographyProps: PropTypes.object
139} : void 0;
140export default withStyles(styles, {
141 name: 'MuiListItemText'
142})(ListItemText);
\No newline at end of file