remove ternary

This commit is contained in:
maddalax 2024-09-22 11:25:18 -05:00
parent 8c9b5e7b24
commit 8562f9e85e
4 changed files with 6 additions and 8 deletions

View file

@ -129,7 +129,7 @@ func Hidden() Ren {
return Attribute("style", "display:none")
}
func Class(value ...string) Ren {
func Class(value ...string) *AttributeMap {
return Attribute("class", MergeClasses(value...))
}

View file

@ -9,13 +9,10 @@ func If(condition bool, node Ren) Ren {
}
func Ternary[T any](value bool, a T, b T) T {
if value {
return a
}
return b
return IfElse(value, a, b)
}
func IfElse(condition bool, node Ren, node2 Ren) Ren {
func IfElse[T any](condition bool, node T, node2 T) T {
if condition {
return node
} else {
@ -23,7 +20,7 @@ func IfElse(condition bool, node Ren, node2 Ren) Ren {
}
}
func IfElseLazy(condition bool, cb1 func() Ren, cb2 func() Ren) Ren {
func IfElseLazy[T any](condition bool, cb1 func() T, cb2 func() T) T {
if condition {
return cb1()
} else {

View file

@ -161,6 +161,7 @@ func ToggleClassOnElement(selector, class string) ComplexJsCommand {
return EvalJs(fmt.Sprintf(`
var el = document.querySelector('%s');
if(el) { el.classList.toggle('%s'); }`,
selector, class,
))
}

View file

@ -43,7 +43,7 @@ func TestRawContent(t *testing.T) {
func TestConditional(t *testing.T) {
result := Render(
Div(
IfElse(true, Text("true"), Text("false")),
Ternary(true, Text("true"), Text("false")),
),
)
assert.Equal(t, "<div >true</div>", result)