Skip to content

Instantly share code, notes, and snippets.

@etoxin
Last active September 4, 2019 01:25
Show Gist options
  • Save etoxin/ea4312b60b5262f97e0dcac878ed253e to your computer and use it in GitHub Desktop.
Save etoxin/ea4312b60b5262f97e0dcac878ed253e to your computer and use it in GitHub Desktop.
Modify method for BEM
@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;
}
}
}
}
}
.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