Skip to content

Instantly share code, notes, and snippets.

@AndrewIngram
Created October 21, 2014 10:52
Show Gist options
  • Save AndrewIngram/e073bf740cd0a7b34a35 to your computer and use it in GitHub Desktop.
Save AndrewIngram/e073bf740cd0a7b34a35 to your computer and use it in GitHub Desktop.
function cx(classNames, namespace, theme) {
var classes;
var bemClasses = [];
if (typeof classNames == 'object') {
classes = Object.keys(classNames).filter(function(className) {
return classNames[className];
});
} else {
classes = classNames;
}
classes.forEach(function(className) {
var baseClassName = namespace + '-' + className;
bemClasses.push(baseClassName);
if (theme) {
bemClasses.push(baseClassName + '--theme-' + theme);
}
});
return bemClasses.join(' ');;
}
module.exports = cx;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment