File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed
Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ import eventEmitter from './eventEmitter.js' ;
2+
3+ export default class DialogHelper {
4+ #instance;
5+
6+ #events = eventEmitter ( ) ;
7+
8+ isOpen ( ) {
9+ return ! ! this . #instance;
10+ }
11+
12+ open ( {
13+ buttons = [ ] ,
14+ cssClass = 'underscript-dialog' ,
15+ message,
16+ title,
17+ ...options
18+ } = BootstrapDialog . defaultOptions ) {
19+ if ( this . #instance || ! message || ! title ) return ;
20+ BootstrapDialog . show ( {
21+ ...options ,
22+ title,
23+ message,
24+ buttons : [
25+ ...buttons ,
26+ {
27+ cssClass : 'btn-primary' ,
28+ // TODO: Translate
29+ label : 'Close' ,
30+ action : ( ) => this . close ( ) ,
31+ } ,
32+ ] ,
33+ cssClass : `mono ${ cssClass } ` ,
34+ onshown : ( diag ) => {
35+ this . #instance = diag ;
36+ this . #events. emit ( 'open' , diag ) ;
37+ } ,
38+ onhidden : ( ) => {
39+ this . #instance = null ;
40+ this . #events. emit ( 'close' ) ;
41+ } ,
42+ } ) ;
43+ }
44+
45+ close ( ) {
46+ this . #instance?. close ( ) ;
47+ }
48+
49+ onClose ( callback ) {
50+ this . #events. on ( 'close' , callback ) ;
51+ }
52+
53+ onOpen ( callback ) {
54+ this . #events. on ( 'open' , callback ) ;
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments