Modified config files for Aceternity.

This commit is contained in:
sid
2024-10-26 20:40:04 +01:00
parent 4a10e8d42a
commit 2235ae9851
3 changed files with 56 additions and 5 deletions

View File

@@ -1,4 +1,10 @@
import type { Config } from 'tailwindcss';
import tailwindcssAnimate from 'tailwindcss-animate';
type ColorValue = string | ColorDictionary;
interface ColorDictionary {
[colorName: string]: ColorValue;
}
const config: Config = {
darkMode: ['class'],
@@ -68,6 +74,44 @@ const config: Config = {
},
},
},
plugins: [require('tailwindcss-animate')],
plugins: [tailwindcssAnimate, addVariablesForColors],
};
export default config;
// Plugin to add each Tailwind color as a CSS variable
function addVariablesForColors({
addBase,
theme,
}: {
addBase: (styles: Record<string, Record<string, string>>) => void;
theme: (path: string) => unknown;
}) {
const colors = theme('colors') as ColorDictionary;
const flattenedColors = flattenColors(colors);
const newVars = Object.fromEntries(
Object.entries(flattenedColors).map(([key, val]) => [`--${key}`, val])
);
addBase({
':root': newVars,
});
}
// Recursive function to flatten nested color objects
function flattenColors(
colors: ColorDictionary,
prefix = ''
): Record<string, string> {
const result: Record<string, string> = {};
for (const [key, value] of Object.entries(colors)) {
if (typeof value === 'string') {
// If the value is a string, add it to the result
result[prefix + key] = value;
} else if (typeof value === 'object' && value !== null) {
// If the value is an object, recursively flatten it
Object.assign(result, flattenColors(value, `${prefix}${key}-`));
}
}
return result;
}