#TypeError: flattenColorPalette is not a function

8 messages · Page 1 of 1 (latest)

vapid forge
#

TypeError: flattenColorPalette is not a function

safe coral
#

same , i got the same error, and i came here looking for answers

vapid forge
pearl thicket
#

same

blissful tendon
#

instead of flattenColorPalette Create a utility function to flatten the color palette.
Use this function within your Tailwind CSS configuration. import type { Config } from "tailwindcss";
import svgToDataUri from "mini-svg-data-uri";
import colors from "tailwindcss/colors";

// Custom flattenColorPalette function
const flattenColorPalette = (obj) => {
const result = {};

const recurse = (cur, prop) => {
if (Object(cur) !== cur) {
result[prop] = cur;
} else if (Array.isArray(cur)) {
for (let i = 0, l = cur.length; i < l; i++) {
recurse(cur[i], prop ? ${prop}-${i} : ${i});
}
if (l === 0) result[prop] = [];
} else {
let isEmpty = true;
for (const p in cur) {
isEmpty = false;
recurse(cur[p], prop ? ${prop}-${p} : p);
}
if (isEmpty) result[prop] = {};
}
};

recurse(obj, '');
return result;
};

// Custom addVariablesForColors function
const addVariablesForColors = ({ addBase, theme }) => {
const allColors = flattenColorPalette(theme("colors"));
const newVars = Object.fromEntries(
Object.entries(allColors).map(([key, val]) => [--${key}, val])
);

addBase({
":root": newVars,
});
};
rest config and plugins same

vapid forge
#

I don't know but i restarted the server and now it kinda works but not as i want it, but at least it works

safe coral