-
Notifications
You must be signed in to change notification settings - Fork 620
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
Tailwind colors with CSS variables results in broken primary/gray palette #1986
Comments
What is it you're trying to achieve? This is exactly what the primary color is for already:
|
Sorry if I wasn't very clear :) Let’s say I have a color palette that is dynamic and I need to fetch it from my backend. I want to use this palette as NuxtUI's primary color and also for other stylings in my app. I guess I could simply work with the tailwind primary color generated by NuxtUI, and override the values of the CSS variables in the root after having fetched the palette, like so: const palette = await fetchPaletteFromBackend() // { 50: '240 253 253', 100: '191 239 242', ...}
// Some formatting
const rootVariables = Object.entries(palette).reduce((acc, [key, value]) => {
return acc + `--color-primary-${key}: ${value};`
}, '')
// Override the root
useHead({ style: `:root {${rootVariables}}` }) This works just fine, but I see a few catches here:
![]() For all these reasons, it would feel cleaner to me if I could use a tailwind color palette that is written using CSS variables as NuxtUI's primary color. Please let me know if I'm missing some other obvious way to achieve this. I'm still new to Nuxt, I might just be embarrassing myself here 🌝 Also, the above is just an example, and there is already an open issue regarding this precise use case. But there might be some other cases where I would need to use CSS variables with tailwind, e.g., if I want to use something like Radix colors and need to change the value of a color depending if I'm in light or dark mode. The real question is: how should NuxtUI handle the case where a palette generated using CSS variables is used as the primary or gray color? If we the answer is "use HEX codes only", then it might be worth raising an error in the |
This issue is stale because it has been open for 30 days with no activity. |
I just got here, because my primary & gray colors are empty, too. tailwind config: import type { Config } from 'tailwindcss'
export default <Partial<Config>>{
theme: {
fontFamily: {
sans: ['Outfit', 'sans-serif', 'ui-sans-serif', 'system-ui'],
primary: ['Outfit', 'sans-serif'],
},
extend: {
colors: {
gray: {
50: '#949698',
100: '#7e8083',
200: '#696b6f',
300: '#53565a',
400: '#3e4146',
DEFAULT: '#282C31',
500: '#282C31',
600: '#24282c',
700: '#202327',
800: '#1c1f22',
900: '#181a1d',
950: '#141619',
},
blue: {
50: '#728598',
100: '#728598',
300: '#5e7389',
400: '#4a627b',
DEFAULT: '#36506C',
500: '#36506C',
600: '#314861',
700: '#2b4056',
800: '#203041',
900: '#1b2836',
950: '#16202b',
},
}
}
}
} |
@develth This is the normal behavior, Nuxt UI uses a It's normal for them to not show up in the Tailwind CSS preview as the variable doesn't exist there You can read more about this on https://ui.nuxt.com/getting-started/theming |
thanks for explanation @benjamincanac - got it & it worked. |
Environment
Version
v2.17.0
Reproduction
https://stackblitz.com/edit/nuxt-ui-keperh
Description
When using CSS variables with tailwind, NuxtUI fails to generate the corresponding primary or gray color palette.
For example (see reproduction for more details):
In the main CSS file:
In
app.config.ts
:And the resulting styles injected in the root is:
Additional context
This, I believe, is due to the
colors
plugin which expects the tailwind config to contain HEX codes only, and attempts to convert them to RGB data using thehexToRgb
utility function. I'll submit a PR soon to attempt to fix this.Logs
No response
The text was updated successfully, but these errors were encountered: