Created
September 1, 2015 07:43
-
-
Save antelle/40f8767a431ee5a905fe to your computer and use it in GitHub Desktop.
Modular SCSS theming
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
// modified version of http://www.sitepoint.com/sass-theming-neverending-story/ | |
// allows to write themified code without breaking modular project structure | |
// only one global variable | |
// Theme definitions | |
$themes: ( | |
unicorn: (primary: hotpink, secondary: pink), | |
dragon: (primary: firebrick, secondary: red) | |
); | |
// Engine | |
$th: null; | |
@function th($key) { | |
@return map-get($th, $key); | |
} | |
@mixin th { | |
@each $theme, $data in $themes { | |
.th-#{$theme} & { | |
$th: $data !global; | |
@content; | |
$th: null !global; | |
} | |
} | |
} | |
// Example | |
@mixin default-border { | |
@include th { border: 1px solid th(primary); } | |
} | |
@function default-border-style { | |
@return 1px solid th(primary); | |
} | |
.media { | |
@include th { border-color: th(secondary); } | |
@include default-border; | |
&__title { | |
@include th { | |
color: darken(th(primary), .5); | |
border: default-border-style(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment