Skip to content

Instantly share code, notes, and snippets.

@benmvp
Created January 18, 2020 00:02
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 benmvp/e2ec9cf644320e2ec090f5c78f795cf8 to your computer and use it in GitHub Desktop.
Save benmvp/e2ec9cf644320e2ec090f5c78f795cf8 to your computer and use it in GitHub Desktop.
Trying to figure out how to programmatically generate CSS class names using SASS + CSS Modules + babel-react-css-modules
$colors: ("white": $white, "yellow": $yellow, "green": $green, "blue": $blue);
@each $name, $color in $colors {
// this programmatically generates 4 class namaes in the resultant css.
// but when Babel parses the module to pull out the class names, it just
// gets "bg-color-#${name}" since postcss-scss doesn't compile the SCSS
// (https://github.com/postcss/postcss-scss) when used with babel-react-css-modules
// (https://github.com/gajus/babel-plugin-react-css-modules#configurate-syntax-loaders)
.bg-color-#{$name} {
background-color: #{$color};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment