Created
August 6, 2016 15:52
-
-
Save mbarnard/5eed61632f187f75db07c2948a81f792 to your computer and use it in GitHub Desktop.
@Mixins to create BEM element & modifier classes
This file contains hidden or 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
/*------------------------------------*\ | |
* #element-modifier-class | |
* BEM element & modifier classes | |
* Using @at-root provides nesting declarations in Sass, | |
* but compiles them to the stylesheet’s root. | |
\*------------------------------------*/ | |
/** | |
* @mixin element | |
* Create a child element declaration | |
* @param {String} $name - element name | |
*/ | |
@mixin element($name) { | |
@at-root #{&}__#{$name} { | |
@content; | |
} | |
} | |
/** | |
* @mixin modifier | |
* Create a child element modifier declaration | |
* @param {String} $name - modifier name | |
*/ | |
@mixin modifier($name) { | |
@at-root #{&}--#{$name} { | |
@content; | |
} | |
} | |
.module { | |
color: red; | |
@include element(h3) { | |
color: blue; | |
@include modifier(success) { | |
color: green; | |
} | |
} | |
} | |
/*------------------------------------* | |
* #element-modifier-class compiled | |
\*------------------------------------*/ | |
.module { | |
color: red; | |
} | |
.module__h3 { | |
color: blue; | |
} | |
.module__h3--success { | |
color: green; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment