1
1
import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { Dialog } from './Dialog' ;
4
- import { awaitForAsyncTask } from '../utils/event-handlers' ;
4
+ import { awaitForAsyncTask , safeClick } from '../utils/event-handlers' ;
5
5
6
- export function ConfirmationDialog ( { title, message, children, onProceed, onCancel, cancelLabel, proceedLabel } ) {
6
+ export function ConfirmationDialog ( {
7
+ title,
8
+ message,
9
+ children,
10
+ onProceed,
11
+ onCancel,
12
+ cancelLabel,
13
+ proceedLabel,
14
+ proceedType,
15
+ } ) {
7
16
return (
8
17
< Dialog
9
18
title = { title }
10
19
body = { message }
11
20
footer = { ( { close } ) => (
12
21
< >
13
- < button type = "button" className = "btn btn-secondary" onClick = { awaitForAsyncTask ( onCancel , close ) } >
22
+ < button type = "button" className = "btn btn-secondary" onClick = { safeClick ( awaitForAsyncTask ( onCancel , close ) ) } >
14
23
{ cancelLabel }
15
24
</ button >
16
- < button type = "button" className = "btn btn-primary" onClick = { awaitForAsyncTask ( onProceed , close ) } >
25
+ < button
26
+ type = "button"
27
+ className = { `btn btn-${ proceedType } ` }
28
+ onClick = { safeClick ( awaitForAsyncTask ( onProceed , close ) ) }
29
+ >
17
30
{ proceedLabel }
18
31
</ button >
19
32
</ >
@@ -30,6 +43,7 @@ ConfirmationDialog.defaultProps = {
30
43
title : 'Atention required' ,
31
44
cancelLabel : 'Cancel' ,
32
45
proceedLabel : 'Proceed' ,
46
+ proceedType : 'primary' ,
33
47
} ;
34
48
35
49
ConfirmationDialog . propTypes = {
@@ -40,4 +54,5 @@ ConfirmationDialog.propTypes = {
40
54
title : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . element ] ) ,
41
55
cancelLabel : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . element ] ) ,
42
56
proceedLabel : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . element ] ) ,
57
+ proceedType : PropTypes . oneOf ( [ 'primary' , 'danger' , 'success' ] ) ,
43
58
} ;
0 commit comments