-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConfirmationDialog.js
48 lines (45 loc) · 1.34 KB
/
ConfirmationDialog.js
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
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Dialog, {
DialogActions,
DialogContent,
DialogTitle,
} from 'material-ui/Dialog';
import Button from 'material-ui/Button';
export default class ConfirmationDialog extends Component {
static propTypes = {
title: PropTypes.string,
message: PropTypes.string,
okButtonLabel: PropTypes.string,
cancelButtonLabel: PropTypes.string,
open: PropTypes.bool,
destructive: PropTypes.bool,
confirm: PropTypes.func.isRequired,
cancel: PropTypes.func.isRequired,
};
static defaultProps = {
destructive: false,
open: true,
okButtonLabel: 'Ok',
cancelButtonLabel: 'Cancel',
message: 'Are you sure?',
};
render() {
const { okButtonLabel, cancelButtonLabel } = this.props;
const { open, title, message, destructive, confirm, cancel } = this.props;
return (
<Dialog open={open} onRequestClose={cancel}>
{title ? <DialogTitle>{title}</DialogTitle> : null}
<DialogContent>{message}</DialogContent>
<DialogActions>
<Button onClick={cancel} color="primary">
{cancelButtonLabel}
</Button>
<Button onClick={confirm} className={destructive ? 'red' : null}>
{okButtonLabel}
</Button>
</DialogActions>
</Dialog>
);
}
}