| Interesting critique. I would highly suggest checking out template literals: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... Yeah styled.div is a function as you can check out in the mdn docs I linked, it's really cool stuff. Inheritance is done like: const List = styled.ul`
li {
padding: 10px;
}
`
const HeavyPaddedList = styled(List)`
li {
padding: 20px;
}
`
If you wanted to just change the li you'd have to: const ListItem = styled.li`
padding: 10px;
`
const HeavilyPaddedListItem = styled(ListItem)`
padding: 20px;
`
You're writing scss within the text blocks. You're correct that you need some understanding of JS.I've never worked with designers that wrote css, I'd also probably not trust them to do so (my own failings). I don't agree that it looks like an unholy mess (hyperbole may be lost on me), but I can see how it could be jarring at first look. I had a similar reaction when I looked at Relay (https://facebook.github.io/relay/), when they used literals for data fetching. |
So, yeah, you lose all the syntax highlighting etc. that comes with just writing normal CSS. I don't think it's unreasonable for a designer to object to that - how would you feel if you were presented with a build system that required you to write all your JavaScript inside one big string statement?
Maybe it's just me, but I don't find it intuitive at all. `styled` has properties for, I assume, every HTML tag? But it can also be called as a function for inheritance purposes? And that inherited call appears to use the same tag as its parent... but what if I want to reuse styles across different tags? How could I define some shared CSS properties I'd use across different elements?
Don't get me wrong, it is cool stuff. But it also feels far too much like hand-wavey magic stuff. I've literally never used Vue before, but looking at this page:
https://vuejs.org/v2/guide/single-file-components.html
I have zero confusion about how to write styles for it. And I really don't understand why styled-components would be worth the extra effort by comparison. What does it bring to the table? It's different without a compelling reason for being different.