Skip to content

Instantly share code, notes, and snippets.

@gsambrotta
Created October 20, 2015 13:50
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 gsambrotta/d80262459461236f7cfc to your computer and use it in GitHub Desktop.
Save gsambrotta/d80262459461236f7cfc to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.14)
// Compass (v1.0.3)
// ----
// utils/z-index/z-index.variables.scss
// -------------
$z-layers: (
"goku": 9001,
"shoryuken": 8000,
"modal": (
"base": 500,
"close": 100,
"header": 50,
"footer": 10
),
"default": 1,
"below": -1,
"bottomless-pit": -9000
);
// utils/z-index/z-index.helpers.scss
// -------------
@function map-has-nested-keys($map, $keys...) {
@each $key in $keys {
@if not map-has-key($map, $key) {
@return false;
}
$map: map-get($map, $key);
}
@return true;
}
@function map-deep-get($map, $keys...) {
@each $key in $keys {
$map: map-get($map, $key);
}
@return $map;
}
@function z($layers...) {
@if not map-has-nested-keys($z-layers, $layers...) {
@warn "No layer found for `#{inspect($layers...)}` in $z-layers map. Double check on z-index.variables.";
}
@return map-deep-get($z-layers, $layers...);
}
// Example of usage
// ---------------
// New stacking context
.modal {
position: absolute;
z-index: z("modal", "base");
.close-button {
z-index: z("modal", "close");
}
header {
z-index: z("modal", "header");
}
footer {
z-index: z("modal", "footer");
}
}
.modal {
position: absolute;
z-index: 500;
}
.modal .close-button {
z-index: 100;
}
.modal header {
z-index: 50;
}
.modal footer {
z-index: 10;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment