object-to-css
object-to-css copied to clipboard
Added support for nested objects
Currently, if a css object has nested classes the resulting css will be [object Object]
This PR will process them correctly by recursively calling for any nested objects, building the nested selectors correctly.
Added isPlainObj util function, can modify to something simpler if needed.
Example usage
const sample_with_class = {
div: {
display: 'inline-flex',
appearance: 'none',
border: 'none',
},
'.title': {
fontSize: 32,
'font-weight': 700,
border: '0 solid transparent',
transformOrigin: 'center top',
'transform-origin': 'center top',
perspective: '1em',
},
}
const output = objToCss(sample_with_class)
/*
// Result
div:{display:inline-flex;appearance:none;border:none;}.title:{font-size:32px;font-weight:700px;border:0 solid transparent;transform-origin:center top;transform-origin:center top;perspective:1em;}'
// Formatted Result
div: {
display: inline-flex;
appearance: none;
border: none;
}
.title: {
font-size: 32px;
font-weight: 700px;
border: 0 solid transparent;
transform-origin: center top;
transform-origin: center top;
perspective: 1em;
}
*/
Sorry, took me a while to see this. This can be done at a higher level with a different package, since I want to just keep this simple. People may want different classnames for example, not sure.