ui icon indicating copy to clipboard operation
ui copied to clipboard

How to handle theme/color changes?

Open Tobjoern opened this issue 2 years ago • 10 comments

Using tailwind, there are a lot of mentions of different colors (i.e. bg-slate-900, bg-red-500 etc.). With 'slate' being the 'primary' color. Let's say my primary colors is a blue, how would I go about changing that? From my current understanding, I would have to go through every single file and change every single occurrence of slate, which is difficult, as slate may in some cases refer to a 'border' and not a primary color.

What would be the suggested way to deal with this issue?

Tobjoern avatar Mar 10 '23 07:03 Tobjoern

My proposal is to define semantic colors in the Tailwind configuration. This will enable users to create their own set of semantic colors in their configuration, and when a user copies a component, the colors will automatically work. Additionally, I suggest supporting auto dark mode with the use of CSS variables, as mentioned in issue #52.

its-monotype avatar Mar 10 '23 10:03 its-monotype

Note: I am looking into it. I'm also reading @its-monotype proposal in #52.

shadcn avatar Mar 10 '23 11:03 shadcn

This is one of the things I'm still unsure about with regards to tailwind. Should one create semantic color names or not?

Tobjoern avatar Mar 10 '23 13:03 Tobjoern

Just change the color slate at tailwind.config.js (Do not extend it, just override it) ezpz

yehorovye avatar Mar 10 '23 18:03 yehorovye

Just change the color slate at tailwind.config.js (Do not extend it, just override it) ezpz

Yeah, I know how to do it, but I'm always struggling to decide wether to use names like 'blue-500' or create semantic classes, like 'primary-500'.

Tobjoern avatar Mar 13 '23 07:03 Tobjoern

Or, just use vscode search and replace tool, replace all "slate" strings in the whole project with the word u want, is that simple :D

yehorovye avatar Mar 18 '23 16:03 yehorovye

I would love to see some way to have more semantic colors (e.g. primary, secondary, tertiary, success, warning, error) instead of just primary, secondary and destructive. And then a way to create themes like https://www.skeleton.dev/docs/generator would be amazing.

multiwebinc avatar Apr 25 '23 18:04 multiwebinc

Another one to look at for inspiration would be https://github.com/williamlmao/chimera-ui, which is a fork of this repo. Here's their theme generator https://www.chimera-ui.com/docs/theme

multiwebinc avatar Apr 26 '23 01:04 multiwebinc

It isn't actually that hard to use the Skeleton UI design tokens to style components and that makes theming all components super easy.

image

image

image

@shadcn I wonder if you would be interested in adding this by default. Here's a discussion on how I did it: https://github.com/skeletonlabs/skeleton/discussions/1367#discussioncomment-5822302

multiwebinc avatar May 09 '23 18:05 multiwebinc

@multiwebinc I'm looking into a theme generator. So many things to do right now... ;)

shadcn avatar May 10 '23 12:05 shadcn

@multiwebinc could you push up what you've made to an example repo? I'm quite interested in using skeleton with shadcn, the theme support is much more powerful with Skeleton with all their pre-built utilities.

DevOfManyThings avatar Jul 04 '23 12:07 DevOfManyThings

I created a tool to let you generate custom themes for shadcn/ui.

You can customize the template and use standard Tailwind colors and tokens like primary, secondary, accent, etc., then specify on the command line. The tool will automatically convert them to HSL format.

https://github.com/kiliman/shadcn-custom-theme

kiliman avatar Aug 09 '23 18:08 kiliman

From my current understanding, I would have to go through every single file and change every single occurrence of slate, which is difficult, as slate may in some cases refer to a 'border' and not a primary color.

This was my impression too. I am 100% sure using shadcn-ui would allow me to save so much time, but it is really really hard to understand how theming works with tailwind utility classes.

I feel like the docs don't really help me to get started. For example I expected to simply set the baseColor to orange and then have my primary color be orange. But that wasn't the case, only gray colors were available. I went to the https://ui.shadcn.com/themes site and there I could easily change the gray primary color to an orange one.

If theming via tailwind utility classes is only an escape hatch and not really the shadcn-ui recommended way to do theming, can the docs please describe that better? I thought this was a preferences thing, but I am going to try the setup with css variables now.

EDIT: Tried it with css variables mode now, I can at least set the colors now. I also like the idea of being able to switch e.g. my primary color in one place. But I still think I am going to use the utility class style and then after installing a component simply add own variants / edit existing ones. Maybe this is simply the way it's meant to be used? Don't configure it but simply edit the final component?

xdivby0 avatar Oct 06 '23 13:10 xdivby0

@xdivby0 I tried the approach of making all colors available via baseColor but then you end up with a lot of your UI being for instance orange. So we start with a more neutral (gray) base and let you add colors on top of it.

Is there anything specific you're looking for? Can you create a separate issue we can hash it out together. Thank you.

shadcn avatar Oct 21 '23 14:10 shadcn

This shadcn ui theme generator outputs dark / light mode custom properties that can be copied and pasted:

It will automatically generate all colours based on at-least a single colour input, then saturation and lightness can be altered to create even more variations.

morganfeeney avatar Jan 16 '24 10:01 morganfeeney