Created
August 3, 2023 14:01
-
-
Save azz0r/2eaabfbd8f9233b95f8418ef472535b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { useState } from 'react' | |
import { | |
Box, | |
AccordionSummary as MuiAccordionSummary, | |
Accordion as MuiAccordion | |
} from '@mui/material' | |
import { HeaderBody } from "./typography"; | |
import ExpandMoreIcon from '@mui/icons-material/ExpandMore' | |
import { makeStyles } from '@mui/styles' | |
const useStyles = makeStyles({ | |
root: { | |
width: '100%', | |
minHeight: 'auto' | |
}, | |
heading: { | |
flexBasis: '33.33%', | |
flexShrink: 0, | |
minHeight: 'auto', | |
textTransform: 'uppercase' | |
} | |
}) | |
export function Accordions({ collection = [], defaultExpanded = true }) { | |
const classes = useStyles() | |
const [expanded, setExpanded] = useState(defaultExpanded) | |
const handleChange = panel => (event, isExpanded) => | |
setExpanded(isExpanded ? panel : false) | |
return ( | |
<Box className={classes.root}> | |
{collection.map((accordian, index) => { | |
const { label, PresentationItem } = accordian | |
return ( | |
<MuiAccordion | |
key={`${index}-${label}`} | |
TransitionProps={{ unmountOnExit: true }} | |
expanded={expanded === label} | |
onChange={handleChange(label)} | |
> | |
<MuiAccordionSummary | |
expandIcon={<ExpandMoreIcon />} | |
aria-controls="panel1bh-content" | |
id="panel1bh-header" | |
> | |
<HeaderBody>{label}</HeaderBody> | |
</MuiAccordionSummary> | |
<Box width="100%" overflow="scroll" p={1}> | |
<PresentationItem /> | |
</Box> | |
</MuiAccordion> | |
) | |
})} | |
</Box> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment