2024-03-17 12:58:25 +01:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { FC } from "react";
|
|
|
|
|
import {
|
2024-04-24 21:44:05 +02:00
|
|
|
Box,
|
|
|
|
|
Dialog as InternalDialog,
|
2024-03-17 12:58:25 +01:00
|
|
|
DialogActions,
|
|
|
|
|
DialogContent,
|
2024-04-24 21:44:05 +02:00
|
|
|
DialogTitle,
|
2024-03-17 12:58:25 +01:00
|
|
|
} from "@mui/material";
|
2024-04-24 21:44:05 +02:00
|
|
|
import { typography, colors } from "../styles/theme";
|
2024-03-17 12:58:25 +01:00
|
|
|
|
2024-04-24 21:44:05 +02:00
|
|
|
type DialogDetailsProps = {
|
|
|
|
|
title: string;
|
|
|
|
|
children: React.ReactNode;
|
|
|
|
|
buttons?: React.ReactNode;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const DialogDetails: FC<DialogDetailsProps> = ({
|
|
|
|
|
title,
|
|
|
|
|
children,
|
|
|
|
|
buttons,
|
|
|
|
|
}) => {
|
2024-04-25 12:31:03 +02:00
|
|
|
const { h4 } = typography;
|
|
|
|
|
const { lightGray, mediumGray, darkMediumGray, white, almostBlack } = colors;
|
2024-04-24 21:44:05 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<DialogTitle
|
|
|
|
|
sx={{
|
|
|
|
|
backgroundColor: mediumGray,
|
2024-04-25 12:31:03 +02:00
|
|
|
borderBottom: `1px solid ${darkMediumGray}`,
|
|
|
|
|
px: 3,
|
|
|
|
|
py: 2,
|
2024-04-24 21:44:05 +02:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
2024-04-25 12:31:03 +02:00
|
|
|
...h4,
|
|
|
|
|
color: almostBlack,
|
2024-04-24 21:44:05 +02:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{title}
|
|
|
|
|
</Box>
|
|
|
|
|
</DialogTitle>
|
2024-04-25 12:31:03 +02:00
|
|
|
<DialogContent
|
|
|
|
|
sx={{
|
|
|
|
|
backgroundColor: lightGray,
|
|
|
|
|
p: 3,
|
|
|
|
|
borderTop: `1px solid ${white}`,
|
|
|
|
|
borderBottom: `1px solid ${darkMediumGray}`,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box sx={{ color: "white", py: 3 }}>{children}</Box>
|
2024-04-24 21:44:05 +02:00
|
|
|
</DialogContent>
|
|
|
|
|
{buttons && (
|
2024-04-25 12:31:03 +02:00
|
|
|
<DialogActions sx={{ backgroundColor: mediumGray, p: 0 }}>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
p: 2,
|
|
|
|
|
borderTop: `1px solid ${white}`,
|
|
|
|
|
width: "100%",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{buttons}
|
|
|
|
|
</Box>
|
2024-04-24 21:44:05 +02:00
|
|
|
</DialogActions>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type DialogProps = {
|
2024-03-17 12:58:25 +01:00
|
|
|
title: string;
|
|
|
|
|
open: boolean;
|
2024-04-25 12:31:03 +02:00
|
|
|
onClose?: Function;
|
|
|
|
|
size?: "xs" | "sm" | "md" | "lg" | "xl";
|
2024-04-24 21:44:05 +02:00
|
|
|
formAction?: any;
|
|
|
|
|
buttons?: React.ReactNode;
|
2024-03-17 12:58:25 +01:00
|
|
|
children?: any;
|
2024-04-24 21:44:05 +02:00
|
|
|
};
|
2024-03-17 12:58:25 +01:00
|
|
|
|
|
|
|
|
export const Dialog: FC<DialogProps> = ({
|
|
|
|
|
title,
|
|
|
|
|
open,
|
2024-04-25 12:31:03 +02:00
|
|
|
size = "md",
|
2024-04-24 21:44:05 +02:00
|
|
|
onClose,
|
|
|
|
|
formAction,
|
|
|
|
|
buttons,
|
2024-03-17 12:58:25 +01:00
|
|
|
children,
|
|
|
|
|
}) => {
|
|
|
|
|
return (
|
2024-04-24 21:44:05 +02:00
|
|
|
<InternalDialog
|
|
|
|
|
open={open}
|
|
|
|
|
onClose={onClose as any}
|
|
|
|
|
fullWidth
|
2024-04-25 12:31:03 +02:00
|
|
|
maxWidth={size}
|
2024-04-24 21:44:05 +02:00
|
|
|
>
|
|
|
|
|
{formAction ? (
|
|
|
|
|
<form action={formAction}>
|
|
|
|
|
<DialogDetails title={title} buttons={buttons}>
|
|
|
|
|
{children}
|
|
|
|
|
</DialogDetails>
|
|
|
|
|
</form>
|
|
|
|
|
) : (
|
|
|
|
|
<DialogDetails title={title} buttons={buttons}>
|
|
|
|
|
{children}
|
|
|
|
|
</DialogDetails>
|
|
|
|
|
)}
|
|
|
|
|
</InternalDialog>
|
2024-03-17 12:58:25 +01:00
|
|
|
);
|
|
|
|
|
};
|