@material-ui/core
Version:
React components that implement Google's Material Design.
135 lines (117 loc) • 3.91 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import withStyles from '../styles/withStyles';
import Typography from '../Typography';
import ListContext from '../List/ListContext';
export const styles = {
/* Styles applied to the root element. */
root: {
flex: '1 1 auto',
minWidth: 0,
marginTop: 4,
marginBottom: 4
},
/* Styles applied to the `Typography` components if primary and secondary are set. */
multiline: {
marginTop: 6,
marginBottom: 6
},
/* Styles applied to the `Typography` components if dense. */
dense: {},
/* Styles applied to the root element if `inset={true}`. */
inset: {
paddingLeft: 56
},
/* Styles applied to the primary `Typography` component. */
primary: {},
/* Styles applied to the secondary `Typography` component. */
secondary: {}
};
const ListItemText = React.forwardRef(function ListItemText(props, ref) {
const {
children,
classes,
className,
disableTypography = false,
inset = false,
primary: primaryProp,
primaryTypographyProps,
secondary: secondaryProp,
secondaryTypographyProps
} = props,
other = _objectWithoutPropertiesLoose(props, ["children", "classes", "className", "disableTypography", "inset", "primary", "primaryTypographyProps", "secondary", "secondaryTypographyProps"]);
const {
dense
} = React.useContext(ListContext);
let primary = primaryProp != null ? primaryProp : children;
if (primary != null && primary.type !== Typography && !disableTypography) {
primary = React.createElement(Typography, _extends({
variant: dense ? 'body2' : 'body1',
className: classes.primary,
component: "span"
}, primaryTypographyProps), primary);
}
let secondary = secondaryProp;
if (secondary != null && secondary.type !== Typography && !disableTypography) {
secondary = React.createElement(Typography, _extends({
variant: "body2",
className: classes.secondary,
color: "textSecondary"
}, secondaryTypographyProps), secondary);
}
return React.createElement("div", _extends({
className: clsx(classes.root, className, dense && classes.dense, inset && classes.inset, primary && secondary && classes.multiline),
ref: ref
}, other), primary, secondary);
});
process.env.NODE_ENV !== "production" ? ListItemText.propTypes = {
/**
* Alias for the `primary` property.
*/
children: PropTypes.node,
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css) below for more details.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* If `true`, the children won't be wrapped by a Typography component.
* This can be useful to render an alternative Typography variant by wrapping
* the `children` (or `primary`) text, and optional `secondary` text
* with the Typography component.
*/
disableTypography: PropTypes.bool,
/**
* If `true`, the children will be indented.
* This should be used if there is no left avatar or left icon.
*/
inset: PropTypes.bool,
/**
* The main content element.
*/
primary: PropTypes.node,
/**
* These props will be forwarded to the primary typography component
* (as long as disableTypography is not `true`).
*/
primaryTypographyProps: PropTypes.object,
/**
* The secondary content element.
*/
secondary: PropTypes.node,
/**
* These props will be forwarded to the secondary typography component
* (as long as disableTypography is not `true`).
*/
secondaryTypographyProps: PropTypes.object
} : void 0;
export default withStyles(styles, {
name: 'MuiListItemText'
})(ListItemText);