question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sass variables should (optionally?) have `!default` flag

See original GitHub issue

In the scss/map-deep format, the variables it generates (for use in the map) have the !default flag:

// '!default' means if the variable is/was already defined, this declaration gets skipped
$my-var: #123ABC !default; 
$tokens: (
  my: (
    var: $my-var,
  )
);

…whereas the scss/variables format doesn’t have that:

// No !default, so this variable can't be overridden during Sass compilation
$my-var: #123ABC;

Is there a reason why one has it and the other doesn’t? To me, it seems like:

  • These should agree…It’s not necessarily a huge deal, but currently if we build both formats, downstream Sass compilations will either be able to override the values or not, based on which format they choose.
  • !default should be added as an option so we can choose whether or not we want them to be able to override the variables from the configuration. (I guess that’s a feature request. 😄)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dbanksdesigncommented, Oct 8, 2020

We merged in #359 onto the 3.0 branch targeting the next major release. We will keep this issue open until the release. We want to see if this flag themeable: true on the token can be used in other built-in formats so that this is not SCSS specific. If anyone has ideas for this please open a PR or comment on this issue: #474 thanks!

0reactions
dbanksdesigncommented, Apr 16, 2021

Closing this issue as this is now a feature in 3.0. You can get it today with npm install style-dictionary@next

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating Stylesheet Feature Flags With Sass !default
default is a Sass flag that indicates conditional assignment to a variable — it assigns a value only if the variable was previously ......
Read more >
Variables - Sass
CSS variables can have different values for different elements, but Sass variables only have one ... To make this possible, Sass provides the...
Read more >
A Sass `!default` use case - Thoughtbot
default flag to the end of the value. This means that if the variable has already been assigned to, it won't be re-assigned,...
Read more >
SASS variables set inside of conditional? - Stack Overflow
You're misusing the !default flag. This flag means "set a value to a variable only if it has no value". – Andrey Mikhaylov...
Read more >
The Ultimate Guide to Learning Sass/SCSS
Usually, when you assign a value to a variable and later assign another value to it, the original value is overwritten. To overcome...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found