Files
Checkmate/client/src/Components/inputs/Dialog.tsx
T

114 lines
2.7 KiB
TypeScript
Raw Normal View History

2026-01-26 19:36:29 +00:00
import Dialog from "@mui/material/Dialog";
2026-01-31 01:12:05 +00:00
import type { DialogProps } from "@mui/material/Dialog";
2026-01-26 19:36:29 +00:00
import DialogActions from "@mui/material/DialogActions";
import DialogContent from "@mui/material/DialogContent";
import DialogTitle from "@mui/material/DialogTitle";
import Typography from "@mui/material/Typography";
import Box from "@mui/material/Box";
2026-02-20 18:13:39 +00:00
import { Button } from "@/Components/inputs";
import { LAYOUT } from "@/Utils/Theme/constants";
import { useTheme } from "@mui/material/styles";
2026-01-26 19:36:29 +00:00
import { useTranslation } from "react-i18next";
2026-01-31 01:12:05 +00:00
import type { ReactNode } from "react";
2026-01-26 19:36:29 +00:00
export const DialogInput = ({
open,
title,
content,
onConfirm,
onCancel,
confirmColor = "primary",
loading = false,
2026-01-31 00:41:03 +00:00
cancelText,
confirmText,
2026-01-31 01:12:05 +00:00
children,
maxWidth,
fullWidth = false,
2026-02-08 16:30:51 +00:00
additionalButtons,
2026-01-26 19:36:29 +00:00
}: {
open: boolean;
title?: string;
content?: string;
onConfirm?(item: any): any;
onCancel?(item: any): any;
confirmColor?: "error" | "primary";
loading?: boolean;
2026-01-31 00:41:03 +00:00
cancelText?: string;
confirmText?: string;
2026-01-31 01:12:05 +00:00
children?: ReactNode;
maxWidth?: DialogProps["maxWidth"];
fullWidth?: boolean;
2026-02-08 16:30:51 +00:00
additionalButtons?: ReactNode;
2026-01-26 19:36:29 +00:00
}) => {
const { t } = useTranslation();
const theme = useTheme();
2026-01-26 19:36:29 +00:00
return (
2026-01-31 01:12:05 +00:00
<Dialog
open={open}
maxWidth={maxWidth}
fullWidth={fullWidth}
onClose={(_event, reason) => {
if (reason !== "backdropClick" && onCancel) onCancel(undefined);
}}
2026-01-31 01:12:05 +00:00
>
{title && (
<DialogTitle
2026-04-29 09:42:49 -07:00
pb={theme.spacing(LAYOUT.XS)}
bgcolor={theme.palette.action.hover}
borderBottom={`1px solid ${theme.palette.divider}`}
>
<Typography
component="span"
variant="h2"
2026-04-29 09:42:49 -07:00
fontWeight={600}
display={"block"}
>
{title}
</Typography>
{content && (
<Typography
variant="body1"
2026-04-29 09:42:49 -07:00
color={theme.palette.text.secondary}
mt={theme.spacing(LAYOUT.XS)}
display={"block"}
>
{content}
</Typography>
)}
</DialogTitle>
)}
{children && (
<DialogContent sx={{ pt: theme.spacing(LAYOUT.MD) }}>
2026-04-29 09:42:49 -07:00
<Box pt={theme.spacing(LAYOUT.XS)}>{children}</Box>
</DialogContent>
)}
<DialogActions
sx={{
p: theme.spacing(LAYOUT.MD),
pt: theme.spacing(LAYOUT.SM),
backgroundColor: theme.palette.action.hover,
borderTop: `1px solid ${theme.palette.divider}`,
}}
>
2026-01-26 19:36:29 +00:00
<Button
loading={loading}
variant="outlined"
2026-01-26 19:36:29 +00:00
onClick={onCancel}
>
2026-01-31 00:41:03 +00:00
{cancelText ?? t("common.buttons.cancel")}
2026-01-26 19:36:29 +00:00
</Button>
2026-02-08 16:30:51 +00:00
{additionalButtons}
2026-02-03 23:45:23 +00:00
{onConfirm && (
<Button
loading={loading}
variant="contained"
color={confirmColor}
onClick={onConfirm}
>
{confirmText ?? t("common.buttons.confirm")}
</Button>
)}
2026-01-26 19:36:29 +00:00
</DialogActions>
</Dialog>
);
};