@material-ui/core
Version:
React components that implement Google's Material Design.
160 lines (140 loc) • 4.22 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import Typography from '../Typography';
export const styles = theme => ({
/* Styles applied to the root element. */
root: {
flex: '1 1 auto',
minWidth: 0,
padding: '0 16px',
'&:first-child': {
paddingLeft: 0
}
},
/* Styles applied to the root element if `inset={true}`. */
inset: {
'&:first-child': {
paddingLeft: 56
}
},
/* Styles applied to the root element if `context.dense` is `true`. */
dense: {
fontSize: theme.typography.pxToRem(13)
},
/* Styles applied to the primary `Typography` component. */
primary: {
'&$textDense': {
fontSize: 'inherit'
}
},
/* Styles applied to the secondary `Typography` component. */
secondary: {
'&$textDense': {
fontSize: 'inherit'
}
},
/* Styles applied to the `Typography` components if `context.dense` is `true`. */
textDense: {}
});
function ListItemText(props, context) {
const {
children,
classes,
className: classNameProp,
disableTypography,
inset,
primary: primaryProp,
primaryTypographyProps,
secondary: secondaryProp,
secondaryTypographyProps
} = props,
other = _objectWithoutProperties(props, ["children", "classes", "className", "disableTypography", "inset", "primary", "primaryTypographyProps", "secondary", "secondaryTypographyProps"]);
const {
dense
} = context;
let primary = primaryProp != null ? primaryProp : children;
if (primary != null && primary.type !== Typography && !disableTypography) {
primary = React.createElement(Typography, _extends({
variant: "subheading",
internalDeprecatedVariant: true,
className: classNames(classes.primary, {
[classes.textDense]: dense
}),
component: "span"
}, primaryTypographyProps), primary);
}
let secondary = secondaryProp;
if (secondary != null && secondary.type !== Typography && !disableTypography) {
secondary = React.createElement(Typography, _extends({
className: classNames(classes.secondary, {
[classes.textDense]: dense
}),
color: "textSecondary"
}, secondaryTypographyProps), secondary);
}
return React.createElement("div", _extends({
className: classNames(classes.root, {
[classes.dense]: dense,
[classes.inset]: inset
}, classNameProp)
}, other), primary, secondary);
}
ListItemText.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* Alias for the `primary` property.
*/
children: PropTypes.node,
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css-api) 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
} : {};
ListItemText.defaultProps = {
disableTypography: false,
inset: false
};
ListItemText.contextTypes = {
dense: PropTypes.bool
};
export default withStyles(styles, {
name: 'MuiListItemText'
})(ListItemText);