htmgo/examples/sse-with-state/pages/index.go
maddalax e806656ec5 wip
2024-10-09 09:57:51 -05:00

42 lines
1.1 KiB
Go

package pages
import (
"fmt"
"github.com/maddalax/htmgo/framework/h"
"sse-with-state/partials"
"sse-with-state/state"
)
func IndexPage(ctx *h.RequestContext) *h.Page {
sessionId := state.GetSessionId(ctx)
return h.NewPage(
RootPage(
ctx,
h.Div(
h.Attribute("ws-connect", fmt.Sprintf("/ws/test?sessionId=%s", sessionId)),
h.Class("flex flex-col gap-4 items-center pt-24 min-h-screen bg-neutral-100"),
h.H3(h.Id("intro-text"), h.Text("Repeater Example"), h.Class("text-2xl")),
partials.CounterForm(ctx, partials.CounterProps{Id: "counter-1"}),
partials.Repeater(ctx, partials.RepeaterProps{
Id: "repeater-1",
AddButton: h.Button(
h.Text("+ Add Item"),
),
RemoveButton: func(index int, children ...h.Ren) *h.Element {
return h.Button(
h.Text("Remove"),
h.Children(children...),
)
},
Item: func(index int) *h.Element {
return h.Input("text",
h.Class("border border-gray-300 rounded p-2"),
h.Value(fmt.Sprintf("item %d", index)))
},
}),
),
),
)
}