-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmodal.py
86 lines (70 loc) · 2.29 KB
/
modal.py
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
81
82
83
84
85
86
from copy import copy
from uuid import uuid4
import idom
from idom.html import div, i
from conreq import HomepageState, config
# pylint: disable=protected-access
MODAL_HEADER = {"className": "modal-header"}
MODAL_HEADER_BTN_CONTAINER = {
"className": "modal-header-btn-container",
"data-bs-dismiss": "modal",
"aria-label": "Close",
}
MODAL_TITLE = {"className": "title"}
MODAL_BODY = {"className": "modal-body loading"}
MODAL_FOOTER = {"className": "modal-footer"}
bootstrap = idom.web.module_from_template(
"[email protected]", "[email protected]", resolve_exports=True
)
bootstrap_modal = idom.web.export(bootstrap, "Modal", allow_children=True)
@idom.component
def modal(websocket, state: HomepageState, set_state):
return div()
return bootstrap_modal(
{
"show": state._modal_state.show,
"centered": state._modal_state.centered,
"size": state._modal_state.size,
**state._modal_state.kwargs,
},
*(
[state._modal(websocket, state, set_state)]
if state._modal
else [
modal_head(websocket, state, set_state),
modal_body(websocket, state, set_state),
modal_footer(websocket, state, set_state),
]
),
key=f"{state._modal.__module__}.{state._modal.__name__}"
if state._modal
else str(uuid4()),
)
def modal_head(websocket, state: HomepageState, set_state):
# pylint: disable=unused-argument
async def close_modal(_):
state._modal_state.show = False
set_state(copy(state))
return div(
MODAL_HEADER,
div(
MODAL_HEADER_BTN_CONTAINER,
i(
{
"title": "Close",
"className": "fas fa-window-close clickable",
"onClick": close_modal,
}
),
),
div(MODAL_TITLE, "Loading..."),
)
def modal_body(websocket, state: HomepageState, set_state):
# pylint: disable=unused-argument
return div(
MODAL_BODY,
div({"className": "loading"}, config.components.loading_animation),
)
def modal_footer(websocket, state: HomepageState, set_state):
# pylint: disable=unused-argument
return div(MODAL_FOOTER)