htmgo/htmgo-site/partials/navbar.go

147 lines
3.2 KiB
Go
Raw Normal View History

2024-09-20 16:45:23 +00:00
package partials
2024-09-21 03:59:07 +00:00
import (
"github.com/maddalax/htmgo/framework/h"
)
2024-09-20 16:45:23 +00:00
type NavItem struct {
Name string
Url string
}
2024-09-20 20:15:12 +00:00
func ToggleNavbar(ctx *h.RequestContext) *h.Partial {
2024-09-21 16:52:56 +00:00
return h.SwapManyPartial(
ctx,
MobileNav(h.GetQueryParam(ctx, "expanded") == "true"),
2024-09-20 20:15:12 +00:00
)
}
2024-09-20 16:45:23 +00:00
2024-09-20 20:15:12 +00:00
var navItems = []NavItem{
{Name: "Docs", Url: "/docs"},
{Name: "Examples", Url: "/examples"},
}
2024-09-24 18:23:38 +00:00
func Star() *h.Element {
return h.Div(
h.Id("github-star"),
h.Class("min-w-[100px]"),
h.Raw(`
2024-09-20 16:45:23 +00:00
<a
2024-09-24 18:23:38 +00:00
class="github-button hidden min-w-[100px]"
2024-09-20 16:45:23 +00:00
href="https://github.com/maddalax/htmgo"
data-color-scheme="no-preference: light; light: light; dark: dark;"
data-icon="octicon-star"
data-size="large"
data-show-count="true"
aria-label="Star maddalax/htmgo on GitHub">Star</a>
2024-09-24 18:23:38 +00:00
`),
)
2024-09-20 20:15:12 +00:00
}
2024-09-20 16:45:23 +00:00
2024-09-20 20:15:12 +00:00
func NavBar(expanded bool) *h.Element {
2024-09-24 19:51:46 +00:00
prelease := h.A(h.Class("bg-yellow-200 text-yellow-800 text-center p-2 flex items-center justify-center"),
h.Href("https://github.com/maddalax/htmgo/issues"),
h.Attribute("target", "_blank"),
h.Text("htmgo is in alpha release. Please report any issues on GitHub."),
2024-09-20 18:25:14 +00:00
)
2024-09-20 20:15:12 +00:00
desktopNav := h.Nav(
2024-09-21 03:59:07 +00:00
h.Script("https://buttons.github.io/buttons.js"),
2024-09-20 20:15:12 +00:00
h.Class("hidden sm:block bg-neutral-100 border border-b-slate-300 p-4 md:p-3"),
h.Div(
2024-09-24 18:16:07 +00:00
h.Class("max-w-[95%] md:max-w-3xl px-4 mx-auto"),
2024-09-20 20:15:12 +00:00
h.Div(
h.Class("flex justify-between items-center"),
h.Div(
h.Class("flex items-center"),
h.A(
h.Class("text-2xl"),
h.Href("/"),
h.Text("htmgo"),
)),
h.Div(
h.Class("flex gap-4 items-center"),
h.List(navItems, func(item NavItem, index int) *h.Element {
return h.Div(
h.Class("flex items-center"),
h.A(
h.Class(""),
h.Href(item.Url),
h.Text(item.Name),
),
)
}),
2024-09-24 18:16:07 +00:00
h.Div(
h.Class("ml-2 hidden md:block min-w-[99px]"),
Star(),
),
2024-09-20 20:15:12 +00:00
),
),
),
)
2024-09-20 18:25:14 +00:00
return h.Div(
2024-09-20 20:15:12 +00:00
h.Id("navbar"),
2024-09-20 18:25:14 +00:00
prelease,
2024-09-20 20:15:12 +00:00
MobileNav(expanded),
desktopNav,
)
}
func MobileNav(expanded bool) *h.Element {
return h.Nav(
h.Id("mobile-nav"),
h.Class("block sm:hidden bg-neutral-100 border border-b-slate-300 p-4 md:p-3"),
h.Div(
h.Class("max-w-[95%] md:max-w-prose mx-auto"),
2024-09-20 16:45:23 +00:00
h.Div(
2024-09-20 20:15:12 +00:00
h.Class("flex justify-between items-center"),
2024-09-20 16:45:23 +00:00
h.Div(
2024-09-20 20:15:12 +00:00
h.Class("flex items-center"),
h.A(
2024-09-21 03:59:07 +00:00
h.Boost(),
2024-09-20 20:15:12 +00:00
h.Class("text-2xl"),
h.Href("/"),
h.Text("htmgo"),
)),
h.Div(
h.Class("flex items-center"),
h.Button(
2024-09-21 03:59:07 +00:00
h.Boost(),
h.GetPartialWithQs(
ToggleNavbar,
h.NewQs("expanded", h.Ternary(expanded, "false", "true"), "test", "true"),
"click",
),
h.AttributePairs(
"class", "text-2xl",
"aria-expanded", h.Ternary(expanded, "true", "false"),
),
2024-09-20 20:15:12 +00:00
h.Class("text-2xl"),
h.Text("☰"),
2024-09-20 18:25:14 +00:00
),
2024-09-20 16:45:23 +00:00
),
),
),
2024-09-20 20:15:12 +00:00
h.If(expanded, h.Div(
h.Class("mt-2 ml-2 flex flex-col gap-2"),
h.Script("https://buttons.github.io/buttons.js"),
h.List(navItems, func(item NavItem, index int) *h.Element {
return h.Div(
h.Class("flex items-center"),
h.A(
2024-09-21 03:59:07 +00:00
h.Boost(),
2024-09-20 20:15:12 +00:00
h.Class(""),
h.Href(item.Url),
h.Text(item.Name),
),
)
}),
h.Div(Star()),
)),
2024-09-20 16:45:23 +00:00
)
}