diff --git a/README.md b/README.md index 569305f..9725a65 100644 --- a/README.md +++ b/README.md @@ -69,9 +69,9 @@ ulElement := elem.Ul(nil, liElements) ``` In this example, we transformed a slice of strings into a list of `li` elements and then wrapped them in a `ul` element. -### Conditional Rendering with Show +### Conditional Rendering with `If` -`elem` provides a utility function `Show` for conditional rendering of elements. +`elem` provides a utility function `If` for conditional rendering of elements. ```go isAdmin := true @@ -80,7 +80,7 @@ guestLink := elem.A(elem.Attrs{attrs.Href: "/login"}, elem.Text("Login")) content := elem.Div(nil, elem.H1(nil, elem.Text("Dashboard")), - elem.Show(isAdmin, adminLink, guestLink), + elem.If(isAdmin, adminLink, guestLink), ) ``` diff --git a/utils.go b/utils.go index 183b0e7..771bffc 100644 --- a/utils.go +++ b/utils.go @@ -31,7 +31,7 @@ func ApplyStyle(s Style) string { } // Show conditionally renders one of the provided elements based on the condition -func Show(condition bool, ifTrue, ifFalse Node) Node { +func If[T any](condition bool, ifTrue, ifFalse T) T { if condition { return ifTrue } diff --git a/utils_test.go b/utils_test.go index ff7a2f5..001913d 100644 --- a/utils_test.go +++ b/utils_test.go @@ -29,14 +29,14 @@ func TestApplyStyle(t *testing.T) { assert.Equal(t, expected, actual) } -func TestShow(t *testing.T) { +func TestIf(t *testing.T) { trueElement := Div(nil, Text("True Condition")) falseElement := Div(nil, Text("False Condition")) - resultTrue := Show(true, trueElement, falseElement) + resultTrue := If(true, trueElement, falseElement) assert.Equal(t, trueElement.Render(), resultTrue.Render()) - resultFalse := Show(false, trueElement, falseElement) + resultFalse := If(false, trueElement, falseElement) assert.Equal(t, falseElement.Render(), resultFalse.Render()) }