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.

Strings get converted to unquoted strings in scss & css

See original GitHub issue

Hey,

I noticed that all strings end up being unquoted, for example:

textCase: {
  value: "uppercase"
}

Will show up in the css file as:

  --body-text-case: uppercase;

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
lukasoppermanncommented, Sep 24, 2020

Hey @tonyjwalt I think this is an interesting solution for me.

@dbanksdesign to clarify where I am coming from.

I am currently working on a figma design token export plugin. I would like to ideally export a json file that can be converted by style-dictionary without any additional magic from my side.

CTI seems a bit limiting, as by default in Figma things like font styles include sizes, fonts and other things. If I understand you correct, I would have to include the “font-family” under the specific category content while the fontSize would be under the category size. Is this correct?

Currently I have a json (before trying to transform it for style-dictionary) that looks like this:

"body": {
    "h3": {
      "description": null,
      "values": {
        "fontSize": {
          "value": 20,
          "unit": "pixels"
        },
        "textDecoration": {
          "value": "none"
        },
        "fontFamily": {
          "value": "Roboto"
        },
        "fontStyle": {
          "value": "Medium"
        },
        "letterSpacing": {
          "value": 2,
          "unit": "percent"
        },
        "lineHeight": {
          "value": 160.0000023841858,
          "unit": "percent"
        },
        "paragraphIndent": {
          "value": 5,
          "unit": "pixels"
        },
        "paragraphSpacing": {
          "value": 8,
          "unit": "pixels"
        },
        "textCase": {
          "value": "uppercase"
        }
      }
    }

I think it would make sense to have this converted into tokens like:

--font-body-h3-fontSize: 20px;
--font-body-h3-textDecoration: none;
--font-body-h3-fontFamily: "Roboto"; 

Does this make sense? Or am I missing something here?

1reaction
tonyjwaltcommented, Sep 23, 2020

CSS seemed to be an odd one for us because some strings cannot be wrapped in quotes, while it’s required for others. On my team we thought this behavior was a format thing, so we built a solution into our custom formatter. You can see that in PR 428 in the formatter file on line 32.

We applied a solution similar to what @dbanksdesign recommended, but used data-type on the attributes object instead of just type. We felt it was descriptive of an attribute of the token and this also allowed us to mix and match a token’s type with the type of data used to define it.

As @dbanksdesign said, there are several ways to solve it. I just thought I’d share what we did if it helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strings - Sass
You can convert a quoted string to an unquoted string using the string.unquote() function, and you can convert an unquoted string to a...
Read more >
SASS string to "non string" - css - Stack Overflow
I am running into an issue where map-get() is not able to find the appropriate value if a quoted string is used for...
Read more >
Working With Strings In Sass - Vanseo Design
That's how it generally works. The exception is interpolation ( #{} ), where all strings will become unquoted. [code type=css] $headline- ...
Read more >
Sass String Functions - W3Schools
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python,...
Read more >
Casting a string to a number in Sass - Kitty Giraudel
Needless to say I found a solution! Even better, I found a solution to convert a string into a valid CSS length you...
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