@@ -4,49 +4,38 @@ import PropTypes from 'prop-types';
4
4
import { awaitForAsyncTask , safeClick } from '../utils/event-handlers' ;
5
5
import { formatClasses } from '../utils/attributes' ;
6
6
7
- import { Dialog } from './Dialog' ;
8
-
9
- export function ConfirmationDialog ( {
10
- title,
11
- message,
12
- children,
13
- onProceed,
14
- onCancel,
15
- cancelLabel,
16
- proceedLabel,
17
- proceedType,
18
- } ) {
7
+ import { Dialog , useDialog } from './Dialog' ;
8
+
9
+ export function useConfirmationDialog ( { title, message, ...footerProps } ) {
10
+ const { showDialog, DialogPortal } = useDialog ( {
11
+ title,
12
+ body : message ,
13
+ // eslint-disable-next-line react/prop-types
14
+ footer ( { close } ) {
15
+ return < ConfirmationDialogFooter close = { close } { ...footerProps } /> ;
16
+ } ,
17
+ } ) ;
18
+
19
+ return {
20
+ showDialog,
21
+ DialogPortal,
22
+ } ;
23
+ }
24
+
25
+ export function ConfirmationDialog ( { title, message, children, ...footerProps } ) {
19
26
return (
20
27
< Dialog
21
28
title = { title }
22
29
body = { message }
23
- footer = { ( { close } ) => (
24
- < >
25
- < button type = "button" className = "btn btn-secondary" onClick = { safeClick ( awaitForAsyncTask ( onCancel , close ) ) } >
26
- { cancelLabel }
27
- </ button >
28
- < button
29
- type = "button"
30
- className = { formatClasses ( [ 'btn' , `btn-${ proceedType } ` ] ) }
31
- onClick = { safeClick ( awaitForAsyncTask ( onProceed , close ) ) }
32
- >
33
- { proceedLabel }
34
- </ button >
35
- </ >
36
- ) }
30
+ footer = { ( { close } ) => < ConfirmationDialogFooter close = { close } { ...footerProps } /> }
37
31
>
38
32
{ children }
39
33
</ Dialog >
40
34
) ;
41
35
}
42
36
43
37
ConfirmationDialog . defaultProps = {
44
- onProceed : ( ) => { } ,
45
- onCancel : ( ) => { } ,
46
38
title : 'Atention required' ,
47
- cancelLabel : 'Cancel' ,
48
- proceedLabel : 'Proceed' ,
49
- proceedType : 'primary' ,
50
39
} ;
51
40
52
41
ConfirmationDialog . propTypes = {
@@ -59,3 +48,35 @@ ConfirmationDialog.propTypes = {
59
48
proceedLabel : PropTypes . node ,
60
49
proceedType : PropTypes . oneOf ( [ 'primary' , 'danger' , 'success' ] ) ,
61
50
} ;
51
+
52
+ function ConfirmationDialogFooter ( { close, onProceed, onCancel, cancelLabel, proceedLabel, proceedType } ) {
53
+ return (
54
+ < >
55
+ < button type = "button" className = "btn btn-secondary" onClick = { safeClick ( awaitForAsyncTask ( onCancel , close ) ) } >
56
+ { cancelLabel }
57
+ </ button >
58
+ < button
59
+ type = "button"
60
+ className = { formatClasses ( [ 'btn' , `btn-${ proceedType } ` ] ) }
61
+ onClick = { safeClick ( awaitForAsyncTask ( onProceed , close ) ) }
62
+ >
63
+ { proceedLabel }
64
+ </ button >
65
+ </ >
66
+ ) ;
67
+ }
68
+ ConfirmationDialogFooter . defaultProps = {
69
+ onProceed : ( ) => { } ,
70
+ onCancel : ( ) => { } ,
71
+ cancelLabel : 'Cancel' ,
72
+ proceedLabel : 'Proceed' ,
73
+ proceedType : 'primary' ,
74
+ } ;
75
+ ConfirmationDialogFooter . propTypes = {
76
+ close : PropTypes . func ,
77
+ onCancel : PropTypes . func ,
78
+ onProceed : PropTypes . func ,
79
+ cancelLabel : PropTypes . node ,
80
+ proceedLabel : PropTypes . node ,
81
+ proceedType : PropTypes . oneOf ( [ 'primary' , 'danger' , 'success' ] ) ,
82
+ } ;
0 commit comments