forked from reactive-python/reactpy-django
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponents.py
36 lines (26 loc) · 887 Bytes
/
components.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
import idom
@idom.component
def HelloWorld(websocket):
return idom.html.h1({"id": "hello-world"}, "Hello World!")
@idom.component
def Button(websocket):
count, set_count = idom.hooks.use_state(0)
return idom.html.div(
idom.html.button(
{"id": "counter-inc", "onClick": lambda event: set_count(count + 1)},
"Click me!",
),
idom.html.p(
{"id": "counter-num", "data-count": count},
f"Current count is: {count}",
),
)
@idom.component
def ParametrizedComponent(websocket, x, y):
total = x + y
return idom.html.h1({"id": "parametrized-component", "data-value": total}, total)
victory = idom.web.module_from_template("react", "victory-bar", fallback="...")
VictoryBar = idom.web.export(victory, "VictoryBar")
@idom.component
def SimpleBarChart(websocket):
return VictoryBar()