Last active
November 7, 2022 16:06
-
-
Save stowball/080e77b8831e57f275f2a906f4d66697 to your computer and use it in GitHub Desktop.
Recursive z-index managment
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
$z-indexes: ( | |
main: ( | |
above-inherit: (), | |
nested: ( | |
low, | |
middle, | |
high | |
), | |
tooltip: () | |
), | |
header: (), | |
toaster: () | |
); | |
.main { | |
z-index: z(main); | |
} | |
.nested { | |
z-index: z(main, nested); | |
} | |
.high { | |
z-index: z(main, nested, high); | |
} |
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
@function z-index($keys) { | |
$map: $z-indexes; | |
$found-index: null; | |
@each $key in $keys { | |
@if (type-of($map) == "map") { | |
$found-index: index(map-keys($map), $key); | |
$map: map-get($map, $key); | |
} | |
@else { | |
$found-index: index($map, $key); | |
} | |
} | |
@return $found-index; | |
} | |
@function z($keys...) { | |
@return z-index($keys); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I'm gonna use this now, please correct "managment" to "management" :-)