forked from bmcmahen/sancho
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlertDialog.tsx
77 lines (72 loc) · 1.71 KB
/
AlertDialog.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
/** @jsx jsx */
import { jsx } from "@emotion/core";
import * as React from "react";
import { Dialog } from "./Dialog";
import { Button, ButtonIntent } from "./Button";
import { useTheme } from "./Theme/Providers";
import { Text } from "./Text";
import { useUid } from "./Hooks/use-uid";
export interface AlertDialogProps {
isOpen: boolean;
onConfirm: () => void;
onCancel?: () => void;
onClose: () => void;
title: string;
subtitle?: string;
confirmLabel?: string;
intent?: ButtonIntent;
}
export const AlertDialog: React.FunctionComponent<AlertDialogProps> = ({
isOpen,
title,
subtitle,
confirmLabel = "Confirm",
onConfirm,
intent = "danger",
onCancel,
onClose
}) => {
const theme = useTheme();
const id = useUid();
const cancel = React.useCallback(() => {
if (onCancel) onCancel();
onClose();
}, [onCancel, onClose]);
const confirm = React.useCallback(() => {
onConfirm();
onClose();
}, [onConfirm]);
return (
<Dialog
role="alertdialog"
aria-labelledby={id}
onRequestClose={cancel}
isOpen={isOpen}
>
<div css={{ padding: "1.5rem" }}>
<Text id={id} variant="h5">
{title}
</Text>
{subtitle && <Text>{subtitle}</Text>}
<div
css={{
marginTop: theme.spaces.md,
display: "flex",
justifyContent: "flex-end"
}}
>
<Button autoFocus onPress={cancel} variant="ghost">
Cancel
</Button>
<Button
onPress={confirm}
css={{ marginLeft: theme.spaces.sm }}
intent={intent}
>
{confirmLabel}
</Button>
</div>
</div>
</Dialog>
);
};