Transform between CSS string and JS object
See original GitHub issueAre there any functions in emotion (either via api, or in the supporting code) that will accept a css string (or css file of classes and transform into a proper JS object? I see a few other libraries out there that do this, but if it can be done with emotion, this is a win.
For example, convert
foo {
background-color: black;
color: orange;
margin-top: 10px;
}
Into:
{
foo: {
backgroundColor: "black",
color: "orange",
marginTop: "10px"
}
}
I tried passing the string to css``, but it just transforms it into a string under a style
field.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Javascript / convert CSS style string into JS object
First split the string with ; as the separator, and then for each result split with : , placing the items in an...
Read more >Convert css string to object - CodePen
JS (Babel) ; 1. var myDynamicCSS = "color:#ffffff; background-color: #00ffbb; border-radius:20px;"; ; 2. ; 3. var myDynamicElement = document.querySelector('.my- ...
Read more >Convert css string to object - Banner Animation - GreenSock
Hey guys, I have a dynamic template, where you can input css into the XML feed, and the banner will read that on...
Read more >Express CSS with JavaScript Objects for CSS-in-JS Notation
We will build a small utility function that will convert the style object we declare to a string that can be applied to...
Read more >Converting a JavaScript Object to a String | HTML Goodies
Learn how to convert a JavaScript object to a string with three different JSON methods in this JavaScript web development tutorial.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
U can use
serializeStyles
from@emotion/serialize
:Not sure what is your exact use case and what do u plan to do with the converted object but this should be a good base for you to start working with: https://codesandbox.io/s/stupefied-tdd-j70vt?file=/src/index.js