@@ -283,4 +283,46 @@ export class Utils {
283283 return result ;
284284 } ;
285285 }
286+
287+ /**
288+ * Renders confirm/close buttons with callback function
289+ */
290+ static createConfirmationContainer (
291+ container : HTMLElement ,
292+ confirmText : string ,
293+ cancelText : string ,
294+ onConfirm : ( Function : object ) => void ,
295+ onCancel : ( Function : object ) => void
296+ ) : void {
297+ const confirmationButtonsContainer = document . createElement ( 'div' ) ;
298+ confirmationButtonsContainer . classList . add ( 'confirmation-btns' ) ;
299+ container . append ( confirmationButtonsContainer ) ;
300+
301+ this . createButton ( confirmationButtonsContainer , cancelText , [ 'btn-cancel' ] , true , onCancel ) ;
302+ this . createButton ( confirmationButtonsContainer , confirmText , [ 'btn-confirm' ] , true , onConfirm ) ;
303+ }
304+
305+ /**
306+ * Renders a button with optional callback function
307+ */
308+ static createButton (
309+ container : HTMLElement ,
310+ text : string ,
311+ className : string [ ] = [ ] ,
312+ visibility : boolean = true ,
313+ callback : ( Function : object ) => void = null
314+ ) : void {
315+ className = className . concat ( [ 'btn' , 'waves-effect' , 'text' ] ) ;
316+ const button = document . createElement ( 'button' ) ;
317+ button . className = className . join ( ' ' ) ;
318+ button . style . visibility = visibility ? 'visible' : 'hidden' ;
319+ button . type = 'button' ;
320+ button . tabIndex = ! ! visibility ? 0 : - 1 ;
321+ button . innerText = text ;
322+ button . addEventListener ( 'click' , callback ) ;
323+ button . addEventListener ( 'keypress' , ( e ) => {
324+ if ( Utils . keys . ENTER . includes ( e . key ) ) callback ( e ) ;
325+ } ) ;
326+ container . append ( button ) ;
327+ }
286328}
0 commit comments