- React Material:UI Cookbook
- Adam Boduch
- 117字
- 2021-06-24 15:49:38
How to do it...
Let's say that you want the text within your ExpansionPanel headers to stand out relative to the text in the content section of each panel. You can change the variant property of the Typography component in the ExpansionPanelSummary component. Here's the code to do it:
import React, { Fragment } from 'react';
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 ExpandMoreIcon from '@material-ui/icons/ExpandMore';
const FormattingPanelHeaders = () => (
<Fragment>
<ExpansionPanel>
<ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>
<Typography variant="subtitle1">Devices</Typography>
</ExpansionPanelSummary>
<ExpansionPanelDetails>
<Typography>Devices content...</Typography>
</ExpansionPanelDetails>
</ExpansionPanel>
<ExpansionPanel>
<ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>
<Typography variant="subtitle1">Networks</Typography>
</ExpansionPanelSummary>
<ExpansionPanelDetails>
<Typography>Networks content...</Typography>
</ExpansionPanelDetails>
</ExpansionPanel>
<ExpansionPanel>
<ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>
<Typography variant="subtitle1">Storage</Typography>
</ExpansionPanelSummary>
<ExpansionPanelDetails>
<Typography>Storage content...</Typography>
</ExpansionPanelDetails>
</ExpansionPanel>
</Fragment>
);
export default FormattingPanelHeaders;
Here's what the panels look like when the screen loads:

Here's what the panels look like when they're expanded:
