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
18 lines (14 loc) • 720 B
JavaScript
// Function to generate CSS rules for text color classes
export function generateColorClasses(colorPrefixName, colors) {
let css = '';
colors.forEach(colorObj => {
if (typeof colorObj === 'object' && colorObj !== null && !Array.isArray(colorObj)) {
const [name, value] = Object.entries(colorObj)[0];
const className = `${colorPrefixName || 'text'}-${name}`; // Prefix the name with 'text-'
css += `.${className} { color: ${value}; }\n`; // For text color
} else {
warnConsolelog(`Invalid text color entry in config: ${JSON.stringify(colorObj)}. Expected an object with a name-value pair.`);
}
});
return css;
}