remove ternary
This commit is contained in:
parent
8c9b5e7b24
commit
8562f9e85e
4 changed files with 6 additions and 8 deletions
|
|
@ -129,7 +129,7 @@ func Hidden() Ren {
|
||||||
return Attribute("style", "display:none")
|
return Attribute("style", "display:none")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Class(value ...string) Ren {
|
func Class(value ...string) *AttributeMap {
|
||||||
return Attribute("class", MergeClasses(value...))
|
return Attribute("class", MergeClasses(value...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,10 @@ func If(condition bool, node Ren) Ren {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Ternary[T any](value bool, a T, b T) T {
|
func Ternary[T any](value bool, a T, b T) T {
|
||||||
if value {
|
return IfElse(value, a, b)
|
||||||
return a
|
|
||||||
}
|
|
||||||
return b
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func IfElse(condition bool, node Ren, node2 Ren) Ren {
|
func IfElse[T any](condition bool, node T, node2 T) T {
|
||||||
if condition {
|
if condition {
|
||||||
return node
|
return node
|
||||||
} else {
|
} 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 {
|
if condition {
|
||||||
return cb1()
|
return cb1()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -161,6 +161,7 @@ func ToggleClassOnElement(selector, class string) ComplexJsCommand {
|
||||||
return EvalJs(fmt.Sprintf(`
|
return EvalJs(fmt.Sprintf(`
|
||||||
var el = document.querySelector('%s');
|
var el = document.querySelector('%s');
|
||||||
if(el) { el.classList.toggle('%s'); }`,
|
if(el) { el.classList.toggle('%s'); }`,
|
||||||
|
selector, class,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ func TestRawContent(t *testing.T) {
|
||||||
func TestConditional(t *testing.T) {
|
func TestConditional(t *testing.T) {
|
||||||
result := Render(
|
result := Render(
|
||||||
Div(
|
Div(
|
||||||
IfElse(true, Text("true"), Text("false")),
|
Ternary(true, Text("true"), Text("false")),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
assert.Equal(t, "<div >true</div>", result)
|
assert.Equal(t, "<div >true</div>", result)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue