Skip to content

Instantly share code, notes, and snippets.

@averyvery
Created January 31, 2017 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save averyvery/9a2b82f980435af13c8e248de6fb1211 to your computer and use it in GitHub Desktop.
Save averyvery/9a2b82f980435af13c8e248de6fb1211 to your computer and use it in GitHub Desktop.
lil trick
/*
example:
dimension(foo, bar, 2, 10px);
- gets the value bar inside foo map
- multiplies it by two
- adds 10px
*/
$dimensions: (
global: (
gutter: 20px
),
);
@function dimension($keys...) {
$value: $dimensions;
@each $key in $keys {
@if (type-of($key) == number) {
@if (unitless($key) == true) {
$value: $value * $key;
} @else if (unitless($key) == false) {
$value: $value + $key;
}
}
@if (type-of($key) == string) {
$value: map-get($value, $key);
}
}
@return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment