-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a171142
commit ed34fa8
Showing
5 changed files
with
117 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// @ts-check | ||
import * as React from 'react' | ||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore' | ||
import Typography from '@mui/material/Typography' | ||
import Accordion from '@mui/material/Accordion' | ||
import AccordionSummary from '@mui/material/AccordionSummary' | ||
import AccordionDetails from '@mui/material/AccordionDetails' | ||
|
||
import { useStorage } from '@store/useStorage' | ||
|
||
const expandIcon = <ExpandMoreIcon /> | ||
|
||
/** | ||
* A basic accordion component that already has the expand icon and state management | ||
* @param {{ | ||
* stateKey?: string | ||
* title: string | ||
* children: React.ReactNode | ||
* } & import('@mui/material').AccordionDetailsProps} props | ||
* @returns | ||
*/ | ||
export function BasicAccordion({ | ||
title, | ||
stateKey = title, | ||
children, | ||
...props | ||
}) { | ||
const expanded = useStorage((s) => !!s.expanded[stateKey]) | ||
|
||
/** @type {(e: unknown, isExpanded: boolean )=> void} */ | ||
const handleChange = React.useCallback( | ||
(_, isExpanded) => | ||
useStorage.setState((prev) => ({ | ||
expanded: { ...prev.expanded, [stateKey]: isExpanded }, | ||
})), | ||
[stateKey], | ||
) | ||
return ( | ||
<Accordion expanded={expanded} onChange={handleChange}> | ||
<AccordionSummary expandIcon={expandIcon}> | ||
<Typography variant="h6">{title}</Typography> | ||
</AccordionSummary> | ||
<AccordionDetails sx={{ p: 0 }} {...props}> | ||
{children} | ||
</AccordionDetails> | ||
</Accordion> | ||
) | ||
} |
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