L-Blondy / tw-colors

Tailwind plugin to easily add multiple color themes to your projects.
MIT License
464 stars 14 forks source link

Add default setting for neutral/duplicate color #20

Closed asen23 closed 1 year ago

asen23 commented 1 year ago

Is it possible to implement some sort of default color to this library?

If say i have a neutral color that is the same across all of my theme, i need to redeclare that color on each theme like so

createThemes({
  light: {
    primary: "white",
    neutral: "#333",
  },
  dark: {
    primary: "black",
    neutral: "#333",
  },
}),

If i only have 2 themes and only one same color it is no problem, but if there are many themes or many neutral color it will become harder to manage and easy to miss updating color. Maybe you can add default color like this

createThemes({
  light: {
    primary: "white",
  },
  dark: {
    primary: "black",
  },
}, {
  defaultColor: {
    neutral: "#333",
  },
}),

And if you need to override just define it on the color

createThemes({
  light: {
    primary: "white",
  },
  dark: {
    primary: "black",
    neutral: "#ccc",
  },
}, {
  defaultColor: {
    neutral: "#333",
  },
}),

Also cool library, definitely help making theming easier in tailwind. Thanks for your hard work!

L-Blondy commented 1 year ago

Hi @asen23, thanks for the feedback. If the color never changes accross the themes you can also define it outside of the plugin, like you would normally do with tailwind.

In other words you can use the plugin just for the colors that change and leave the other colors in the standard config

asen23 commented 1 year ago

If the use case doesn't include color overriding, defining color in vanilla tailwind will work, but in my third example, if i want to override the color for certain theme, it won't work. I think the use case is kinda niche, but still nice to have in my opinion

L-Blondy commented 1 year ago

Why not go for something like this?

const defaults = {
  neutral: "#888" 
} 

createThemes({
  light: {
    ...defaults,
    primary: "white",
  },
  dark: {
    ...defaults,
    primary: "black",
    neutral: "#789" 
  },
})

To me it feels like it is easier to read and to reason about.

asen23 commented 1 year ago

Ah you're right, i didn't really think about that. That works for me. Thanks for the quick reply