css-in-js - andrii los (20.10.2017)

22
I'm Andrii Los, Frontend Engineer at ITV Project GitHub: RIP21 Twitter: @RIP212

Upload: grand-parade-poland

Post on 21-Jan-2018

383 views

Category:

Technology


0 download

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