feat(tailwind.config): add global CSS variables for colors
A new function, `addVariablesForColors`, has been added into the Tailwind configuration file to map each Tailwind color into a global CSS variable. This allows usage such as `var(--gray-200)` throughout the application for all Tailwind colors.
This commit is contained in:
parent
0f6a67470d
commit
409926a97b
@ -1,5 +1,8 @@
|
|||||||
import type { Config } from "tailwindcss"
|
import type { Config } from "tailwindcss"
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
import {default as flattenColorPalette} from "tailwindcss/lib/util/flattenColorPalette";
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
darkMode: ["class"],
|
darkMode: ["class"],
|
||||||
content: [
|
content: [
|
||||||
@ -74,7 +77,19 @@ const config = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [require("tailwindcss-animate")],
|
plugins: [require("tailwindcss-animate"), addVariablesForColors],
|
||||||
} satisfies Config
|
} satisfies Config
|
||||||
|
|
||||||
|
// This plugin adds each Tailwind color as a global CSS variable, e.g. var(--gray-200).
|
||||||
|
function addVariablesForColors({ addBase, theme }: any) {
|
||||||
|
let allColors = flattenColorPalette(theme("colors"));
|
||||||
|
let newVars = Object.fromEntries(
|
||||||
|
Object.entries(allColors).map(([key, val]) => [`--${key}`, val])
|
||||||
|
);
|
||||||
|
|
||||||
|
addBase({
|
||||||
|
":root": newVars,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export default config
|
export default config
|
Loading…
x
Reference in New Issue
Block a user