2023-03-23 11:32:09 +00:00
|
|
|
import { ReactNode, useState } from "react";
|
|
|
|
import { Box, Typography, useTheme } from "@mui/material";
|
|
|
|
import ExpandIcon from "./ExpandIcon";
|
|
|
|
|
|
|
|
interface Props {
|
2024-05-21 07:41:31 +00:00
|
|
|
headerText: string;
|
|
|
|
children: (callback: () => void) => ReactNode;
|
2023-03-23 11:32:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function Collapse({ headerText, children }: Props) {
|
2024-05-21 07:41:31 +00:00
|
|
|
const theme = useTheme();
|
|
|
|
const [isExpanded, setIsExpanded] = useState<boolean>(false);
|
2024-02-21 09:00:40 +00:00
|
|
|
|
2024-05-21 07:41:31 +00:00
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
position: "relative",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
onClick={() => setIsExpanded((prev) => !prev)}
|
|
|
|
sx={{
|
|
|
|
height: "72px",
|
|
|
|
p: "16px",
|
|
|
|
backgroundColor: theme.palette.menu.main,
|
|
|
|
borderRadius: "12px",
|
2023-03-23 11:32:09 +00:00
|
|
|
|
2024-05-21 07:41:31 +00:00
|
|
|
display: "flex",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
alignItems: "center",
|
|
|
|
cursor: "pointer",
|
|
|
|
userSelect: "none",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Typography variant="h4">{headerText}</Typography>
|
|
|
|
<ExpandIcon isExpanded={isExpanded} />
|
|
|
|
</Box>
|
|
|
|
{isExpanded && (
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
mt: "8px",
|
|
|
|
position: "absolute",
|
|
|
|
zIndex: 100,
|
|
|
|
backgroundColor: theme.palette.content.main,
|
|
|
|
width: "100%",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{children(() => setIsExpanded(false))}
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
);
|
2024-02-21 09:00:40 +00:00
|
|
|
}
|