Skip to content

Commit 75bbc20

Browse files
committed
feat: dialog helper
1 parent 2392469 commit 75bbc20

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/utils/DialogHelper.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
}

0 commit comments

Comments
 (0)