-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.py
36 lines (30 loc) · 942 Bytes
/
hello.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
from fasttea import FastTEA, Model, Msg, Cmd, Element, CSSFramework
from fasttea.html import div, h1, input_, button, p
class AppModel(Model):
name: str = ""
greeting: str = ""
app = FastTEA(AppModel(), css_framework=CSSFramework.PICO)
@app.update
def update(msg: Msg, model: AppModel) -> tuple[AppModel, Cmd | None]:
if msg.action == "greet":
model.name = msg.value
model.greeting = f"Hello {msg.value}!"
return model, None
@app.view
def view(model: AppModel) -> Element:
return div({},[
h1({}, "FastTEA Hello Example"),
input_({
"id": "input",
"type": "text",
"value": model.name,
"name": "name",
"placeholder": "Enter your name"
}, ""),
button({
"onClick": "greet",
"getValue": "input"
},"Greet"),
p ({}, model.greeting)
])
app.run()