From d2887f5e6a5670aaf105dfe51cb810982c3984fa Mon Sep 17 00:00:00 2001 From: joerdav Date: Fri, 31 May 2024 10:03:56 +0100 Subject: [PATCH] feat: support []CSSClass in class expression --- 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),