diff options
author | Markus Wüstenberg | 2020-12-10 13:00:23 +0100 |
---|---|---|
committer | GitHub | 2020-12-10 13:00:23 +0100 |
commit | a76262652b227c95ce140f3698c46f59b79354ac (patch) | |
tree | 15987ad4a4a4f830f0df9fc110faf667fe83514a /examples/dot-import/dot-import.go | |
parent | a7e24c6cddaafb98091c3989c9da7779eeba30b5 (diff) | |
download | gomponents-a76262652b227c95ce140f3698c46f59b79354ac.tar.lz gomponents-a76262652b227c95ce140f3698c46f59b79354ac.tar.zst gomponents-a76262652b227c95ce140f3698c46f59b79354ac.zip |
Move elements and attributes into html package (#52)
This makes it easier to use dot-imports. Also updated the readme and examples with new usage, and move the `Classes` helper into the `components` package.
Diffstat (limited to 'examples/dot-import/dot-import.go')
-rw-r--r-- | examples/dot-import/dot-import.go | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/examples/dot-import/dot-import.go b/examples/dot-import/dot-import.go index be3bd50..1d595b8 100644 --- a/examples/dot-import/dot-import.go +++ b/examples/dot-import/dot-import.go @@ -3,9 +3,9 @@ package main import ( "net/http" - . "github.com/maragudk/gomponents" + g "github.com/maragudk/gomponents" . "github.com/maragudk/gomponents/components" - . "github.com/maragudk/gomponents/el" + . "github.com/maragudk/gomponents/html" ) func main() { @@ -13,25 +13,32 @@ func main() { } func handler(w http.ResponseWriter, r *http.Request) { - p := page(props{ - title: r.URL.Path, - path: r.URL.Path, - }) - _ = p.Render(w) -} - -type props struct { - title string - path string + page := Page("Hi!", r.URL.Path) + _ = page.Render(w) } -func page(p props) Node { - return HTML5(DocumentProps{ - Title: p.title, +func Page(title, currentPath string) g.Node { + return HTML5(HTML5Props{ + Title: title, Language: "en", - Body: []Node{ - H1(p.title), - P(Textf("Welcome to the page at %v.", p.path)), + Head: []g.Node{ + StyleEl(Type("text/css"), g.Raw(".is-active{ font-weight: bold }")), + }, + Body: []g.Node{ + Navbar(currentPath), + H1(title), + P(g.Textf("Welcome to the page at %v.", currentPath)), }, }) } + +func Navbar(currentPath string) g.Node { + return Nav( + NavbarLink("/", "Home", currentPath), + NavbarLink("/about", "About", currentPath), + ) +} + +func NavbarLink(href, name, currentPath string) g.Node { + return A(href, Classes{"is-active": currentPath == href}, g.Text(name)) +} |