Files
Checkmate/Client/src/Components/Dialog/genericDialog.jsx
T

69 lines
1.6 KiB
React
Raw Normal View History

import { useId } from "react";
2024-10-22 05:58:21 -04:00
import PropTypes from "prop-types";
import { Modal, Stack, Typography } from "@mui/material";
2024-10-22 05:58:21 -04:00
const GenericDialog = ({ title, description, open, onClose, theme, children }) => {
const titleId = useId();
const descriptionId = useId();
const ariaDescribedBy = description?.length > 0 ? descriptionId : "";
2024-10-22 05:58:21 -04:00
return (
<Modal
aria-labelledby={titleId}
aria-describedby={ariaDescribedBy}
2024-10-22 05:58:21 -04:00
open={open}
onClose={onClose}
2024-11-03 06:50:49 -05:00
onClick={(e) => e.stopPropagation()}
2024-10-22 05:58:21 -04:00
>
<Stack
gap={theme.spacing(2)}
sx={{
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
width: 400,
bgcolor: theme.palette.primary.main,
2024-10-22 05:58:21 -04:00
border: 1,
2025-01-08 21:41:59 -05:00
borderColor: theme.palette.primary.lowContrast,
2024-10-22 05:58:21 -04:00
borderRadius: theme.shape.borderRadius,
boxShadow: 24,
p: theme.spacing(15),
"&:focus": {
outline: "none",
},
}}
>
<Typography
id={titleId}
component="h2"
fontSize={16}
2025-01-07 21:27:52 -05:00
color={theme.palette.primary.contrastText.main}
fontWeight={600}
>
{title}
</Typography>
{description && (
<Typography
id={descriptionId}
2025-01-07 21:27:52 -05:00
color={theme.palette.primary.contrastText.tertiary}
>
{description}
</Typography>
)}
2024-10-22 05:58:21 -04:00
{children}
</Stack>
</Modal>
);
};
GenericDialog.propTypes = {
title: PropTypes.string.isRequired,
description: PropTypes.string,
2024-10-22 05:58:21 -04:00
open: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
theme: PropTypes.object.isRequired,
2024-11-03 06:50:49 -05:00
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
.isRequired,
2024-10-22 05:58:21 -04:00
};
export { GenericDialog };