Sebb

Sebb

Utility classes are 2022 - now we have utility elements

is this too evil? :sunglasses:

<.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

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

BartOtten

Please also create SubSubSubSubHeader :slight_smile:

Evil or not; it looks in the spirit of Tailwind :slight_smile:

LostKobrakai

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

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.

Where Next?

Popular in Discussions Top

New
scouten
I’m looking for a host for the server part of a small (personal) side project that I’m working on. It’s currently written in Node.js and ...
New
AstonJ
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them? Feel free to be as concise or in-depth as you li...
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
chuck
Let me start by stating an assumption: Phoenix is a great approach to building REST APIs. There are many reasons for this, but I will ass...
New
Rustixir
Hi everyone, im working on find best language/framework/system for high concurrency, high performance and stable performance after wor...
New
crispinb
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement