I have an application getting migrated from Tailwindcss v3 to v4.1.
I make use of color themes, dynamically switched by the client using data attribute or class on the <body>. Thus elements can simply be styled using var(--primary-500), or even bg-neutral-100 text-primary-500 border-primary-500, while the actual color palette is determined dynamically.
Here's an outline of the theme system:
//color-schemes.js - which is imported into the tailwind.config.js
module.exports = {
blue: {
primary: {
50: "#f1f9ff",
100: "#d9efff",
200: "#b1dfff",
},
accent: {
50: "#fff6ed",
100: "#ffedd5",
200: "#fed7aa",
},
neutral: {
50: "#f8fafc",
100: "#f1f5f9",
200: "#e2e8f0",
},
},
green: {
primary: {
50: "#f6faf3",
100: "#e3f1dc",
},
accent: {
50: "#ecfdf5",
100: "#d1fae5",
},
}
...etc
//blue.css
[data-theme="blue"] {
--primary-50: theme("colors.blue.primary.50");
--primary-100: theme("colors.blue.primary.100");
--primary-200: theme("colors.blue.primary.200");
--secondary-50: theme("colors.blue.secondary.50");
--secondary-100: theme("colors.blue.secondary.100");
--secondary-200: theme("colors.blue.secondary.200");
}
//green.css
[data-theme="green"] {
--primary-50: theme("colors.green.primary.50");
--primary-100: theme("colors.green.primary.100");
--primary-200: theme("colors.green.primary.200");
--secondary-50: theme("colors.green.secondary.50");
--secondary-100: theme("colors.green.secondary.100");
--secondary-200: theme("colors.green.secondary.200");
}
I'm now unable to get this to work in v4 as config.js is discouraged. What is the css-first way to achieve this?