Created
July 11, 2017 12:06
-
-
Save BuddyLReno/0ecd0e5cdaefe3e19b88c8ca3a8b146a to your computer and use it in GitHub Desktop.
Mixin to insert class inside parent selector.
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
@mixin insertParent($class, $append: false) { | |
$selString: quote(&); | |
$parent: str-slice($selString, 0, str-index($selString, " ") - 1); | |
$minusParent: str-slice($selString, str-index($selString, " ") + 1); | |
$firstChild: str-slice($minusParent, 0, str-index($minusParent, " ") - 1); | |
$otherChildren: str-slice($selString, str-index($selString, $firstChild) + str-length($firstChild) + 1); | |
$selector: unquote(""); | |
@if $append { | |
$selector: $parent #{$firstChild}#{$class} $otherChildren; | |
} @else { | |
$selector: $parent $class $firstChild $otherChildren; | |
} | |
@at-root { | |
#{$selector} { | |
@content; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment