Last active
March 21, 2019 11:23
-
-
Save sekoyo/9e4a9e940ae0039bb8322cb35fe14e6e to your computer and use it in GitHub Desktop.
BEM Class helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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