Skip to content

Commit 4d6f1f7

Browse files
committed
Add WarningDialog component
This was extracted from the `confirm` utility in @hypothesis/frontend-shared.
1 parent 5813192 commit 4d6f1f7

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { ModalDialog, Button } from '@hypothesis/frontend-shared';
2+
3+
export type WarningDialogProps = {
4+
/** Title of the dialog. */
5+
title: string;
6+
7+
/** Message displayed in the dialog. */
8+
message: string;
9+
10+
/** Label for the confirmation button. */
11+
confirmAction: string;
12+
13+
/** Callback invoked when the user confirms the action. */
14+
onConfirm: () => void;
15+
16+
/** Callback invoked when the user aborts the action. */
17+
onCancel: () => void;
18+
};
19+
20+
/**
21+
* A modal dialog that warns users about a potentially destructive action.
22+
*/
23+
export default function WarningDialog({
24+
title,
25+
message,
26+
confirmAction,
27+
onConfirm,
28+
onCancel,
29+
}: WarningDialogProps) {
30+
return (
31+
<ModalDialog
32+
buttons={
33+
<>
34+
<Button data-testid="cancel-button" onClick={onCancel}>
35+
Cancel
36+
</Button>
37+
<Button
38+
variant="primary"
39+
data-testid="confirm-button"
40+
onClick={onConfirm}
41+
>
42+
{confirmAction}
43+
</Button>
44+
</>
45+
}
46+
title={title}
47+
onClose={onCancel}
48+
>
49+
{message}
50+
</ModalDialog>
51+
);
52+
}

0 commit comments

Comments
 (0)