-
Notifications
You must be signed in to change notification settings - Fork 519
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
Proposal: make gray-*
properly themable
#2026
Comments
gray-*
_properly_ themablegray-*
properly themable
@davestewart I read your issue quickly before leaving for vacation, I understand your point and before you start working on this I just want to say that I'm not sure it's a good idea to make such a refactor while |
Thanks for taking the time to read it, and I understand your position. So you know when the next version will be released? Will we need able to theme the "gray" component? Maybe this will give you some ideas, at the very least! Also, bonne vacances! |
Have you checked https://github.com/benjamincanac/ui3? |
Not for a while, only for some UI prop related stuff. You're developing this in isolation of the current version? |
It's a fork, it's |
To answer your previous question, for now it's quite basic and mimic the behaviour of the current version for the colors. The only difference is its config in |
Here are some additional informations about the v3 progress: #1289 (comment) |
I see. Ok, well, we can survive without this proposal, but in the meantime I'll check out the new repo. I'm sure it's 👌👌👌. Cheers, |
Description
Abstract
Right now, the
gray-*
CSS classes are reserved by Nuxt UI for borders, backgrounds, etc.Unfortunately, due to how the theming works, the
gray
name cannot be changed, so developers have to use a word other thangray
to reference real grays (asgray
now effectively identifies "Nuxt UI's secondary color") such ascool
:My understanding is that this isn't going to change – I presume because it would be a breaking change for those already relying on
gray-*
in their apps.Problem
Our existing Figma design system is based on borders and backgrounds using Tailwind's
neutral
color, so using Nuxt UI we're in a kind of "hybrid" situation where:neutral
color variablesneutral
for Nuxt UI's themegray-*
classes (pointing atneutral
variable values)gray
elsewhere we need to use an alias, such ascool
,slate
, or currently a prefixedfgd-gray
Whilst I understand the decisions which got Nuxt UI here, and the problems that changing the naming convention would bring, I've been looking fairly deeply at the config and component code, and looking to see if there might be a way to give everyone what they want.
Proposal
Theming recap
As I understand it, Nuxt UI is styled is through
ui.config
files, and themed via{color}
placeholders.Several strategies combine to achieve the final HTML/CSS colorised output:
color
prop defaults to a merge of the componentapp.config
andui.config
objectsui
props, the placeholder{color}
is swapped out with thecolor
propExpanding theming to better-support gray
So my conjecture is that:
{placeholder}
mechanism for the "gray" part of the theme (rather than onlygray
)primary
andgray
colors / classes{color}
and{gray}
in componentsI have done some initial prototyping, and it seems the theory is sound. It adds only a modest amount of safe-listed values (which in all likelihood would be created anyway) whilst removing the restrictions on what class names can be used.
The outcome is that Nuxt UI's component rendered markup would actually point to the Tailwind gray-color it is supposed to, leaving the user to use the actual "gray" class, without worrying that the "theme gray" class (
i.e. neutral
) would be different, without having to do the mental or physical gymnastics:Initial prototyping
I've experimented with the following code, with mainly good results.
Adding
{gray}
placeholders toui.config/
Whilst I did this to make the
RegExp
replacements easier, I was surprised to see that when I imported theui.config
files, the{color}
placeholders were already replaced with the configuredprimary
value.Clearly I don't understand the lifecycle of the module; perhaps you can connect the dots for me?
Making
safelistByComponent()
programmaticI needed to test my idea was sound, so rather than manually add new options to
safelistByComponent()
I instead imported theui.config
objects and walked them to find all classes, then parsed and processed them to build the a unique set of Tailwind safelist configs.This seem to work great!
As such, I was wondering why this wasn't done in the first place. I assume I'm missing something?
Improving
ui.prop
color replacementRather than replacing
ui
props on an individual level, I added a single helper would replace color and gray placeholders:Again, this seems to work just fine.
Summing up
So, as mentioned, this is a kind of issue / proposal / sanity-check before doing any more work in this direction.
Maybe there are some fundamental issues that I haven't appreciated?
But my feeling is that we can make it work without impacting current users (perhaps even behind an
experimental
flag, like Nuxt Content, or such like). It would be really useful for us, and to others.Some related tickets:
primary
/gray
as main colors might conflict with existing projects. #1721I'll be here to answer questions or follow up if I've overlooked things.
All the best,
Dave
Additional context
I can push a new branch to my Nuxt UI repo without a PR if you like, then you could review the changes there.
The text was updated successfully, but these errors were encountered: