feat: create generic dialog component

This commit is contained in:
Caio Cabral committed 2024-10-22 05:58:21 -04:00
1 parent 7184d57588
commit effc6dac3a
2 files changed
+53 -26

No files matched your search

@@ -0,0 +1,45 @@
import { Modal, Stack } from "@mui/material";
import PropTypes from "prop-types";
const GenericDialog = ({ title, description, open, onClose, theme, children }) => {
return (
<Modal
aria-labelledby={title}
aria-describedby={description}
open={open}
onClose={onClose}
>
<Stack
gap={theme.spacing(2)}
sx={{
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
width: 400,
bgcolor: theme.palette.background.main,
border: 1,
borderColor: theme.palette.border.light,
borderRadius: theme.shape.borderRadius,
boxShadow: 24,
p: theme.spacing(15),
"&:focus": {
outline: "none",
},
}}
>
{children}
</Stack>
</Modal>
);
};
GenericDialog.propTypes = {
title: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
open: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
theme: PropTypes.object.isRequired,
children: PropTypes.element.isRequired,
};
export { GenericDialog };
+8 -26
View File
@@ -1,6 +1,7 @@
import LoadingButton from "@mui/lab/LoadingButton"; import LoadingButton from "@mui/lab/LoadingButton";
import { Button, Modal, Stack, Typography } from "@mui/material"; import { Button, Stack, Typography } from "@mui/material";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { GenericDialog } from "./genericDialog";
const Dialog = ({ const Dialog = ({
modelTitle, modelTitle,
modelDescription, modelDescription,
@@ -16,30 +17,12 @@ const Dialog = ({
description, description,
}) => { }) => {
return ( return (
<Modal <GenericDialog
aria-labelledby={modelTitle} title={modelTitle}
aria-describedby={modelDescription} description={modelDescription}
open={open} open={open}
onClose={onClose} close={onClose}
> theme={theme}
<Stack
gap={theme.spacing(2)}
sx={{
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
width: 400,
bgcolor: theme.palette.background.main,
border: 1,
borderColor: theme.palette.border.light,
borderRadius: theme.shape.borderRadius,
boxShadow: 24,
p: theme.spacing(15),
"&:focus": {
outline: "none",
},
}}
> >
<Typography <Typography
id={modelTitle} id={modelTitle}
@@ -80,8 +63,7 @@ const Dialog = ({
{confirmationBtnLbl} {confirmationBtnLbl}
</LoadingButton> </LoadingButton>
</Stack> </Stack>
</Stack> </GenericDialog>
</Modal>
); );
}; };