Skip to content

Instantly share code, notes, and snippets.

@nestorivan
Created March 21, 2017 00:30
Show Gist options
  • Save nestorivan/1ca4285b336fccd57e9606f587b5981c to your computer and use it in GitHub Desktop.
Save nestorivan/1ca4285b336fccd57e9606f587b5981c to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.21)
// Compass (v1.0.3)
// ----
// Define theme variables
$themes: (
default: ( // default theme
bg-color: white,
text-color: black,
),
dark: (
bg-color: black,
text-color: white,
),
colorful: (
bg-color: green,
text-color: orange,
)
);
// Mixins and functions defined once
@mixin themify() {
// Iterate over the themes
@each $theme-name, $theme in $themes {
$current-theme: $theme !global;
@if $theme-name == 'default' {
@content;
} @else {
.theme-#{$theme-name} & {
@content;
}
}
}
}
@function theme-get($key, $theme: $current-theme) {
$ret: map-get($theme, $key);
@if not $ret {
@error 'Your theme doesn\'t have a value for `#{$key}`.';
}
@return $ret;
}
// This is how you use your themes
.example{
padding: 10px;
@include themify {
background: theme-get(bg-color);
color: theme-get(text-color);
}
}
.example {
padding: 10px;
background: white;
color: black;
}
.theme-dark .example {
background: black;
color: white;
}
.theme-colorful .example {
background: green;
color: orange;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment