cblavier

cblavier

Hi there :waving_hand:

I’m the author of phx_component_helpers and I have a recurring complaint of users regarding the CSS extension feature. I’m struggling to find a solution to this issue. :exploding_head:

The purpose of this feature is to build components with default CSS classes and extend its classes when using the component. For instance a component can have following default style: border border-gray-400 bg-red :red_circle: If I use it and extend its style with bg-blue the resulting CSS will be border border-gray bg-blue :blue_circle:

We actually replace all classes from default styling having the same prefix (everything before first hyphen). It’s kinda working for a lot of cases but if you want to extend border border-2 border-orange-500 with border-red-500 it will be a little too greedy and replace all border classes resulting in border-red-500 instead of border border-2 border-red-500.

The code is right there: phx_component_helpers/lib/phx_component_helpers/css.ex at main · cblavier/phx_component_helpers · GitHub

Another case completely defeating my prefix base approach is when you use multiple Tailwind classes that deal with the same CSS properties but do not share any common prefix. For instance you may want to extend a component using block (in CSS it’s display: block;) with flex (in CSS it’s display: flex;)

It looks like I might need some specific Tailwind related code dealing with Tailwind semantics. Do you know where I could find some JSON (or so) metadata regarding the whole Tailwind CSS class hierarchy?

Any other idea?

:folded_hands:

Showing Posts 1 to 4

cmo

cmo

My instinct would be not to do that sort of thing at all. Sounds like a lot of work for something that will be confusing and/or brittle.

cblavier

cblavier OP

Sounds wise indeed! :owl:
Let’s see what other folks might think of this feature :thinking:

Eiji

Eiji

I will support something like:

<MyComponents.component cmp-color="red-500"/>
# and then
color = assigns["cmp-color"] || "orange-500"
~H"""
<span class={"border border-2 border-#{color}"}>
  …
</span>
"""

plus some extras like:

# override class
<MyComponents.component class="btn btn-primary"/>

# merge base classes with theme classes
# default_comp_classes = ["border"]
<MyComponents.component theme-classes={~w[border-2 border-red-500]}/>

# or merge base classes + theme classes with extra classes
# default_comp_classes = ["border border-2 orange-red-500"]
<MyComponents.component classes={["color-red-500"]}/>
cblavier

cblavier OP

One of a my teammates just had an idea I found clever and not too brittle (ping @cmo): extend component CSS classes with explicit class removal or additions.

A button component with following default CSS: block border border-2 border-gray-500 would be used like this:

<.button class="!block flex !border-gray-* border-blue-300"/>

The ! is used to remove classes.
So the previous example would produce flex border border-2 border-blue-300.

— 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
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
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
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews