Skip to content

Instantly share code, notes, and snippets.

@finteractive
Created August 21, 2015 16:32
Show Gist options
  • Save finteractive/9d99f2c1a261ed675288 to your computer and use it in GitHub Desktop.
Save finteractive/9d99f2c1a261ed675288 to your computer and use it in GitHub Desktop.
An Introduction to Sass Maps: Examples (Generated by SassMeister.com.)
// ----
// libsass (v3.2.5)
// ----
/*
Source: http://webdesign.tutsplus.com/tutorials/an-introduction-to-sass-maps-usage-and-examples--cms-22184
Topic:An Introduction to Sass Maps: Examples
*/
//Define the themes
// _config.scss
$themes: (
theme1: theme-light,
theme2: theme-dark
);
//Getting the Value (Short Way)
// _functions.scss
@function setStyle($map, $object, $style) {
@if map-has-key($map, $object) {
@return map-get(map-get($map, $object), $style);
}
@warn "The key ´#{$object} is not available in the map.";
@return null;
}
//Build the Module & Loop Through the Themes
// _m-buttons.scss
// 1.Config
$config: (
theme1: (
background: #f2f2f2,
color: #000
),
theme2: (
background: #666,
color: #fff
)
);
// _m-buttons.scss
// 2.Base
.m-button {
@each $key, $value in $themes {
@if map-has-key($config, $key) {
.#{$value} & {
background: setStyle($config, $key, background);
color: setStyle($config, $key, color);
}
} @else {
@warn "The key ´#{$key} isn’t defined in the map $config´"
}
}
}
/*
Source: http://webdesign.tutsplus.com/tutorials/an-introduction-to-sass-maps-usage-and-examples--cms-22184
Topic:An Introduction to Sass Maps: Examples
*/
.theme-light .m-button {
background: #f2f2f2;
color: #000;
}
.theme-dark .m-button {
background: #666;
color: #fff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment