From e3c7992bfd43af972b21a2e5a6ca4c71e48af80f Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Tue, 28 Nov 2023 10:36:13 -0800 Subject: [PATCH] Use an MUI accordion for the sidebar collapsing sections --- src/components/CollapsibleSection.js | 53 +++++++++------------------- src/config/settings.js | 19 ++++++++++ 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/components/CollapsibleSection.js b/src/components/CollapsibleSection.js index d7c13d8156..04c5f7d513 100644 --- a/src/components/CollapsibleSection.js +++ b/src/components/CollapsibleSection.js @@ -1,17 +1,10 @@ import { Component } from 'react'; import PropTypes from 'prop-types'; -import { styled } from '@mui/material/styles'; import Typography from '@mui/material/Typography'; -import KeyboardArrowDown from '@mui/icons-material/KeyboardArrowDownSharp'; -import KeyboardArrowUp from '@mui/icons-material/KeyboardArrowUpSharp'; -import MiradorMenuButton from '../containers/MiradorMenuButton'; - -const StyledContainer = styled('div')(() => ({ - alignItems: 'flex-start', - cursor: 'pointer', // This style will be applied to Typography - display: 'flex', - justifyContent: 'space-between', -})); +import Accordion from '@mui/material/Accordion'; +import AccordionDetails from '@mui/material/AccordionDetails'; +import AccordionSummary from '@mui/material/AccordionSummary'; +import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; /** * CollapsableSection ~ @@ -22,14 +15,12 @@ export class CollapsibleSection extends Component { super(props); this.state = { open: true }; - this.toggleSection = this.toggleSection.bind(this); + this.handleChange = this.handleChange.bind(this); } - /** */ - toggleSection() { - const { open } = this.state; - - this.setState({ open: !open }); + /** Control the accordion state so we can provide aria labeling */ + handleChange(event, isExpanded) { + this.setState({ open: isExpanded }); } /** @@ -42,28 +33,16 @@ export class CollapsibleSection extends Component { const { open } = this.state; return ( - <> - - + + }> + {label} - - {open ? : } - - - {open && children} - + + + {children} + + ); } } diff --git a/src/config/settings.js b/src/config/settings.js index c7f53e48a7..77f3552b39 100644 --- a/src/config/settings.js +++ b/src/config/settings.js @@ -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,