Last active
September 3, 2017 15:03
-
-
Save tzi/2e54c245af91769ea912fa4e5f6d3820 to your computer and use it in GitHub Desktop.
Using a "next generation mixin" to generate themes in sass
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
// Passing arguments from a mixin to a content block | |
// Planned for Sass 4 | |
// https://github.com/sass/sass/issues/871 | |
// File: common.scss | |
$theme-colors: ( | |
pink: #FF69B4, | |
orange: #FFA500, | |
); | |
@mixin theme() { | |
@each $theme, $color in $theme-colors { | |
.app--#{$theme} & { | |
@content($color); | |
} | |
} | |
} | |
// File: component.scss | |
.component { | |
@include theme() using($color) { | |
color: $color; | |
} | |
} | |
// This code should output | |
.app--pink .component { | |
color: #FF69B4; | |
} | |
.app--orange .component { | |
color: #FFA500; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment