@@ -27,6 +27,7 @@ interface IModalDialogAttributes {
27
27
warning ?: boolean
28
28
actions ?: ModalAction [ ]
29
29
className ?: string
30
+ discardAsPrimary ?: boolean
30
31
}
31
32
interface ModalInput {
32
33
type : EditAttributeType
@@ -56,6 +57,7 @@ export function ModalDialog({
56
57
onDiscard,
57
58
onSecondary,
58
59
secondaryText,
60
+ discardAsPrimary,
59
61
} : React . PropsWithChildren < IModalDialogAttributes > ) : JSX . Element | null {
60
62
const { t } = useTranslation ( )
61
63
const inputResult = useRef < ModalInputResult > (
@@ -114,7 +116,7 @@ export function ModalDialog({
114
116
e . stopPropagation ( )
115
117
116
118
if ( isAcceptKey ( e . code ) ) {
117
- handleAccept ( e )
119
+ discardAsPrimary ? handleDiscard ( e ) : handleAccept ( e )
118
120
} else if ( isDismissKey ( e . code ) ) {
119
121
handleDiscard ( e )
120
122
}
@@ -203,13 +205,23 @@ export function ModalDialog({
203
205
</ div >
204
206
) : null }
205
207
< div
206
- className = { ClassNames ( 'mod' , {
207
- alright : ! secondaryText ,
208
- } ) }
208
+ className = { ClassNames (
209
+ 'mod' ,
210
+ {
211
+ alright : ! secondaryText ,
212
+ } ,
213
+ 'modal-dialog-actions'
214
+ ) }
209
215
>
210
216
{ secondaryText && (
211
217
< button
212
- className = "btn btn-secondary"
218
+ className = { ClassNames (
219
+ 'btn' ,
220
+ discardAsPrimary ? 'btn-primary' : 'btn-secondary' ,
221
+ 'discard-btn' ,
222
+ { 'btn-warn' : discardAsPrimary && warning }
223
+ ) }
224
+ autoFocus = { discardAsPrimary }
213
225
onClick = { handleSecondary }
214
226
onKeyDown = { preventClickOnEnter }
215
227
onKeyUp = { emulateClick }
@@ -240,11 +252,11 @@ export function ModalDialog({
240
252
} )
241
253
) }
242
254
< button
243
- className = { ClassNames ( 'btn btn-primary' , {
255
+ className = { ClassNames ( 'btn' , ! discardAsPrimary ? ' btn-primary' : 'btn-secondary ', {
244
256
right : secondaryText !== undefined ,
245
- 'btn-warn' : warning ,
257
+ 'btn-warn' : ! discardAsPrimary && warning ,
246
258
} ) }
247
- autoFocus
259
+ autoFocus = { ! discardAsPrimary }
248
260
onClick = { handleAccept }
249
261
onKeyDown = { preventClickOnEnter }
250
262
onKeyUp = { emulateClick }
@@ -284,6 +296,8 @@ export interface ModalDialogQueueItem {
284
296
actions ?: ModalAction [ ]
285
297
/** Is a critical decition/information */
286
298
warning ?: boolean
299
+ /** Discard as primary */
300
+ discardAsPrimary ?: boolean
287
301
}
288
302
interface IModalDialogGlobalContainerProps { }
289
303
interface IModalDialogGlobalContainerState {
@@ -382,6 +396,7 @@ class ModalDialogGlobalContainer0 extends React.Component<
382
396
actions = { actions }
383
397
show = { true }
384
398
warning = { onQueue . warning }
399
+ discardAsPrimary = { onQueue . discardAsPrimary }
385
400
>
386
401
{ _ . isString ( onQueue . message ) ? this . renderString ( onQueue . message ) : onQueue . message }
387
402
</ ModalDialog >
0 commit comments