Skip to content

Instantly share code, notes, and snippets.

@antelle
Created September 1, 2015 07:43
Show Gist options
  • Save antelle/40f8767a431ee5a905fe to your computer and use it in GitHub Desktop.
Save antelle/40f8767a431ee5a905fe to your computer and use it in GitHub Desktop.
Modular SCSS theming
// 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