Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: exclude for global attributes #2590

Open
ssbb opened this issue Apr 14, 2023 · 1 comment
Open

Feature request: exclude for global attributes #2590

ssbb opened this issue Apr 14, 2023 · 1 comment

Comments

@ssbb
Copy link

ssbb commented Apr 14, 2023

Hello there

I think it would be cool to add some kind of exclude for global attributes.

Eg with default button component:

<button
  type={@type}
  class={[
    "phx-submit-loading:opacity-75 rounded-lg bg-zinc-900 hover:bg-zinc-700 py-2 px-3",
    "text-sm font-semibold leading-6 text-white active:text-white/80",
    @class
  ]}
  {@rest}
>
  <%= render_slot(@inner_block) %>
</button>

If I need a button with text-lg and different spacing - I am in trouble. I can just pass text-lg to class and maybe it will actually work sometimes but sometimes it won't (default css priority comes from order of rule definitions which hard to guess in case of TW). Also I can do !text-lg but I need to know in advance that I need override it (so I should keep in head that in case of button component I can use something like margin as is but font-size with important flag only).

So basically in my workflow I am trying to keep my re-usable components to be configured via attributes only. For things like margins I just wrap component with div (or maybe will add spacing attribute in future).

Because of this I would like to have something like

attr :rest, :global, exclude: ~w(class)

Currently I can get something similar with unused class attribute but I would like to have compile-time checks:

attr :class, :string

def button(assigns) do
  if assigns[:class] do
    Logger.warn("You should configure button component with attributes instead, class attr ignored.")
  end
  
  ...
end

How people normally manage this issue with Tailwind (just in case there is some better workflow and I missing it).

@Neophen
Copy link
Contributor

Neophen commented Jun 14, 2023

What i do is try to avoid adding the global attribute at all.
But there are two options i'd like to have:

  1. an attribute which allows you to define include only, and when you provide anything else it errors out.
  2. what you propose add an exclude option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants