This repository has been archived by the owner on Mar 23, 2023. It is now read-only.
Convert components to use LESS compiled into style attrs #149
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Status: Opened for discussion
Reviewers: None yet
Notes
After having weighed the options, I felt like this deserved some exploration. The demos are using global CSS, which kind of goes away from the same idea for proposing HTML in JS. Then there's some which seem to be compiling and injecting style tags on a per-component basis or something (seems like Instagram). That's where vjeux comes in with inline styles. Which generally I like because we have interoperability with other interfaces (React Native now, maybe games or wearables in the future - Unreal Engine, Hololens). Whichever way Facebook moves, I feel like there's going to be a demand for some sort of utility library around styling. Things like vendor prefixing, validating properties, and generally just making it easier to style. If we have a system around something that's already quite mainstream like LESS, it should be easier to adopt. While this system may not be as fast as straight style objects, it still compiles down into the same thing. I'm not sure the performance is going to be noticeably impacted. It needs to be explored, as I know UI performance is one of the goals of React people. I'd love to explore this some more with somebody :)
I did try transforming the string into an AST in place, but it was too large and required some work hooking up the right classes. Similar to GraphQL, I gather.
There is actually some additional magic going on here — our transform pipeline actually embeds the AST directly (as JavaScript objects) in place of the template — but generally developers won't need to worry about that at all.
TODO
styles.find('#todo-list li.edit')
and it'll return all rules that match that selector, including#todo-list li.edit {}
,#todo-list li {}
andli {}
.Changes
How to test
npm start
afternpm install
and you should see something like this: