Skip to content

Commit

Permalink
Use an MUI accordion for the sidebar collapsing sections
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Nov 28, 2023
1 parent ea70a21 commit a4a32b8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
42 changes: 11 additions & 31 deletions src/components/CollapsibleSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Component } from 'react';
import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles';
import Typography from '@mui/material/Typography';
import Accordion from '@mui/material/Accordion';
import AccordionDetails from '@mui/material/AccordionDetails';
import AccordionSummary from '@mui/material/AccordionSummary';
import KeyboardArrowDown from '@mui/icons-material/KeyboardArrowDownSharp';
import KeyboardArrowUp from '@mui/icons-material/KeyboardArrowUpSharp';
import MiradorMenuButton from '../containers/MiradorMenuButton';

Check warning on line 10 in src/components/CollapsibleSection.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'MiradorMenuButton' is defined but never used

Check warning on line 10 in src/components/CollapsibleSection.js

View workflow job for this annotation

GitHub Actions / build (20.x)

'MiradorMenuButton' is defined but never used
Expand All @@ -20,16 +23,6 @@ export class CollapsibleSection extends Component {
/** */
constructor(props) {

Check warning on line 24 in src/components/CollapsibleSection.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Useless constructor

Check warning on line 24 in src/components/CollapsibleSection.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Useless constructor
super(props);

this.state = { open: true };
this.toggleSection = this.toggleSection.bind(this);
}

/** */
toggleSection() {
const { open } = this.state;

this.setState({ open: !open });
}

/**
Expand All @@ -39,31 +32,18 @@ export class CollapsibleSection extends Component {
const {
children, id, label, t,
} = this.props;
const { open } = this.state;

return (
<>
<StyledContainer sx={{ padding: 0 }}>
<Typography
sx={{ alignSelf: 'center', cursor: 'pointer' }}
id={id}
onClick={this.toggleSection}
variant="overline"
component="h4"
>
<Accordion id={id} elevation={0} defaultExpanded onChange={this.toggleSection} disableGutters square variant="compact">
<AccordionSummary id={`${id}-header`} aria-controls={`${id}-content`} aria-label={t(open ? 'collapseSection' : 'expandSection', { section: label })} expandIcon={open ? <KeyboardArrowUp /> : <KeyboardArrowDown />}>

Check failure on line 38 in src/components/CollapsibleSection.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected use of 'open'

Check failure on line 38 in src/components/CollapsibleSection.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected use of 'open'

Check failure on line 38 in src/components/CollapsibleSection.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected use of 'open'

Check failure on line 38 in src/components/CollapsibleSection.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected use of 'open'
<Typography variant="overline" component="h4">
{label}
</Typography>
<MiradorMenuButton
aria-label={t(open ? 'collapseSection' : 'expandSection', { section: label })}
aria-expanded={open}
sx={{ padding: 0 }}
onClick={this.toggleSection}
>
{open ? <KeyboardArrowUp /> : <KeyboardArrowDown />}
</MiradorMenuButton>
</StyledContainer>
{open && children}
</>
</AccordionSummary>
<AccordionDetails>
{children}
</AccordionDetails>
</Accordion>
);
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/config/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,25 @@ export default {
},
},
},
MuiAccordion: {
variants: [
{
props: { variant: 'compact' },
style: {
'& .MuiAccordionSummary-root': {
minHeight: 'unset',
padding: 0,
},
'& .MuiAccordionSummary-content': {
margin: 0,
},
'& .MuiAccordionDetails-root': {
padding: 0,
},
},
},
],
},
MuiButtonBase: {
defaultProps: {
disableTouchRipple: true,
Expand Down

0 comments on commit a4a32b8

Please sign in to comment.