cssclasscrafter
Version:
CSSClassCrafter is an npm library that enables developers to dynamically generate CSS classes based on user-defined configuration files. With a simple JSON format for specifying styles, it streamlines the styling process, allowing for easy customization a
30 lines (25 loc) • 981 B
JavaScript
import { warnConsolelog } from "../LodingAnimation.mjs";
// Function to generate CSS rules for background color classes
export function generateBackgroundColorClasses(backgroundColorPrefix, colors) {
let css = "";
colors.forEach((colorObj) => {
if (
typeof colorObj === "object" &&
colorObj !== null &&
!Array.isArray(colorObj)
) {
const [name, value] = Object.entries(colorObj)[0];
const className = `${backgroundColorPrefix || "bg"}-${name}`; // Prefix the name with 'bg-'
if (value.startsWith("linear-gradient")) {
css += `.${className} { background: ${value}; }\n`; // For gradients
} else {
css += `.${className} { background-color: ${value}; }\n`; // For solid colors
}
} else {
warnConsolelog(
`Invalid background color entry in config: ${JSON.stringify(colorObj)}. Expected an object with a name-value pair.`
);
}
});
return css;
}