Created
December 3, 2015 20:40
-
-
Save oranj/f238c44f15cd71de8765 to your computer and use it in GitHub Desktop.
BEM SASS Mixins
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 mixins (Block, Element, Modifier) | |
// | |
// Just google if you're confused. | |
@mixin block($name) { | |
@at-root .#{$name} { | |
@content; | |
} | |
} | |
@mixin element($names...) { | |
$selector: ""; | |
$i: 1; | |
@each $name in $names { | |
@if ($i != 1) { | |
$selector: ", #{$selector}"; | |
} | |
$selector: "#{&}__#{$name} #{$selector}"; | |
$i: $i + 1; | |
} | |
@at-root #{$selector} { | |
@content; | |
} | |
} | |
@mixin modifier($names...) { | |
$selector: ""; | |
$i: 1; | |
@each $name in $names { | |
@if ($i != 1) { | |
$selector: ", #{$selector}"; | |
} | |
$selector: "#{&}--#{$name} #{$selector}"; | |
$i: $i + 1; | |
} | |
@at-root #{$selector} { | |
@content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment