import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import ExpansionPanel from '@material-ui/core/ExpansionPanel'; import ExpansionPanelSummary from '@material-ui/core/ExpansionPanelSummary'; import ExpansionPanelDetails from '@material-ui/core/ExpansionPanelDetails'; import Typography from '@material-ui/core/Typography'; import withStyles from '@material-ui/core/styles/withStyles'; const styles = { summaryText: { width: '100%', }, detailsText: { opacity: 0.5, width: '100%', }, }; /** * Expandable component with header text (summary) and expandable description text (details) */ class ExpandableListItem extends Component { componentWillReceiveProps(nextProps) { if (nextProps.selected && nextProps.scrollToSelected) { // @material-ui/core encourages ReactDOM until React find better way // https://@material-ui/core.com/getting-started/frequently-asked-questions/#how-can-i-access-the-dom-element- ReactDOM.findDOMNode(this).scrollIntoView(nextProps.scrollOptions || { behavior: 'smooth', block: 'center' }) } } render() { const { classes, panelClass, details, selected, summary, ExpansionPanelDetailsProps, ExpansionPanelDetailsTypographyProps, ExpansionPanelMoreIconProps, ExpansionPanelProps, ExpansionPanelSummaryProps, ExpansionPanelSummaryTypographyProps, SelectedExpansionPanelProps, } = this.props; const rootProps = selected ? { ...ExpansionPanelProps, ...SelectedExpansionPanelProps } : ExpansionPanelProps; return ( } {...ExpansionPanelSummaryProps} > {summary} {details} ) } } export default withStyles(styles)(ExpandableListItem)