Last active
February 22, 2023 13:05
-
-
Save DaveKin/d70b9a8fceb6f252f74d to your computer and use it in GitHub Desktop.
Utility SASS mixin to convert a map of property names and values to CSS
This file contains hidden or 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
/** | |
* Converts a SASS map of css property names and values into CSS output. | |
* Properties named `description` will have their value inserted as comments. | |
* | |
* Nested maps will be processed recursively. | |
* | |
* @param {map} $map the map of properties to output | |
*/ | |
@mixin map-to-props($map){ | |
@if type-of($map) == map { | |
@each $prop, $value in $map { | |
@if type-of($value) != map { | |
@if inspect($prop) == 'description' { | |
/* #{inspect($value)} */ | |
} | |
@else { | |
#{inspect($prop)}: #{inspect($value)}; | |
} | |
} | |
@else { | |
@include map-to-props($value); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!
Found this a very useful approach in exporting variables to use as a module in webpack.