1
1
import { forwardRef , useImperativeHandle , useRef , useState } from 'react' ;
2
- import { Typography } from '../../base' ;
2
+ import { Checkbox , FormControlLabel , Typography } from '../../base' ;
3
3
import { useTheme } from '../../theme' ;
4
4
import { Modal , ModalBody , ModalButtonPrimary , ModalButtonSecondary , ModalFooter } from '../Modal' ;
5
5
import { ActionComponent , Subtitle } from './style' ;
@@ -26,6 +26,8 @@ interface State {
26
26
showInfoIcon ?: string ;
27
27
variant ?: PromptVariant ;
28
28
headerIcon ?: React . ReactNode ;
29
+ showCheckbox ?: boolean ;
30
+ isChecked ?: boolean ;
29
31
}
30
32
31
33
interface ShowParams {
@@ -34,11 +36,13 @@ interface ShowParams {
34
36
primaryOption : string ;
35
37
variant : PromptVariant ;
36
38
showInfoIcon ?: string ;
39
+ showCheckbox ?: boolean ;
37
40
headerIcon ?: React . ReactNode ;
38
41
}
39
42
40
43
export interface PromptRef {
41
44
show : ( params : ShowParams ) => Promise < string > ;
45
+ getCheckboxState : ( ) => boolean ;
42
46
}
43
47
44
48
const PromptComponent = forwardRef < PromptRef , PromptProps > ( ( { variant } , ref ) => {
@@ -49,7 +53,9 @@ const PromptComponent = forwardRef<PromptRef, PromptProps>(({ variant }, ref) =>
49
53
primaryOption : '' ,
50
54
showInfoIcon : '' ,
51
55
variant,
52
- headerIcon : undefined
56
+ headerIcon : undefined ,
57
+ isChecked : false ,
58
+ showCheckbox : false
53
59
} ) ;
54
60
55
61
/* This ref is used to store the resolve and reject functions of the promise returned by the show method */
@@ -67,7 +73,8 @@ const PromptComponent = forwardRef<PromptRef, PromptProps>(({ variant }, ref) =>
67
73
setState ( {
68
74
...params ,
69
75
isOpen : true ,
70
- showInfoIcon : params . showInfoIcon || ''
76
+ showInfoIcon : params . showInfoIcon || '' ,
77
+ showCheckbox : ! ! params . showCheckbox
71
78
} ) ;
72
79
} ) ;
73
80
} ;
@@ -77,11 +84,20 @@ const PromptComponent = forwardRef<PromptRef, PromptProps>(({ variant }, ref) =>
77
84
setState ( ( prevState ) => ( { ...prevState , isOpen : false } ) ) ;
78
85
} ;
79
86
87
+ const handleCheckboxChange = ( ) => {
88
+ setState ( ( prevState ) => ( { ...prevState , isChecked : ! prevState . isChecked } ) ) ;
89
+ } ;
90
+
91
+ const getCheckboxState = ( ) => {
92
+ return ! ! state . isChecked ;
93
+ } ;
94
+
80
95
useImperativeHandle ( ref , ( ) => ( {
81
- show
96
+ show,
97
+ getCheckboxState
82
98
} ) ) ;
83
99
84
- const { isOpen, primaryOption, title, subtitle, showInfoIcon, headerIcon } = state ;
100
+ const { isOpen, primaryOption, title, subtitle, showInfoIcon, headerIcon, showCheckbox } = state ;
85
101
const { resolve } = promiseInfoRef . current ;
86
102
87
103
return (
@@ -96,10 +112,28 @@ const PromptComponent = forwardRef<PromptRef, PromptProps>(({ variant }, ref) =>
96
112
{ subtitle && (
97
113
< ModalBody >
98
114
< Subtitle id = "alert-dialog-description" variant = "body1" component = "div" >
99
- < Typography variant = "body1" component = "div" >
115
+ < Typography
116
+ variant = "body1"
117
+ component = "div"
118
+ style = { {
119
+ color : theme . palette . text . primary
120
+ } }
121
+ >
100
122
{ subtitle }
101
123
</ Typography >
102
124
</ Subtitle >
125
+ { showCheckbox && (
126
+ < FormControlLabel
127
+ control = {
128
+ < Checkbox
129
+ checked = { getCheckboxState ( ) }
130
+ onChange = { handleCheckboxChange }
131
+ color = "primary"
132
+ />
133
+ }
134
+ label = { < span style = { { fontSize : '1rem' } } > Do not show again</ span > }
135
+ />
136
+ ) }
103
137
</ ModalBody >
104
138
) }
105
139
< ModalFooter variant = "filled" helpText = { showInfoIcon } >
0 commit comments