From 599b54f2bec12338f9a1b640732f00415ed6c9f3 Mon Sep 17 00:00:00 2001 From: Joe Davidson Date: Sat, 1 Jun 2024 21:07:53 +0100 Subject: [PATCH] feat: support []CSSClass in class expression (#768) --- runtime.go | 8 ++++++++ runtime_test.go | 1 + 2 files changed, 9 insertions(+) diff --git a/runtime.go b/runtime.go index 1a18e9041..9f6df504d 100644 --- a/runtime.go +++ b/runtime.go @@ -233,6 +233,10 @@ func (cp *cssProcessor) Add(item any) { for _, item := range c { cp.Add(item) } + case []CSSClass: + for _, item := range c { + cp.Add(item) + } case func() CSSClass: cp.AddClassName(c().ClassName(), true) default: @@ -438,6 +442,10 @@ func renderCSSItemsToBuilder(sb *strings.Builder, v *contextValue, classes ...an renderCSSItemsToBuilder(sb, v, ccc.Key) case CSSClasses: renderCSSItemsToBuilder(sb, v, ccc...) + case []CSSClass: + for _, item := range ccc { + renderCSSItemsToBuilder(sb, v, item) + } case func() CSSClass: renderCSSItemsToBuilder(sb, v, ccc()) case []string: diff --git a/runtime_test.go b/runtime_test.go index d481acf1b..8fcd1f8a4 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -145,6 +145,7 @@ var cssInputs = []any{ func() templ.CSSClass { return templ.ConstantCSSClass("l") }, // func() CSSClass templ.CSSClass(templ.ConstantCSSClass("m")), // CSSClass customClass{name: "n"}, // CSSClass + []templ.CSSClass{customClass{name: "n"}}, // []CSSClass templ.KV[templ.ConstantCSSClass, bool](templ.ConstantCSSClass("o"), true), // KeyValue[ConstantCSSClass, bool] []templ.KeyValue[templ.ConstantCSSClass, bool]{ templ.KV(templ.ConstantCSSClass("p"), true),