Sebb
Utility classes are 2022 - now we have utility elements
is this too evil? ![]()
<.flex gap-4 justify-start>
...
</.flex>
<.grid grid-cols-3 gap-3>
...
</.grid>
defmodule Components.Tailwind do
use Phoenix.Component
import Phoenix.LiveView.HTMLEngine, only: [component: 3]
def flex(assigns), do: component(&div/1, classes(assigns, "flex"), [])
def grid(assigns), do: component(&div/1, classes(assigns, "grid"), [])
...
defp div(assigns) do
~H"""
<div class={@classes}>
<%= render_slot(@inner_block) %>
</div>
"""
end
defp classes(assigns, base) do
classes =
assigns
|> Enum.reject(fn {k, v} -> k == :__changed__ || v != true end)
|> Enum.map(fn {k, _} -> k end)
|> Enum.join(" ")
assign_new(assigns, :classes, fn -> base <> " " <> classes end)
end
end
Most Liked
LostKobrakai
I’d suggest taking a step back and ask yourself if changing the syntax for how to apply css is actually useful. In my opinion there’s not much use in that. I’d rather look into actual higher levels of abstraction, like e.g. presented on https://every-layout.dev/.
Also I’d worry there’s pitfalls for LVs change tracking with the approach you’re taking there.
BartOtten
LostKobrakai
import Phoenix.LiveView.HTMLEngine, only: [component: 3]
Maybe not for change tracking, but afaik using this essentially means the LV has no means of splitting the static content of a template from the dynamic parts, which is used to optimize diffs by not sending the static parts again.
Last Post!
LostKobrakai
Thinking about this some more I might actually be wrong here. This static vs dynamic part is likely done at runtime, where using the a dynamic component wouldn’t really be different to a compile time known one.
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









