-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathConfirmDialog.tsx
More file actions
114 lines (104 loc) · 2.96 KB
/
ConfirmDialog.tsx
File metadata and controls
114 lines (104 loc) · 2.96 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* ConfirmDialog - Dirty file close confirmation dialog
*
* Shows a modal with Save / Don't Save / Cancel buttons when
* the user attempts to close a file with unsaved changes.
* Built on CortexModal from the Cortex UI Design System.
*/
import { Component, JSX } from "solid-js";
import { CortexModal } from "../cortex/primitives/CortexModal";
import { CortexButton } from "../cortex/primitives/CortexButton";
import { CortexIcon } from "../cortex/primitives/CortexIcon";
export interface ConfirmDialogProps {
open: boolean;
fileName: string;
message?: string;
onSave: () => void;
onDontSave: () => void;
onCancel: () => void;
}
export const ConfirmDialog: Component<ConfirmDialogProps> = (props) => {
const bodyStyle: JSX.CSSProperties = {
display: "flex",
"align-items": "flex-start",
gap: "16px",
};
const iconContainerStyle: JSX.CSSProperties = {
display: "flex",
"align-items": "center",
"justify-content": "center",
width: "40px",
height: "40px",
"border-radius": "var(--cortex-radius-md, 8px)",
background: "var(--cortex-warning-bg, rgba(245, 158, 11, 0.1))",
"flex-shrink": "0",
};
const textStyle: JSX.CSSProperties = {
display: "flex",
"flex-direction": "column",
gap: "4px",
};
const messageStyle: JSX.CSSProperties = {
margin: "0",
"font-size": "14px",
color: "var(--cortex-text-primary)",
"line-height": "1.5",
};
const detailStyle: JSX.CSSProperties = {
margin: "0",
"font-size": "13px",
color: "var(--cortex-text-muted)",
"line-height": "1.5",
};
const footerStyle: JSX.CSSProperties = {
display: "flex",
"align-items": "center",
"justify-content": "flex-end",
gap: "8px",
width: "100%",
};
return (
<CortexModal
open={props.open}
onClose={props.onCancel}
title="Unsaved Changes"
size="sm"
closeOnOverlay={false}
showFooter={true}
footer={
<div style={footerStyle}>
<CortexButton variant="ghost" onClick={props.onCancel}>
Cancel
</CortexButton>
<CortexButton variant="secondary" onClick={props.onDontSave}>
Don't Save
</CortexButton>
<CortexButton variant="primary" onClick={props.onSave}>
Save
</CortexButton>
</div>
}
>
<div style={bodyStyle}>
<div style={iconContainerStyle}>
<CortexIcon
aria-hidden="true"
name="triangle-exclamation"
size={20}
style={{ color: "var(--cortex-warning, #F59E0B)" }}
/>
</div>
<div style={textStyle}>
<p style={messageStyle}>
{props.message ??
`Do you want to save the changes you made to ${props.fileName}?`}
</p>
<p style={detailStyle}>
Your changes will be lost if you don't save them.
</p>
</div>
</div>
</CortexModal>
);
};
export default ConfirmDialog;