-
-
Notifications
You must be signed in to change notification settings - Fork 325
/
Copy pathalt_stateful_picture_component.py
37 lines (34 loc) · 1.14 KB
/
alt_stateful_picture_component.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
from reactpy import component, event, hooks, html
# start
@component
def picture():
is_active, set_is_active = hooks.use_state(False)
if is_active:
return html.div(
{
"className": "background",
"onClick": lambda event: set_is_active(False),
},
html.img(
{
"onClick": event(stop_propagation=True),
"className": "picture picture--active",
"alt": "Rainbow houses in Kampung Pelangi, Indonesia",
"src": "https://i.imgur.com/5qwVYb1.jpeg",
}
),
)
else:
return html.div(
{"className": "background background--active"},
html.img(
{
"onClick": event(
lambda event: set_is_active(True), stop_propagation=True
),
"className": "picture",
"alt": "Rainbow houses in Kampung Pelangi, Indonesia",
"src": "https://i.imgur.com/5qwVYb1.jpeg",
}
),
)