Transcript
Page 1: CSS-in-JS - Andrii Los (20.10.2017)

I'm Andrii Los,

Frontend Engineer at ITV Project

πŸ‘‹

GitHub: RIP21 Twitter: @RIP212

Page 2: CSS-in-JS - Andrii Los (20.10.2017)

πŸ’„CSS-in-JS πŸ’…Styling for component era web

Page 3: CSS-in-JS - Andrii Los (20.10.2017)

πŸ’© Problems of CSS

πŸ€– How they were addressed

πŸ’… CSS-in-JS features

πŸ€–β™€οΈ CSS-in-JS F.A.Q and its problems πŸ’©

πŸŽ‰ Future of CSS-in-JS

Page 4: CSS-in-JS - Andrii Los (20.10.2017)

Problems of CSS πŸ’©

πŸ’© Designed for documents not apps

πŸ’© Globally scoped

πŸ’© Hardly reusable

πŸ’© Leaking

πŸ’© Non-programmatic

πŸ’© Non-modular

πŸ’© CSS develops too slow

Page 5: CSS-in-JS - Andrii Los (20.10.2017)

How they were addressed πŸ€–

πŸ€– LESS

πŸ€– PostCSS

πŸ€– SASS

πŸ€– Stylus

πŸ€– CSS Modules

πŸ€– All above with Webpack loaders and plugins

Page 6: CSS-in-JS - Andrii Los (20.10.2017)

What problems were

preserved? πŸ’©

πŸ’© Non-modular out of the box

πŸ’© Still not componentized enough

πŸ’© Require a lot of class names manual work

πŸ’© Still global and can leak

πŸ’© Reusability still not perfect

Page 7: CSS-in-JS - Andrii Los (20.10.2017)

So what if we would like to

fix them all in one ultimate

solution? πŸ€–

Page 8: CSS-in-JS - Andrii Los (20.10.2017)

πŸ’„

Glorious

CSS-in-JS!

πŸ’…

Page 9: CSS-in-JS - Andrii Los (20.10.2017)

CSS-in-JS

πŸ’… styled-components

πŸ‘©πŸŽ€ emotion

πŸ’„ glamorous

Page 10: CSS-in-JS - Andrii Los (20.10.2017)

CSS rules definition

πŸ’… Template string literals

πŸ’„ Object React inline-styles notation

πŸ‘©πŸŽ€ Supports both

Page 11: CSS-in-JS - Andrii Los (20.10.2017)

So what the possibilities?

πŸŽ‰ Media queries

πŸŽ‰ Keyframes

πŸŽ‰ Pseudo classes

πŸŽ‰ Nested selectors

πŸŽ‰ It's JS, so you have all its power

πŸŽ‰ Babel and Webpack optimisations for production

πŸŽ‰ Total isolation if old global CSS approach is not used

πŸŽ‰ Easy theming support

Page 12: CSS-in-JS - Andrii Los (20.10.2017)

So what the possibilities?

πŸŽ‰ Full interoperability with existent CSS

πŸŽ‰ Inject global styles if you know what you are doing

πŸŽ‰ Full support for styling 3rd parties components

πŸŽ‰ Extend API for easily reuse styles

πŸŽ‰ react-primitives - React Native, React Sketch, etc.

πŸŽ‰ Endless of other powerful things that you can

come up with

Page 13: CSS-in-JS - Andrii Los (20.10.2017)

Main features demo πŸ€–

Page 14: CSS-in-JS - Andrii Los (20.10.2017)

What's the problems? πŸ’©

Page 15: CSS-in-JS - Andrii Los (20.10.2017)

πŸ’© Weak editors support?! It's just strings and objects!

πŸŽ‰ Nope! Webstorm, VS Code, Sublime Text, Atom support is there!

πŸ’© Formatting! I sure it's just highlights the text, but no formatting!

πŸŽ‰ Nope! Webstorm formats it perfectly. (Not sure about others though)

πŸ’© Meh! Then I won't use!

πŸŽ‰ Editors doesn't matter. Prettier is formatting CSS in template literals ;)

πŸ’© But we don't use it!

πŸ€–β™€οΈ What's wrong with you?! It's amazing!

πŸ’© I'm not impressed yet..... I need something. It's stupid to have CSS in JS!

πŸ€·β™€οΈ Okay, but what did you were saying about JSX a few years ago πŸ€–

πŸ’© PERFORMANCE!

Page 16: CSS-in-JS - Andrii Los (20.10.2017)

Well, you are a little correct πŸ’©

πŸ’© styled-components performance in unrealistic

benchmarks is very weak

πŸŽ‰ Good news. Emotion and glamorous have bench

performance only 5-10% slower than CSS Modules

πŸŽ‰ Real world apps performance is good for all

solutions

πŸŽ‰ There is a hacks to improve it even further if so

needed

Page 17: CSS-in-JS - Andrii Los (20.10.2017)

So, what you would

recommend?styled-components πŸ’…

Page 18: CSS-in-JS - Andrii Los (20.10.2017)

Why?

πŸ’… 11000 stars on GitHub, means lots of contributions

πŸ’… Supports React Native and other renderers

πŸ’… Amazing Jest and other test runners support

πŸ’… A lot of tooling is already done for it

πŸ’… Stylelint support (works for emotion as well)

πŸ’… The best documentation

πŸ’… Better performance - matter of time

Page 19: CSS-in-JS - Andrii Los (20.10.2017)

Future of CSS-in-JS

πŸ€– ISTF - Interoperable Style Transfer

Format (Even further performance

improvement, CSS-in-JS styles interop)

🀷 Extreme styles optimisations to reduce

amount of CSS code up to 30-60%

(depends on codebase size)

Page 20: CSS-in-JS - Andrii Los (20.10.2017)
Page 21: CSS-in-JS - Andrii Los (20.10.2017)

That's all folks! πŸ‘‹GitHub: RIP21 Twitter: @RIP212

Page 22: CSS-in-JS - Andrii Los (20.10.2017)

List of links and resources πŸ”—

β€’ Sandbox for this speech

β€’ A unified styled language @markdalgleish - MUST READ (pick on

CSS-in-JS by co-author of CSS Modules)

β€’ styled-components documentation

β€’ emotion documentation and full of perf demos of emotion in its

authors twitter

β€’ glamorous documentation

β€’ Amazing article about styled-components future and CSS-in-JS in

overall by one of the authors of s-c

β€’ Template string literals or Object notations, what to choose? Read

that


Top Related