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

Add theme colors as tailwind variables #2948

Open
jeannen opened this issue Dec 22, 2024 · 4 comments · May be fixed by #2967
Open

Add theme colors as tailwind variables #2948

jeannen opened this issue Dec 22, 2024 · 4 comments · May be fixed by #2967
Labels
enhancement New feature or request v3 #1289

Comments

@jeannen
Copy link

jeannen commented Dec 22, 2024

Description

Hey!

It would be nice to have the primary/secondary/neutral/etc colours defined in app.config.ts directly as tailwind variables (ex: text-primary-500)

Right now we have to define the colours both in app.config.ts and tailwind.config.js to be able to do that. (the new main.css would require to create a variable for each sub-colour manually so not worth using it)

For neutral, since it's a tailwind colour, it could be named text-neutr-500
Or maybe name all colours with something like text-Uneutral-500

Additional context

No response

@jeannen jeannen added enhancement New feature or request triage v3 #1289 labels Dec 22, 2024
Copy link
Member

It is disabled by default to not override the user's theme, you might have an error color already in your theme. However, you can add them pretty easily: https://ui3.nuxt.dev/getting-started/theme#colors
CleanShot 2024-12-22 at 16.30.01@2x.png

@jeannen
Copy link
Author

jeannen commented Dec 23, 2024

Yes, would be nice to have an option for that without manually writing the whole variables for each color and variant (77 in total)

That way, it's easy to switch a colour from the config and have it change everywhere in the app without having to replace each instance of a tailwind colour.

Maybe in the config something like addColorsInTailwind: true

Copy link
Member

Unfortunately, we can't do that as the @nuxt/ui import can't be dynamic and is hard-coded: https://github.com/nuxt/ui/blob/v3/src/runtime/index.css

Also, Nuxt UI v3 has taken a CSS variable approach to avoid conflicts with the user's theme as mentioned previously, you can simply use the tokens from the color palette: text-(--ui-color-primary-500).

We also have configurable tokens for light and dark mode, for example you can write text-(--ui-primary) which would be the equivalent of text-primary-500 dark:text-primary-400.

Note that you can use the Tailwind CSS colors as usual though.

I understand it can be tedious if you want to use each one of Nuxt UI colors as Tailwind CSS classes but you can make another CSS file and import it. Actually, maybe we can provide another CSS file that does that, something like @import "@nuxt/ui-colors";. I'll think about it!

@benjamincanac benjamincanac linked a pull request Dec 24, 2024 that will close this issue
8 tasks
@benjamincanac benjamincanac removed the triage label Dec 24, 2024 — with Volta.net
@unpseudocomplique
Copy link

Would like to go further in the request. Would be much better to have the global classes available in tailwind by default. For exemple i often need for my own component to have the base background / background 2 or base border ect...

Would be great if this can be integrated by default to be consistent accross projects :
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v3 #1289
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants