Slide 1

Slide 1 text

Why we should write KL React Meetup CSS in JS

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

I’m the one who use it first… use other class name, or …

Slide 6

Slide 6 text

SaSS / ScSS Preprocessor that is compiled to CSS Mixins Variables Functions Extend + + + = Awesome CSS, but…..

Slide 7

Slide 7 text

Conventions OOCSS SMACSS BEM C-BEUT ITCSS Object Oriented CSS Scalable Modular Architecture CSS Block Element Modifier Cascade, Block, Element, Utility and Token Inverted Triangle CSS Nicole Sullivan Jonathan Snook Yandex Andy Bell Harry Roberts

Slide 8

Slide 8 text

SaSS + BEM image taken from https://medium.com/@ZeeCoder/a-practical-introduction-to-the-bem-css-methodology-eeef578bac8c

Slide 9

Slide 9 text

External libraries 3rd party plugins CSS framework Breaking the Convention

Slide 10

Slide 10 text

Scoped / Local Stylesheet Encapsulated CSS Web Components

Slide 11

Slide 11 text

“Revolution Isn’t Smashing Something It Is Bringing Forth” Joseph Campbell (American writer)

Slide 12

Slide 12 text

css in JS? $(‘.domNodeClassName’).css({paddingTop: 20, color: red}) $(‘.domNodeClassName’).setStyle({paddingTop: 20, color: red}) domStyle(domNode, {paddingTop: 20, color: red}) Cool but no pseudo & media queries

Slide 13

Slide 13 text

Aphrodite Styletron CXS emotion CSS-in-JS movement “I knew it was going to be controversial but I had absolutely no idea that it would generate an entire movement of people building out libraries around it” vjeux

Slide 14

Slide 14 text

Stop using it! It’s almost like saying “we’re doing everything in JS” gives developers permission to flush a few decades’ worth of HTML/CSS best practices down the toilet Brad Frost The creator of Atomic Design Please aren’t saying “CSS is broken” because of browser bugs. They are saying it because they don’t understand CSS & want it to be like JS. Jen Simmons Member of the CSS Working Group CSS-in-JS is a cry for help Lea Verou Invited Expert to the CSS Working Group

Slide 15

Slide 15 text

Stop using it! It’s almost like saying “we’re doing everything in JS” gives developers permission to flush a few decades’ worth of HTML/CSS best practices down the toilet Brad Frost The creator of Atomic Design Please aren’t saying “CSS is broken” because of browser bugs. They are saying it because they don’t understand CSS & want it to be like JS. Jen Simmons Member of the CSS Working Group CSS-in-JS is a cry for help Lea Verou Invited Expert to the CSS Working Group help best practices css is broken

Slide 16

Slide 16 text

Use it, but…. Does CSS-in-JS scare me? Yes, of course. But not because it’s wrong. It’s because that evolution renders my detailed knowledge of the cascade obsolete. If you really love CSS, than it shouldn’t matter if you writing in its own file, a function, js, a string…. Nicole Sullivan Frameworks PM, Google Chrome, Creator of OOCSS Adam Argley Chrome CSS Developer Advocate at Google I’ve seen talks from prominent figures in the CSS- in-JS community, and I think that they definitely address real problems, and I’m glad that they’re working on solutions, but I’m still not sold. Harry Roberts invited Google Developer Expert

Slide 17

Slide 17 text

Use it, but…. Does CSS-in-JS scare me? Yes, of course. But not because it’s wrong. It’s because that evolution renders my detailed knowledge of the cascade obsolete. If you really love CSS, than it shouldn’t matter if you writing in its own file, a function, js, a string…. Nicole Sullivan Frameworks PM, Google Chrome, Creator of OOCSS Adam Argley Chrome CSS Developer Advocate at Google I’ve seen talks from prominent figures in the CSS- in-JS community, and I think that they definitely address real problems, and I’m glad that they’re working on solutions, but I’m still not sold. Harry Roberts invited Google Developer Expert But not because it’s wrong If you really love CSS they definitely address real problems

Slide 18

Slide 18 text

You should use it By moving from mere convention towards enforcing locally-scoped styles by default, we’ve now improved the baseline quality of our styles. Primarily, CSS-in-JS boosts my confidence. I can add, change and delete CSS without any unexpected consequences. Mark Dalgleish CSS-modules co-creator Max Stoiber Styled-component co-creator Ideally, I'd like CSS-in-JS to become a proving ground for new ideas, that can get subsumed into future CSS specs, the way Sass has done Glen Maddern Styled-component & CSS-modules co-creator

Slide 19

Slide 19 text

You should use it By moving from mere convention towards enforcing locally-scoped styles by default, we’ve now improved the baseline quality of our styles. Primarily, CSS-in-JS boosts my confidence. I can add, change and delete CSS without any unexpected consequences. Mark Dalgleish CSS-modules co-creator Max Stoiber Styled-component co-creator Ideally, I'd like CSS-in-JS to become a proving ground for new ideas, that can get subsumed into future CSS specs, the way Sass has done Glen Maddern Styled-component & CSS-modules co-creator by default unexpected consequences future CSS specs

Slide 20

Slide 20 text

Should us?

Slide 21

Slide 21 text

Same CSS but free from style conflicts Frustrations of the class name collisions and specificity wars

Slide 22

Slide 22 text

state-based styling API to describe state-based styles in a better way than using a bunch of conditional class names

Slide 23

Slide 23 text

Critical rendering styles Send only the critical CSS to the user for a rapid first paint

Slide 24

Slide 24 text

Single File Component By eliminate the source order, SFC pattern is possible. For small component, this pattern is very handy.

Slide 25

Slide 25 text

Inline styling Yes! with pseudos and media queries

Slide 26

Slide 26 text

Utility components serves as a wrapper component for most of the CSS utility needs.

Slide 27

Slide 27 text

Reusability Reuse component

Slide 28

Slide 28 text

Reusability Reuse ruleset const StyledButton = styled.button` ${props => props.disabled && css` ${disabled} ` ` const StyledContainer = styled(Box)` overflow: auto; max-height: 300px; ${customScrollbar} `

Slide 29

Slide 29 text

Conclusion • Component styles should be scoped and isolated by default to its component. • Conventions is unwritten law that doesn’t enforce people to obey it. • CSS-in-JS is a solution for real problems. • CSS with combination of JS offered cool out-of-the-box features. You should write CSS in JS!

Slide 30

Slide 30 text

Thank you! • https://github.com/abumuawiyah/react-meetup-24oct19 • https://speakerdeck.com/aziziyazit/why-we-should-write- css-in-js.