-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog_ui.js
82 lines (65 loc) · 1.68 KB
/
dialog_ui.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// dialog.js
// Martin Pravda
// Main container for rendering dialogs
/*jslint browser */
import make_ui from "./ui.js";
import dom from "./dom.js";
function render_css({visibility}) {
const display = (
visibility
? "block;"
: "none;"
);
return `
:host {
display: ${display}
}`;
}
const dialog_ui = make_ui("dialog-ui", function (element, {
on_close,
visibility
}) {
let close_button;
let dialog_container;
const style = dom("style");
const shadow = element.attachShadow({mode: "closed"});
function close() {
style.textContent = render_css({visibility: false});
dialog_container.innerHTML = "";
}
function open(content) {
style.textContent = render_css({visibility: true});
dialog_container.append(content);
}
close_button = dom("button", {
onclick: function (event) {
event.preventDefault();
on_close();
}
}, ["Close"]);
dialog_container = dom("div");
shadow.append(style, close_button, dialog_container);
element.open = open;
element.close = close;
return {
connect() {
style.textContent = render_css({visibility});
},
disconnect() {
close();
}
};
});
//demo import demo from "./demo.js";
//demo const dialog = dialog_ui({
//demo on_close: function on_close() {
//demo dialog.close();
//demo setTimeout(function () {
//demo dialog.open(dom("div", ["Content"]));
//demo }, 1000);
//demo },
//demo visibility: true
//demo });
//demo
//demo demo(dialog);
export default Object.freeze(dialog_ui);