Skip to content

Commit

Permalink
feat: support []CSSClass in class expression (#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
joerdav authored Jun 1, 2024
1 parent 2dafa71 commit 599b54f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 599b54f

Please sign in to comment.