Skip to content

Instantly share code, notes, and snippets.

@sekoyo
Last active March 21, 2019 11:23
Show Gist options
  • Save sekoyo/9e4a9e940ae0039bb8322cb35fe14e6e to your computer and use it in GitHub Desktop.
Save sekoyo/9e4a9e940ae0039bb8322cb35fe14e6e to your computer and use it in GitHub Desktop.
BEM Class helper
/*
BEM Class helper:
const c = makeClass('myparentclass');
className={c`myclass myclass--active`}
becomes: className="myparentclass__myclass myparentclass__myclass--active"
*/
export const makeClass = (cls) =>
(subCls) => subCls[0].split(' ').reduce((acc, s) =>
`${acc}${cls}__${s} `, '').trimRight();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment