Feature request: `exclude` for global attributes
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).
What i do is try to avoid adding the global attribute at all. But there are two options i'd like to have:
- an attribute which allows you to define include only, and when you provide anything else it errors out.
- what you propose add an
excludeoption
I think I have a very strong case for this. I want to ban title attribute, because I have implemented floating tooltips. Native tooltips conflict with them (both will be shown together when provided). Right now the only option is to re-implement :global which is just sad.