Last active
September 4, 2019 01:25
-
-
Save etoxin/ea4312b60b5262f97e0dcac878ed253e to your computer and use it in GitHub Desktop.
Modify method for BEM
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
@mixin modify ($modifier) { | |
$class: quote(#{&}); | |
$index: str-index($class, '__'); | |
$parent: str-slice($class, 1, $index - 1); | |
@at-root #{selector-nest(#{$parent}--#{$modifier}, &)} { | |
@content; | |
} | |
} | |
.parent { | |
&__title { | |
color: purple; | |
@include modify("error"){ | |
color: red; | |
} | |
} | |
&__child { | |
&__grandChild { | |
@include modify("valid"){ | |
color: green; | |
} | |
&__deep { | |
@include modify("error") { | |
color: red; | |
} | |
} | |
} | |
} | |
} |
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
.parent__title { | |
color: purple; | |
} | |
.parent--error .parent__title { | |
color: red; | |
} | |
.parent--valid .parent__child__grandChild { | |
color: green; | |
} | |
.parent--error .parent__child__grandChild__deep { | |
color: red; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment