Last active
November 12, 2018 23:01
-
-
Save ben-rogerson/091c28697ffe06803cb172e043b393a4 to your computer and use it in GitHub Desktop.
SASS Mapping Example
This file contains 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
// Helper: Get a map item from an object that is a few levels deep | |
@function map-deep-get($map, $keys...) { | |
@each $key in $keys { | |
$map: map-get($map, $key); | |
} | |
@return $map; | |
} | |
// Define the theme within your project palette | |
$palette: ( | |
themes: ( | |
plain: ( | |
text: white, | |
bg: black | |
) | |
) | |
); | |
// Define your helper | |
@function theme-text($key) { @return map-deep-get($palette, 'themes', $key, 'text'); } | |
// Usage | |
body { | |
color: theme-text(plain); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment