3 ms·
I'm not 100% what this is exactly... Care to clear it up a bit? At first I though this is for those situations where you find yourself urged to modify the css
by onli 10y ago
I'm not 100% what this is exactly... Care to clear it up a bit?
At first I though this is for those situations where you find yourself urged to modify the css in your javascript. But looking at the documentation, this seems to be a way to write the complete CSS in JS, and then to have it compiled into CSS. Do I understand that wrong? If not: Why would one want that?
- kej 10y agoI imagine it's the same appeal as wanting to run JavaScript on the server. The more things you can do in one language, the fewer times you have to switch from thinking in one language to another.
- scaryclam 10y agoTo me, this is like trying to use a hammer for nails, screws and painting. Use the right tools for the job at hand. Don't know how to hang dry wall? It's ok to get help!
- nilliams 10y agoNot really that simple. People like myself learnt CSS back in the day, and modern CSS systems like BEM, and Sass/LESS and friends, (I love Sass), yet still see the benefits of CSS-in-JS for certain kinds of 'component-based apps' (not every site). See [0] for some of the reasonings behind CSS-in-JS. [0] https://speakerdeck.com/vjeux/react-css-in-js https://speakerdeck.com/vjeux/react-css-in-js
- kej 10y agoI think that's a fair point, but I'd say it's more like wanting to use the tools in your pocket knife instead of getting an actual screw driver or set of pliers. No, it's not as good as the real thing, but you can save time by using the slightly inferior version that's already at hand.
- mxstbr 10y agoYes, this is kinda like the "lodash" for writing styles in JavaScript. The main goal with writing styles in JavaScript is to make CSS work in the context of component-based systems. The language is magnificent, but it was made in an age where the web consisted of documents. These days we're building rich, interactive, client-side user interfaces with the same language, but it's standing in our way. That's why there has been a lot of exploration, especially in the React ecosystem, around putting styles in JavaScript. I'd encourage you to take a look at these magnificent resources which I cannot do justice in a single comment: - The talk that kicked it all off: "CSS in JS" by vjeux[0] (made React Native, works at Facebook) - "Rendering Khan Academys Learn Menu Whereever I Please" [1] - "Scale FUD and style components" [2] and a bunch of other talks and articles if you google "CSS in JS". [0]: https://speakerdeck.com/vjeux/react-css-in-js https://speakerdeck.com/vjeux/react-css-in-js [1]: https://medium.com/@jdan/rendering-khan-academys-learn-menu-wherever-i-please-4b58d4a9432d#.w9nshye05 https://medium.com/@jdan/rendering-khan-academys-learn-menu-... [2]: https://medium.learnreact.com/scale-fud-and-style-components-c0ce87ec9772#.kzjba8lcg https://medium.learnreact.com/scale-fud-and-style-components...
- onli 10y agoThe idea of writing CSS in JS is horrible to me. But I'm coming from a completely different developer camp, and find the vjeux talk completely unconvincing, so that does not mean much :) And with your comment it is clearer now where this might be useful. Maybe add a "How to use this" section describing possible workflows to the Readme? Also I run into situations where my js produces inline css, and a lodash style lib for that could be useful. Thanks for the answer, congratz for launching!
- mxstbr 10y agoThanks for the kind words, totally understand that this isn't for everybody. Definitely will work on improving the README, just needed to finally get this out of the door ;) Cheers!
- mbrookes 10y ago> this seems to be a way to write the complete CSS in JS, and then to have it compiled into CSS. That isn't what this is although I also had to poke around the source code to figure out what it is exactly. It's a set of mixins and utility functions that return a js object that is then used as input for either inline styles, or for one of the may CSS in JS libraries that convert do a JS object to CSS. As for how useful? Well, the color utilities seem to replicate what color.js does, so nothing new there. The mixins seem to be mostly about prefixing, and you're going to need to prefix the rest of your CSS-in-JS anyway - for which there are various standalone libraries, and plugins to the aforementioned libraries. The shorthands let you do things like: borderWidth('12px', '24px', '36px', '48px') => { 'border-top-width': '12px', 'border-right-width': '24px', 'border-bottom-width': '36px', 'border-left-width': '48px' } Thing is, I can already do that without the expansion: { 'borderWidth': '12px 24px 36px 48px' } As much as I respect the guys behind this, I'd question how useful it is overall.
- mxstbr 10y agoSorry it isn't clear to you, we could definitely do a better job with the README. If you look on the website[0] you'll see actual examples of usage. (I just announced this project on stage at ReactLondon during my talk, so it's very fresh and we haven't had a lot of time to clean up the docs yet) Basically, there is lots of styles in JavaScript libraries floating around, especially in the React ecosystem. The issue is that many people need Sass utility functions and mixins like lighten/darken/clearfix to be productive with their styling, and no real comprehensive "Compass for styles in JavaScript" exists—so this is it. We looked at a lot of existing JavaScript color libraries, but most of them have some sort of fluent API that is very different from the way CSS preprocessors handle these functions. This confuses people and makes the API hard to learn, so we decided to build our own that mimics the Sass API as closely as possible. (apart from being all curried functions that are composeable, which means switching some argument orders around) [0]: https://polished.js.org https://polished.js.org
- pygy_ 10y agoThis was a big missing piece of code in the CSS-in-JS world. Thanks for providing the stdlib (following SASS is definitely a great approach).