PaulBickford

PaulBickford

I am having trouble with my Phoenix/LiveView/Tailwind app not displaying correctly. The proper Tailwind classes are being created, but not all of them are being turned into CSS classes. I created a demo app below to illustrate the problem.

The Tailwind labels

absolute
top-0 (8, 16, 24, 32, 40)
left-0 (8, 16, 24, 32, 40)
bg-red-500 (yellow)
h-8
w-8
pt-px
pl-px

are all being created in the HTML, but the CSS classes do not include

top-x
left-x

Any idea on why the correct CSS is not being generated for all Tailwind classes?

TWTest demo app

Erlang 24.3.1 and Elixir 1.13.3-otp-24.

$ mix phx.new tw_test --no-ecto --no-mailer

mix.exs, deps:

{:tailwind, "~> 0.1", runtime: Mix.env() == :dev}

config.exs, add:

config :tailwind,
  version: "3.0.10",
  default: [
  args: ~w(
  --config=tailwind.config.js
  --input=css/app.css
  --output=../priv/static/assets/app.css
  ),
  cd: Path.expand("../assets", __DIR__)
  ]
$ mix deps.get
$ mix tailwind.install
$ mix tailwind default

dev.exs, watchers:

tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}

mix.exs, aliases add:

"assets.deploy": ["tailwind default --minify", ...]

router.ex, change route to:

    live "/", Demo

Add demo.ex:

defmodule TwTestWeb.Demo do
  use TwTestWeb, :live_view

  def render(assigns) do
    ~H"""
    <h1>Tailwind Test</h1>

    <div class={"relative w-screen h-80 bg-teal-50"}>
    <%= for i <- 0..4 do %>
      <.box
        style="bg-red-500"
        x={assigns.nodes[i].x}
        y={assigns.nodes[i].y}
      />
      <.box
        style="bg-yellow-500"
        x={assigns.nodes[i].y}
        y={assigns.nodes[i].x}
      />
    <% end %>
    </div>
    """
  end

  def mount(_params, _session, socket) do
    nodes =
      Map.new(0..4, &{&1, %{x: 4 - &1, y: &1}})
      |> IO.inspect()

    {:ok, assign(socket, nodes: nodes)}
  end

  def box(assigns) do
    ~H"""
        <div
      class={
        "absolute top-#{8 * assigns.y} left-#{8 * assigns.x} #{assigns.style} h-8 w-8 pt-px pl-px"
      }
    >
    </div>
    """
  end
end

Showing Posts 1 to 2

stefanchrobot

stefanchrobot

This is because you’re computing the classes dynamically - Tailwind purges the top-8, top-16 etc. classes since it doesn’t “see” them being used.

One way to fix this would be to list them explicitly in a comment:

def box(assigns) do
    ~H"""
    <!-- top-8 top-16 ... ->
    """
karlosmid

karlosmid

Hi!

Or you could put all possible computed CSS classes in tailwind.config.js exclude list.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews