Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Adding a variable to a property causes lighten/darken to not work

I am trying to create variables using a mixin, however, when I do so, the lighten and darken functions don’t work.

@mixin create-color($name, $value) {
  --color-#{$name}: #{$value};
  --color-#{$name}-light: lighten($color: #{$value}, $amount: 10);
  --color-#{$name}-dark: darken($color: #{$value}, $amount: 10);
}

:root {
  @include create-color('primary', #0000cd);
}

This results in the following output:

:root {
    --color-primary: #0000cd;
    --color-primary-light: lighten($color: #0000cd, $amount: 10);
    --color-primary-dark: darken($color: #0000cd, $amount: 10);
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to interpolate the whole function.

@mixin create-color($name, $value) {
  --color-#{$name}: #{$value};
  --color-#{$name}-light: #{lighten($color: $value, $amount: 10)};
  --color-#{$name}-dark: #{darken($color: $value, $amount: 10)};
}

:root {
  @include create-color('primary', #0000cd);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading