Skip to content

Instantly share code, notes, and snippets.

@jensgro
Forked from DaveKin/_propmap.scss
Created February 22, 2023 13:05
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 jensgro/cf372084e8193c0e9bbdd44bc4c908e8 to your computer and use it in GitHub Desktop.
Save jensgro/cf372084e8193c0e9bbdd44bc4c908e8 to your computer and use it in GitHub Desktop.
Utility SASS mixin to convert a map of property names and values to CSS
/**
* 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