-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (43 loc) · 1003 Bytes
/
main.go
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
package main
import (
"embed"
"net/http"
"strconv"
"time"
w "github.com/i2y/wasabi"
a "github.com/i2y/wasabi/modifier/attr"
)
//go:embed counter/assets
var assets embed.FS
func main() {
handler := w.NewHTTPHandler(
"counter",
"/counter",
counter,
w.Assets(assets),
w.Timeout(10*time.Minute),
)
http.ListenAndServe(":8080", handler)
}
func counter(f *w.Factory) w.Element {
count := w.NewState(0)
return f.Div(a.Class("flex items-center justify-center w-screen h-screen"))(
f.Button(
a.Class("btn text-4xl w-24 h-24 items-center justify-center"),
a.OnClick(func() { count.Set(count.Get() + 1) }),
)(
f.Text("+"),
),
f.Reactive(count, func() w.Element {
return f.Div(a.Class("text-slate-400 text-4xl w-24 h-24 flex items-center justify-center"))(
f.Text(strconv.Itoa(count.Get())),
)
}),
f.Button(
a.Class("btn text-4xl w-24 h-24 items-center justify-center"),
a.OnClick(func() { count.Set(count.Get() - 1) }),
)(
f.Text("-"),
),
)
}