Created
August 21, 2015 16:32
-
-
Save finteractive/9d99f2c1a261ed675288 to your computer and use it in GitHub Desktop.
An Introduction to Sass Maps: Examples (Generated by SassMeister.com.)
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
// ---- | |
// 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´" | |
} | |
} | |
} |
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
/* | |
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