1- import React from 'react' ;
2- import { Button , ModalProps , Modal , ModalVariant , ButtonVariant } from '@patternfly/react-core' ;
1+ import React , { useState } from 'react' ;
2+ import { Button , ModalProps , Modal , ModalVariant , ButtonVariant , Checkbox } from '@patternfly/react-core' ;
33
44export interface WarningModalProps extends Omit < ModalProps , 'ref' > {
55 /** Callback for the confirm action button. */
66 onConfirm ?: ( ) => void ;
77 /** Custom label for the confirm action button */
8- confirmButtonLabel ? : string ;
8+ confirmButtonLabel ?: string ;
99 /** Custom label for the cancel action button */
10- cancelButtonLabel ? : string ;
10+ cancelButtonLabel ?: string ;
11+ /** Whether modal requires a checkbox before confirming */
12+ withCheckbox ?: boolean ;
13+ /** Custom checkbox label */
14+ checkboxLabel ?: string ;
15+ /** Visual variant of the confirm button */
16+ confirmButtonVariant ?: boolean ;
1117}
1218
1319const WarningModal : React . FunctionComponent < WarningModalProps > = ( {
@@ -19,37 +25,55 @@ const WarningModal: React.FunctionComponent<WarningModalProps> = ({
1925 cancelButtonLabel = 'Cancel' ,
2026 variant = ModalVariant . small ,
2127 titleIconVariant = 'warning' ,
28+ withCheckbox = false ,
29+ checkboxLabel= 'I understand that this action cannot be undone' ,
30+ confirmButtonVariant = false ,
2231 ...props
23- } : WarningModalProps ) => (
24- < Modal
25- variant = { variant }
26- isOpen = { isOpen }
27- onClose = { onClose }
28- onEscapePress = { onClose }
29- titleIconVariant = { titleIconVariant }
30- actions = { [
31- < Button
32- ouiaId = "primary-confirm-button"
33- key = "confirm"
34- variant = { ButtonVariant . primary }
35- onClick = { onConfirm }
36- >
37- { confirmButtonLabel }
38- </ Button > ,
39- < Button
40- ouiaId = "secondary-cancel-button"
41- key = "cancel"
42- variant = { ButtonVariant . link }
43- onClick = { onClose }
44- >
45- { cancelButtonLabel }
46- </ Button > ,
47- ] }
48- { ...props }
49- >
50- { children }
51- </ Modal >
52- ) ;
32+ } : WarningModalProps ) => {
33+ const [ checked , setChecked ] = useState ( false ) ;
34+
35+ return (
36+ < Modal
37+ variant = { variant }
38+ isOpen = { isOpen }
39+ onClose = { onClose }
40+ onEscapePress = { onClose }
41+ titleIconVariant = { titleIconVariant }
42+ actions = { [
43+ < Button
44+ ouiaId = "primary-confirm-button"
45+ key = "confirm"
46+ variant = { confirmButtonVariant ? ButtonVariant . danger : ButtonVariant . primary }
47+ onClick = { onConfirm }
48+ isDisabled = { withCheckbox && ! checked }
49+ >
50+ { confirmButtonLabel }
51+ </ Button > ,
52+ < Button
53+ ouiaId = "secondary-cancel-button"
54+ key = "cancel"
55+ variant = { ButtonVariant . link }
56+ onClick = { onClose }
57+ >
58+ { cancelButtonLabel }
59+ </ Button > ,
60+ ] }
61+ { ...props }
62+ >
63+ { children }
64+ { withCheckbox ? (
65+ < Checkbox
66+ isChecked = { checked }
67+ onChange = { ( ) => setChecked ( ! checked ) }
68+ label = { checkboxLabel }
69+ id = "warning-modal-check"
70+ className = "pf-v5-u-mt-lg"
71+ />
72+ ) : null }
73+ </ Modal >
74+ )
75+
76+ } ;
5377
5478
5579export default WarningModal ;
0 commit comments