-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathActionDialog.tsx
80 lines (77 loc) · 1.73 KB
/
ActionDialog.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import * as React from "react";
import {
Button,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
IconButton,
Stack
} from "@mui/material";
import { ActionDialogProps } from "./ActionDialog.types";
import CloseIcon from "@mui/icons-material/Close";
/**
* ActionDialog component is used to show a dialog with title, content and action buttons.
*/
export default function ActionDialog({
onCancelClick,
onSaveClick,
title = "Some title",
cancelText = "cancel",
saveText = "Save",
open = true,
content,
saveDisabled = false,
width = "400px",
showCloseIcon = true
}: ActionDialogProps) {
// return components
return (
<Dialog
open={open}
data-testid="action-dialog"
sx={{
"& .MuiDialog-container": {
"& .MuiPaper-root": {
maxWidth: width,
width: "100%"
}
},
"& .MuiDialogActions-root": {
p: [2, 3]
}
}}
>
<DialogTitle fontWeight={600}>
{title}
{showCloseIcon ? (
<IconButton
data-testid="close-icon"
aria-label="close"
onClick={onCancelClick}
sx={{
position: "absolute",
right: 8,
top: 8
}}
>
<CloseIcon />
</IconButton>
) : null}
</DialogTitle>
<DialogContent dividers>
<Stack spacing={3}>{content}</Stack>
</DialogContent>
<DialogActions>
<Button onClick={onCancelClick}>{cancelText}</Button>
<Button
variant="contained"
onClick={onSaveClick}
disabled={saveDisabled}
>
{saveText}
</Button>
</DialogActions>
</Dialog>
);
}