link-stack/packages/ui/components/Dialog.tsx

95 lines
1.8 KiB
TypeScript
Raw Normal View History

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,
}) => {
const { h3 } = typography;
const { mediumGray, darkMediumGray } = colors;
return (
<>
<DialogTitle
sx={{
backgroundColor: mediumGray,
p: 3,
}}
>
<Box
sx={{
...h3,
borderBottom: `1px solid ${darkMediumGray}`,
pb: 1.5,
}}
>
{title}
</Box>
</DialogTitle>
<DialogContent sx={{ backgroundColor: mediumGray, p: 3, pb: 4 }}>
{children}
</DialogContent>
{buttons && (
<DialogActions sx={{ backgroundColor: mediumGray, p: 3 }}>
{buttons}
</DialogActions>
)}
</>
);
};
type DialogProps = {
2024-03-17 12:58:25 +01:00
title: string;
open: boolean;
2024-04-24 21:44:05 +02:00
onClose: Function;
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-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
maxWidth="md"
>
{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
);
};