-
Notifications
You must be signed in to change notification settings - Fork 515
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
feat(module): reuse existing primary
and gray
colors
#2009
Conversation
@benjamincanac β right now, Nuxt UI renames any I wanted to check though, in case I missing some hidden situations? As such, I think the CSS Variables section of the theming docs could be simplified. I propose:
What do you think? |
primary
and gray
colors
* dev: fix(module): handle nested colors from ui config (nuxt#2008)
@davestewart Do you think it would be a breaking change to remove the I 100% agree with your proposal about the docs, will review in other PR π |
I was hoping you would know!!! Or at least, be more familiar with the logic / situations. I guess it would be simple to check in the playground, or even spin up a dummy project. |
Honestly, it kind of depends if we can achieve the same thing on |
OK, I think we're good! I have left in the default to SetupI tested undefined
'slate'
'gray' // no tw config
'gray' // custom tw config I used the following playground code: <template>
<UContainer class="min-h-screen max-w-sm !mx-auto flex flex-col justify-center content-center gap-8 m-8">
<UCard>
<template #header>
Gray
</template>
<p class="p-2 leading-none
text-gray-900 hover:text-gray-900
bg-gray-600 hover:bg-gray-500
">bg-gray-600 (themed as {{ ui.gray }})</p>
<p class="p-2 leading-none
text-slate-900 hover:text-slate-900
bg-slate-600 hover:bg-slate-500
">bg-slate-600</p>
<p class="p-2 leading-none
text-cool-900 hover:text-cool-900
bg-cool-600 hover:bg-cool-500
">bg-cool-600</p>
</UCard>
</UContainer>
</template>
<script setup>
const ui = useAppConfig().ui
</script> I (optionally) used the following gray config (just so it is obvious): gray: {
'50': '#edfffc',
'100': '#c0fff9',
'200': '#81fff4',
'300': '#3affef',
'400': '#00ffe1',
'500': '#00e2c9',
'600': '#00b7a6',
'700': '#009185',
'800': '#00726b',
'900': '#045d58',
'950': '#003a39',
}, ResultsI got the following results:
ConclusionSo I think that means: Primary:
Gray:
It also seems to mean that you could change the default As I understand it, the only reason to leave it would be if it confused some people if it was changed, but AFAIK |
@davestewart I'll review and merge your PRs tomorrow after a patch release including #2008 π |
Enjoy the rest of your weekend π |
src/runtime/utils/colors.ts
Outdated
return excludeColors(globalColors) | ||
return [ | ||
...excludeColors(globalColors), | ||
...Object.keys(userColors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not export $gray
or $primary
here, otherwise it gets exported from #ui-colors
(https://github.com/nuxt/ui/blob/dev/src/templates.ts#L4) and will be prompted to users in color
prop: https://github.com/nuxt/ui/blob/dev/src/runtime/types/button.d.ts#L8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Taking a look now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure of the best way to handle this, or sufficiently confident I understand some of the subtleties of the code.
A simple option might be to filter the keys in the template creation function, but I am wondering if perhaps I misunderstood the role of setGlobalColors()
and perhaps the theme
object should not be augmented here.
If that was the case, then maybe in src/tailwind.ts
we should detect and add primary
and gray
to nuxt.options.appConfig.ui.themeColors
and refactor how plugins/colors.ts
determines where to pull the colors from, referencing ui.themeColors
instead.
I'll try this second option now, but if you want to offer any advice, I'm happy to hear it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing, looking at the interface for app config, that perhaps app config is the wrong place to temporarily save these colors.
The challenge is caching primary
and gray
somewhere so they can be accessed in plugins/colors.ts
as by this point they will have been overwritten in the theme.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, think I have it using runtimeConfig
.
It's a bit late now, but I'll submit a revised PR tomorrow.
Good morning @benjamincanac βοΈ I've moved the logic of separating user vs global colors from I have some Nuxt module experience, but usually just what I need to learn to get the job done; perhaps you can let me know if that is the right place. |
Just checking in Benjamin. Hope your holiday was good. |
Hey @davestewart, it was good thank you :) I'm still not sure what to do about this regarding the future compatibility with However, what do you think of merging #2010 and #2014 first? I think only a few changes needs to be done in #2010. |
Morning!
I understand your concerns about going back. Remember, the core idea is you can use any theme color names you like, without having to work around reserved names. If the implementation is transparent, should it not be possible in either version? The code in this version isn't particularly complex, it's just thinking about the problem slightly differently.
Sure! Let me take a look at see if what I wrote still works.
Once #2010 is merged, I can update the docs Haven't looked at this stuff for six weeks or so, so need to re-familiarise myself :) |
@davestewart I'm thinking of closing this and keep it as-is for |
Hey @benjamincanac, sure, I get it. It looks like a lot of thought has gone into your new system. I'm away right now so will just say do what you gotta do! |
π Linked issue
Resolves #1721
β Type of change
π Description
Right now, the color names
primary
andgray
are reserved by Nuxt UI so it can build alpha-ready versions of the primary colors used in the individual components.The problem with this is that it overwrites existing colors, and means users can't use the name "primary" in their themes (and possibly design-systems if using codegens).
This PR attempts to fix this by first detecting if the user has used a key called
primary
(andgray
) and then copies these values to$primary
(and$gray
) aliases.The existing machinery then checks if the user's
ui
config points toprimary
andgray
, then in the Nuxt plugin property, points towards the aliased / backed-up values instead, to generate the CSS variables.I've checked it out in the playground and it seems to work well, but suggest a check on site in the wild!
I can do this with our current site.
Also, looking at any docs updates now.
π Checklist