From b5f7532efd3f234be26162caf3142259c7becc5c Mon Sep 17 00:00:00 2001 From: luke-dcz Date: Wed, 5 Feb 2025 12:11:51 +0000 Subject: [PATCH 1/4] define routes for cascading select example --- internal/server/routes.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/server/routes.go b/internal/server/routes.go index 0d19465..a895b10 100644 --- a/internal/server/routes.go +++ b/internal/server/routes.go @@ -7,6 +7,7 @@ import ( "github.com/gofs-cli/template/internal/server/handlers" activesearch "github.com/gofs-cli/template/internal/ui/pages/active-search" bulkupdate "github.com/gofs-cli/template/internal/ui/pages/bulk-update" + cascadingselect "github.com/gofs-cli/template/internal/ui/pages/cascading-select" clicktoedit "github.com/gofs-cli/template/internal/ui/pages/click-to-edit" clicktoload "github.com/gofs-cli/template/internal/ui/pages/click-to-load" deleterow "github.com/gofs-cli/template/internal/ui/pages/delete-row" @@ -56,6 +57,10 @@ func (s *Server) Routes() { routesMux.Handle("GET /active-search", activesearch.Index()) routesMux.Handle("POST /active-search/search", activesearch.Search()) + // cascading select example + routesMux.Handle("GET /cascading-select", cascadingselect.Index()) + routesMux.Handle("GET /cascading-select/models", cascadingselect.Models()) + routesMux.Handle("GET /modal", home.Modal()) routesMux.Handle("GET /page1", page1.Index()) From 632b1bba89f6961b443bfdda85e1786ad16bb098 Mon Sep 17 00:00:00 2001 From: luke-dcz Date: Wed, 5 Feb 2025 12:12:10 +0000 Subject: [PATCH 2/4] create handlers --- .../ui/pages/cascading-select/handlers.go | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 internal/ui/pages/cascading-select/handlers.go diff --git a/internal/ui/pages/cascading-select/handlers.go b/internal/ui/pages/cascading-select/handlers.go new file mode 100644 index 0000000..8129e55 --- /dev/null +++ b/internal/ui/pages/cascading-select/handlers.go @@ -0,0 +1,22 @@ +package cascadingselect + +import ( + "net/http" + + "github.com/a-h/templ" + "github.com/gofs-cli/template/internal/ui" + "github.com/gofs-cli/template/internal/ui/components/header" +) + +func Index() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + templ.Handler(ui.IndexPage(layout(header.Header(), body()))).ServeHTTP(w, r) + }) +} + +func Models() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + make := r.URL.Query().Get("make") + templ.Handler(modelOptions(make)).ServeHTTP(w, r) + }) +} From 7f3dd38af87c97f2dc37852f121165036e729e31 Mon Sep 17 00:00:00 2001 From: luke-dcz Date: Wed, 5 Feb 2025 12:12:27 +0000 Subject: [PATCH 3/4] create templ cascading select --- .../ui/pages/cascading-select/index.templ | 54 ++++++ .../ui/pages/cascading-select/index_templ.go | 155 ++++++++++++++++++ 2 files changed, 209 insertions(+) create mode 100644 internal/ui/pages/cascading-select/index.templ create mode 100644 internal/ui/pages/cascading-select/index_templ.go diff --git a/internal/ui/pages/cascading-select/index.templ b/internal/ui/pages/cascading-select/index.templ new file mode 100644 index 0000000..778e0ad --- /dev/null +++ b/internal/ui/pages/cascading-select/index.templ @@ -0,0 +1,54 @@ +package cascadingselect + +css classLayout() { + display: grid; +} + +templ layout(header, body templ.Component) { +
+
+ @header +
+
+ @body +
+
+} + +templ body() { +

Cascading Select:

+
+ + +
+
+ + + +
+} + +templ modelOptions(make string) { + switch make { + case "audi": + + + + case "bmw": + + + + case "toyota": + + + + } +} diff --git a/internal/ui/pages/cascading-select/index_templ.go b/internal/ui/pages/cascading-select/index_templ.go new file mode 100644 index 0000000..a954aac --- /dev/null +++ b/internal/ui/pages/cascading-select/index_templ.go @@ -0,0 +1,155 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.3.819 +package cascadingselect + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import templruntime "github.com/a-h/templ/runtime" + +func classLayout() templ.CSSClass { + templ_7745c5c3_CSSBuilder := templruntime.GetBuilder() + templ_7745c5c3_CSSBuilder.WriteString(`display:grid;`) + templ_7745c5c3_CSSID := templ.CSSID(`classLayout`, templ_7745c5c3_CSSBuilder.String()) + return templ.ComponentCSSClass{ + ID: templ_7745c5c3_CSSID, + Class: templ.SafeCSS(`.` + templ_7745c5c3_CSSID + `{` + templ_7745c5c3_CSSBuilder.String() + `}`), + } +} + +func layout(header, body templ.Component) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + var templ_7745c5c3_Var2 = []any{classLayout()} + templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var2...) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = header.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = body.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func body() templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var4 := templ.GetChildren(ctx) + if templ_7745c5c3_Var4 == nil { + templ_7745c5c3_Var4 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "

Cascading Select:

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func modelOptions(make string) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var5 := templ.GetChildren(ctx) + if templ_7745c5c3_Var5 == nil { + templ_7745c5c3_Var5 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + switch make { + case "audi": + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + case "bmw": + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + case "toyota": + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) +} + +var _ = templruntime.GeneratedTemplate From 8fdc3a3698973ef3f2a77e87d35cbb9d7793551a Mon Sep 17 00:00:00 2001 From: luke-dcz Date: Wed, 5 Feb 2025 12:12:37 +0000 Subject: [PATCH 4/4] change route to cascading select page --- internal/ui/pages/home/index.templ | 2 +- internal/ui/pages/home/index_templ.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/ui/pages/home/index.templ b/internal/ui/pages/home/index.templ index 7ede121..0628c21 100644 --- a/internal/ui/pages/home/index.templ +++ b/internal/ui/pages/home/index.templ @@ -57,7 +57,7 @@ templ body() { Progress Bar
  • - Value Select + Value Select
  • Animations diff --git a/internal/ui/pages/home/index_templ.go b/internal/ui/pages/home/index_templ.go index 00a2af3..0b1c66b 100644 --- a/internal/ui/pages/home/index_templ.go +++ b/internal/ui/pages/home/index_templ.go @@ -112,7 +112,7 @@ func body() templ.Component { templ_7745c5c3_Var4 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "Welcome to the sample application! This application demonstrates how to use htmx with Go. The following examples are based on the htmx examples: https://htmx.org/examples/

    Home

    Demo: Toast

    ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "Welcome to the sample application! This application demonstrates how to use htmx with Go. The following examples are based on the htmx examples: https://htmx.org/examples/

    Home

    Demo: Toast

    ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }