Last active
July 27, 2022 21:56
-
-
Save toranb/1ab7e4cce9f2e5fb79abe93f3d62bd28 to your computer and use it in GitHub Desktop.
inline conditional css comparison of leex and heex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### phx live view 0.16 with leex | |
def render(assigns) do | |
~L""" | |
<button class="<%= if @foo && @bar && @baz do %>text-blue-600<% else %>text-red-600<% end %>">hello</button> | |
""" | |
end | |
##### phx live view 0.16 with heex -inline edition | |
def render(assigns) do | |
~H""" | |
<button class={"#{if @foo && @bar && @baz, do: "text-blue-600", else: "text-red-600"}"}>hello</button> | |
""" | |
end | |
##### phx live view 0.16 with heex -verbose edition | |
def render(assigns) do | |
~H""" | |
<button class={"#{css_apply(&some_func/3, [@foo, @bar, @baz], "text-blue-600", "text-red-600")}"}>hello</button> | |
""" | |
end | |
def some_func(foo, bar, baz) do | |
if foo && bar && baz, do: true, else: false | |
end | |
def css_apply(func, args, result, else_result \\ "") do | |
if apply(func, args) do | |
result | |
else | |
else_result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment