Skip to content

Instantly share code, notes, and snippets.

@anatooly
Created November 8, 2020 12:13
Show Gist options
  • Save anatooly/9bc22cadb6df27e36d86338e419cdf2b to your computer and use it in GitHub Desktop.
Save anatooly/9bc22cadb6df27e36d86338e419cdf2b to your computer and use it in GitHub Desktop.
BEM tool className
export default (block, element, modifier) => {
let prefix, ret;
if (!element) {
prefix = block;
} else {
prefix = block + '__' + element;
}
if (modifier) {
if (modifier instanceof Array) {
ret = [ prefix ].concat(modifier.map(mod => prefix + '--' + mod));
} else {
ret = [ prefix, prefix + '--' + modifier ];
}
} else {
ret = prefix;
}
return ret instanceof Array ? ret.join(' ') : ret;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment