-
Notifications
You must be signed in to change notification settings - Fork 1
/
view.py
77 lines (67 loc) · 1.74 KB
/
view.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
from fastapi import FastAPI
from uvicorn import run
from reactpy import component, html, hooks
from reactpy.backend.fastapi import configure, Options
from dukkha.utils import head
import demo
app = FastAPI()
def Components():
for name, component in demo.demos.items():
yield html.div(
{
"class": "p-4 border-2 border-gray-200 rounded-lg shadow-md my-4",
},
html.h2(
{
"class": "text-2xl font-bold mb-4",
},
name,
),
component(),
)
@component
def Root():
dark, set_dark = hooks.use_state(False)
return html.main(
{
"class": "dark" if dark else "",
},
html.button(
{
"class": "fixed bottom-4 right-4 p-2 rounded-full shadow-md",
"on_click": lambda _: set_dark(not dark),
},
html.span(
{
"class": "text-2xl",
},
"🌞" if dark else "🌚",
),
),
html.div(
{
"class": "bg-gray-100 min-h-screen dark:bg-gray-900 dark:text-white",
},
html.div(
{
"class": "container mx-auto p-4",
},
html.h1(
{
"class": "text-6xl font-bold mb-4",
},
"components",
),
html.div(
*Components(),
),
),
),
)
configure(
app,
Root,
Options(head=head.create_head(tailwind_config={})),
)
if __name__ == "__main__":
run(app)