front-hub/src/components/CustomAccordion.tsx

106 lines
2.9 KiB
TypeScript
Raw Normal View History

2022-12-21 11:26:07 +00:00
import { Box, Typography, useMediaQuery, useTheme } from "@mui/material";
import { useState } from "react";
import ExpandIcon from "./icons/ExpandIcon";
2023-07-25 22:31:04 +00:00
import type { ReactNode } from "react";
2022-12-21 11:26:07 +00:00
interface Props {
2023-07-25 22:31:04 +00:00
header: ReactNode;
text: string;
divide?: boolean;
2023-08-18 16:39:29 +00:00
price?: number;
2022-12-21 11:26:07 +00:00
}
2023-08-18 16:39:29 +00:00
export default function CustomAccordion({ header, text, divide = false, price }: Props) {
2023-07-25 22:31:04 +00:00
const theme = useTheme();
const upMd = useMediaQuery(theme.breakpoints.up("md"));
const upXs = useMediaQuery(theme.breakpoints.up("xs"));
const [isExpanded, setIsExpanded] = useState<boolean>(false);
2022-12-21 11:26:07 +00:00
2023-07-25 22:31:04 +00:00
return (
<Box
sx={{
backgroundColor: "white",
"&:first-of-type": {
borderTopLeftRadius: "12px",
borderTopRightRadius: "12px",
},
"&:last-of-type": {
borderBottomLeftRadius: "12px",
borderBottomRightRadius: "12px",
},
"&:not(:last-of-type)": {
2023-08-22 10:28:22 +00:00
borderBottom: `1px solid ${theme.palette.gray.main}`,
2023-07-25 22:31:04 +00:00
},
}}
>
<Box
onClick={() => setIsExpanded((prev) => !prev)}
sx={{
minHeight: "72px",
px: "20px",
display: "flex",
alignItems: "stretch",
justifyContent: "space-between",
cursor: "pointer",
userSelect: "none",
rowGap: "10px",
flexDirection: upXs ? undefined : "column",
}}
>
<Box
sx={{
display: "flex",
alignItems: "center",
width: "100%",
fontSize: upMd ? undefined : "16px",
lineHeight: upMd ? undefined : "19px",
fontWeight: 500,
2023-08-22 10:28:22 +00:00
color: theme.palette.gray.dark,
2023-07-25 22:31:04 +00:00
px: 0,
}}
>
{header}
</Box>
<Box
sx={{
pl: "20px",
width: "52px",
display: "flex",
alignItems: "center",
justifyContent: "center",
borderLeft: divide ? "1px solid #000000" : "none",
}}
>
<ExpandIcon isExpanded={isExpanded} />
</Box>
</Box>
{isExpanded && (
2022-12-21 11:26:07 +00:00
<Box
2023-07-25 22:31:04 +00:00
sx={{
2023-08-18 16:39:29 +00:00
display: "flex",
justifyContent: "space-between",
2023-07-25 22:31:04 +00:00
px: "20px",
py: upMd ? "25px" : undefined,
pt: upMd ? undefined : "15px",
pb: upMd ? undefined : "25px",
backgroundColor: "#F1F2F6",
}}
>
<Typography
2022-12-21 11:26:07 +00:00
sx={{
2023-07-25 22:31:04 +00:00
fontSize: upMd ? undefined : "16px",
lineHeight: upMd ? undefined : "19px",
2023-08-22 10:28:22 +00:00
color: theme.palette.gray.dark,
2022-12-21 11:26:07 +00:00
}}
2023-07-25 22:31:04 +00:00
>
{text}
</Typography>
2023-08-18 16:39:29 +00:00
<Typography sx={{ display: price ? "block" : "none", fontSize: "18px", mr: "120px" }}>
{price} руб.
</Typography>
2022-12-21 11:26:07 +00:00
</Box>
2023-07-25 22:31:04 +00:00
)}
</Box>
);
}