-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New DS core component: accordion (#632)
- Loading branch information
Showing
9 changed files
with
420 additions
and
111 deletions.
There are no files selected for viewing
This file contains 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
54 changes: 54 additions & 0 deletions
54
packages/react-ui/src/components/molecules/AccordionGroup.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Accordion, AccordionDetails, AccordionSummary } from '@mui/material'; | ||
import { styled } from '@mui/material/styles'; | ||
|
||
const AccordionContainer = styled('div', { | ||
shouldForwardProp: (prop) => prop !== 'variant' | ||
})(({ variant, theme }) => ({ | ||
width: '100%', | ||
borderRadius: theme.spacing(0.5), | ||
|
||
...(variant === 'outlined' && { | ||
backgroundColor: theme.palette.background.paper, | ||
boxShadow: `inset 0 0 0 1px ${theme.palette.divider}` | ||
}) | ||
})); | ||
|
||
const AccordionGroup = ({ variant, items, ...otherProps }) => { | ||
return ( | ||
<AccordionContainer {...otherProps} variant={variant}> | ||
{items.map((item, index) => ( | ||
<Accordion | ||
key={index} | ||
disabled={item.disabled} | ||
defaultExpanded={item.defaultExpanded} | ||
onChange={item.onChange} | ||
> | ||
<AccordionSummary aria-controls={`${index}-content`} id={`${index}-header`}> | ||
{item.summary} | ||
</AccordionSummary> | ||
<AccordionDetails>{item.content}</AccordionDetails> | ||
</Accordion> | ||
))} | ||
</AccordionContainer> | ||
); | ||
}; | ||
|
||
AccordionGroup.defaultProps = { | ||
variant: 'standard' | ||
}; | ||
AccordionGroup.propTypes = { | ||
variant: PropTypes.oneOf(['standard' | 'outlined']), | ||
items: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
summary: PropTypes.string.isRequired, | ||
content: PropTypes.oneOfType([PropTypes.element, PropTypes.string]).isRequired, | ||
disabled: PropTypes.boolean, | ||
defaultExpanded: PropTypes.boolean, | ||
onChange: PropTypes.func | ||
}) | ||
).isRequired | ||
}; | ||
|
||
export default AccordionGroup; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.