Skip to content

Instantly share code, notes, and snippets.

@ben-rogerson
Last active November 12, 2018 23:01
Show Gist options
  • Save ben-rogerson/091c28697ffe06803cb172e043b393a4 to your computer and use it in GitHub Desktop.
Save ben-rogerson/091c28697ffe06803cb172e043b393a4 to your computer and use it in GitHub Desktop.
SASS Mapping Example
// 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