2
2
3
3
<img src =" logo.png " alt =" Logo " width =" 300 " align =" right " >
4
4
5
- [ ![ GoDoc] ( https://pkg.go.dev/badge/github.com/maragudk/ gomponents-htmx )] ( https://pkg.go.dev/github.com/maragudk /gomponents-htmx )
5
+ [ ![ GoDoc] ( https://pkg.go.dev/badge/maragu.dev/ gomponents-htmx )] ( https://pkg.go.dev/maragu.dev /gomponents-htmx )
6
6
[ ![ CI] ( https://github.com/maragudk/gomponents-htmx/actions/workflows/ci.yml/badge.svg )] ( https://github.com/maragudk/gomponents-htmx/actions/workflows/ci.yml )
7
7
8
8
[ HTMX] ( https://htmx.org ) attributes and helpers for [ gomponents] ( https://www.gomponents.com ) .
@@ -14,7 +14,7 @@ Does your company depend on this project? [Contact me at
[email protected] ](mailt
14
14
## Usage
15
15
16
16
``` shell
17
- go get github.com/maragudk/ gomponents-htmx
17
+ go get maragu.dev/ gomponents-htmx@v1.0.0-beta1
18
18
```
19
19
20
20
``` go
@@ -26,12 +26,13 @@ import (
26
26
" net/http"
27
27
" time"
28
28
29
- g " github.com/maragudk/gomponents"
30
- c " github.com/maragudk/gomponents/components"
31
- . " github.com/maragudk/gomponents/html"
32
- ghttp " github.com/maragudk/gomponents/http"
33
- hx " github.com/maragudk/gomponents-htmx"
34
- hxhttp " github.com/maragudk/gomponents-htmx/http"
29
+ . " maragu.dev/gomponents"
30
+ . " maragu.dev/gomponents/components"
31
+ . " maragu.dev/gomponents/html"
32
+ . " maragu.dev/gomponents/http"
33
+
34
+ hx " maragu.dev/gomponents-htmx"
35
+ hxhttp " maragu.dev/gomponents-htmx/http"
35
36
)
36
37
37
38
func main () {
@@ -43,11 +44,11 @@ func main() {
43
44
func start () error {
44
45
now := time.Now ()
45
46
mux := http.NewServeMux ()
46
- mux.HandleFunc (" /" , ghttp. Adapt (func (w http.ResponseWriter , r *http.Request ) (g. Node , error ) {
47
+ mux.HandleFunc (" /" , Adapt (func (w http.ResponseWriter , r *http.Request ) (Node, error ) {
47
48
if r.Method == http.MethodPost && hxhttp.IsBoosted (r.Header ) {
48
49
now = time.Now ()
49
50
50
- hxhttp.SetPushURL (w.Header (), " /?time=" +now.Format (timeFormat ))
51
+ hxhttp.SetPushURL (w.Header (), " /?time=" +now.Format (timeOnly ))
51
52
52
53
return partial (now), nil
53
54
}
@@ -61,22 +62,29 @@ func start() error {
61
62
return nil
62
63
}
63
64
64
- const timeFormat = " 15:04:05"
65
+ const timeOnly = " 15:04:05"
66
+
67
+ func page (now time .Time ) Node {
68
+ return HTML5 (HTML5Props{
69
+ Title: now.Format (timeOnly),
65
70
66
- func page (now time .Time ) g .Node {
67
- return c.HTML5 (c.HTML5Props {
68
- Title: now.Format (timeFormat),
69
- Head: []g.Node {
71
+ Head: []Node{
70
72
Script (Src (" https://cdn.tailwindcss.com?plugins=forms,typography" )),
71
73
Script (Src (" https://unpkg.com/htmx.org" )),
72
74
},
73
- Body: []g.Node {
75
+
76
+ Body: []Node{
74
77
Div (Class (" max-w-7xl mx-auto p-4 prose lg:prose-lg xl:prose-xl" ),
75
- H1 (g.Text (` gomponents + HTMX` )),
76
- P (g.Textf (` Time at last full page refresh was %v.` , now.Format (timeFormat))),
78
+ H1 (Text (` gomponents + HTMX` )),
79
+
80
+ P (Textf (` Time at last full page refresh was %v.` , now.Format (timeOnly))),
81
+
77
82
partial (now),
78
- FormEl (Method (" post" ), Action (" /" ), hx.Boost (" true" ), hx.Target (" #partial" ), hx.Swap (" outerHTML" ),
79
- Button (Type (" submit" ), g.Text (` Update time` ),
83
+
84
+ Form (Method (" post" ), Action (" /" ),
85
+ hx.Boost (" true" ), hx.Target (" #partial" ), hx.Swap (" outerHTML" ),
86
+
87
+ Button (Type (" submit" ), Text (` Update time` ),
80
88
Class (" rounded-md border border-transparent bg-orange-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-orange-700 focus:outline-none focus:ring-2 focus:ring-orange-500 focus:ring-offset-2" ),
81
89
),
82
90
),
@@ -85,11 +93,7 @@ func page(now time.Time) g.Node {
85
93
})
86
94
}
87
95
88
- func partial (now time .Time ) g . Node {
89
- return P (ID (" partial" ), g. Textf (` Time was last updated at %v.` , now.Format (timeFormat )))
96
+ func partial (now time .Time ) Node {
97
+ return P (ID (" partial" ), Textf (` Time was last updated at %v.` , now.Format (timeOnly )))
90
98
}
91
-
92
99
```
93
-
94
-
95
- Made in 🇩🇰 by [ maragu] ( https://www.maragu.dk/ ) , maker of [ online Go courses] ( https://www.golang.dk/ ) .
0 commit comments