css in react - the good, the bad, and the ugly

140

Upload: joe-seifi

Post on 22-Mar-2017

106 views

Category:

Engineering


4 download

TRANSCRIPT

Page 1: CSS in React - The Good, The Bad, and The Ugly
Page 2: CSS in React - The Good, The Bad, and The Ugly

JOE SEIFI

@joeseifi

Page 3: CSS in React - The Good, The Bad, and The Ugly
Page 4: CSS in React - The Good, The Bad, and The Ugly
Page 5: CSS in React - The Good, The Bad, and The Ugly
Page 6: CSS in React - The Good, The Bad, and The Ugly

Today’s Plan

Page 7: CSS in React - The Good, The Bad, and The Ugly
Page 8: CSS in React - The Good, The Bad, and The Ugly
Page 9: CSS in React - The Good, The Bad, and The Ugly
Page 10: CSS in React - The Good, The Bad, and The Ugly
Page 11: CSS in React - The Good, The Bad, and The Ugly
Page 12: CSS in React - The Good, The Bad, and The Ugly
Page 13: CSS in React - The Good, The Bad, and The Ugly

COMPONENT

REACT

CSS

Page 14: CSS in React - The Good, The Bad, and The Ugly

COMPONENT

REACT

Page 15: CSS in React - The Good, The Bad, and The Ugly

CSS…

Page 16: CSS in React - The Good, The Bad, and The Ugly

GOOD

Page 17: CSS in React - The Good, The Bad, and The Ugly

FamiliarityGOOD

Page 18: CSS in React - The Good, The Bad, and The Ugly

FamiliarityMatured browser support

GOOD

From caniuse.com

Page 19: CSS in React - The Good, The Bad, and The Ugly

FamiliarityMatured browser supportContinuous growth

GOOD

Page 20: CSS in React - The Good, The Bad, and The Ugly

FamiliarityMatured browser supportContinuous growth

GOOD

BAD Naming

Page 21: CSS in React - The Good, The Bad, and The Ugly

FamiliarityMatured browser supportContinuous growth

GOOD

BAD NamingNot DRY

Page 22: CSS in React - The Good, The Bad, and The Ugly

FamiliarityMatured browser supportContinuous growth

GOOD

BAD NamingNot DRY Developer Experience

Page 23: CSS in React - The Good, The Bad, and The Ugly

FamiliarityMatured browser supportContinuous growth

GOOD

BAD NamingNot DRY Developer ExperienceDOM updates require JS

Page 24: CSS in React - The Good, The Bad, and The Ugly

FamiliarityMatured browser supportContinuous growth

GOOD

BAD NamingNot DRY Developer ExperienceDOM updates require JS

UGLY Globals

Page 25: CSS in React - The Good, The Bad, and The Ugly

FamiliarityMatured browser supportContinuous growth

GOOD

BAD NamingNot DRY Developer ExperienceDOM updates require JS

UGLY GlobalsCascades

Page 26: CSS in React - The Good, The Bad, and The Ugly

FamiliarityMatured browser supportContinuous growth

GOOD

BAD NamingNot DRY Developer ExperienceDOM updates require JS

UGLY GlobalsCascadesSpecificity

Page 27: CSS in React - The Good, The Bad, and The Ugly

FamiliarityMatured browser supportContinuous growth

GOOD

BAD NamingNot DRY Developer ExperienceDOM updates require JS

UGLY GlobalsCascadesSpecificitySource Order

Page 28: CSS in React - The Good, The Bad, and The Ugly

BAD Naming Not DRY Developer Experience DOM updates require JS

Familiarity Matured browser support Continuous growth

GOOD

UGLY Globals Cascades Specificity Source Order

IDEAL FEATURES FOR CSS IN REACT FRAMEWORKS

Page 29: CSS in React - The Good, The Bad, and The Ugly

BAD Naming Not DRY Developer Experience DOM updates require JS

Familiarity Matured browser support Continuous growth

GOOD

UGLY Globals Cascades Specificity Source Order

IDEAL FEATURES FOR CSS IN REACT FRAMEWORKS

Components with local CSS

Optional global CSS

Page 30: CSS in React - The Good, The Bad, and The Ugly

BAD Naming Not DRY Developer Experience DOM updates require JS

Familiarity Matured browser support Continuous growth

GOOD

UGLY Globals Cascades Specificity Source Order

Full CSS support

Server side rendering / Extract CSS

IDEAL FEATURES FOR CSS IN REACT FRAMEWORKS

Components with local CSS

Optional global CSS

Page 31: CSS in React - The Good, The Bad, and The Ugly

BAD Naming Not DRY Developer Experience DOM updates require JS

Familiarity Matured browser support Continuous growth

GOOD

UGLY Globals Cascades Specificity Source Order

Full CSS support

Server side rendering / Extract CSS

No dead CSS

Themes

Debugging in DevTools

Linting & syntax highlighting

Automatic vendor prefixing

IDEAL FEATURES FOR CSS IN REACT FRAMEWORKS

Components with local CSS

Optional global CSS

Page 32: CSS in React - The Good, The Bad, and The Ugly
Page 33: CSS in React - The Good, The Bad, and The Ugly
Page 34: CSS in React - The Good, The Bad, and The Ugly

React with CSS Loader

Page 35: CSS in React - The Good, The Bad, and The Ugly

.btn

btn:hover

btn.depressed

React with CSS Loader

Page 36: CSS in React - The Good, The Bad, and The Ugly

React with CSS Loader

Page 37: CSS in React - The Good, The Bad, and The Ugly

React with CSS Loader

Page 38: CSS in React - The Good, The Bad, and The Ugly

React with CSS Loader

Page 39: CSS in React - The Good, The Bad, and The Ugly

React with CSS Loader

Page 40: CSS in React - The Good, The Bad, and The Ugly

React with CSS Loader

Page 41: CSS in React - The Good, The Bad, and The Ugly

React with CSS Loader

Page 42: CSS in React - The Good, The Bad, and The Ugly

React with CSS Loader

Page 43: CSS in React - The Good, The Bad, and The Ugly

React with CSS Loader

Page 44: CSS in React - The Good, The Bad, and The Ugly

React with CSS Loader

Page 45: CSS in React - The Good, The Bad, and The Ugly

React with CSS Loader

Page 46: CSS in React - The Good, The Bad, and The Ugly

React with CSS Loader

Page 47: CSS in React - The Good, The Bad, and The Ugly

React with CSS Loader

Page 48: CSS in React - The Good, The Bad, and The Ugly

React with CSS Loader

Page 49: CSS in React - The Good, The Bad, and The Ugly
Page 50: CSS in React - The Good, The Bad, and The Ugly

React with Inline Styles

Page 51: CSS in React - The Good, The Bad, and The Ugly

styles.btn

:hover

styles.btn.depressed

React with Inline Styles

Page 52: CSS in React - The Good, The Bad, and The Ugly

styles.btn

:hover

styles.btn.depressed

React with Inline Styles

Page 53: CSS in React - The Good, The Bad, and The Ugly

styles.btn

:hover

styles.btn.depressed

React with Inline Styles

Page 54: CSS in React - The Good, The Bad, and The Ugly

styles.btn

:hover

styles.btn.depressed

React with Inline Styles

Page 55: CSS in React - The Good, The Bad, and The Ugly

styles.btn

:hover

styles.btn.depressed

X

React with Inline Styles

Page 56: CSS in React - The Good, The Bad, and The Ugly

React with Inline Styles

Page 57: CSS in React - The Good, The Bad, and The Ugly

React with Inline Styles

Page 58: CSS in React - The Good, The Bad, and The Ugly

React with Inline Styles

Page 59: CSS in React - The Good, The Bad, and The Ugly

React with Inline Styles

Page 60: CSS in React - The Good, The Bad, and The Ugly
Page 61: CSS in React - The Good, The Bad, and The Ugly

Radium

Page 62: CSS in React - The Good, The Bad, and The Ugly

css pseudoclasses &elements

:active

:focus

:hover

Radium

Page 63: CSS in React - The Good, The Bad, and The Ugly

:any

:checked

:default

:dir()

:disabled

:empty

:enabled

:first

:first-child

:first-of-type

:fullscreen

:indeterminate

:in-range

:invalid

:lang()

:last-child

:last-of-type

:left

:link

:not()

:nth-child()

:nth-last-child()

:nth-last-of-type()

:nth-of-type()

:only-child

:only-of-type

:optional

:out-of-range

:read-only

:read-write

:required

:right

:root

:scope

:target

:valid

:visited

::after

::before

::first-letter

::first-line

::selection

::backdrop

::placeholder

::marker

::spelling-error

::grammar-error

css pseudoclasses &elements

:active

:focus

:hover

Radium

Page 64: CSS in React - The Good, The Bad, and The Ugly

styles.btn

‘:hover’

styles.btn.depressed

Radium

Page 65: CSS in React - The Good, The Bad, and The Ugly

styles.btn

‘:hover’

styles.btn.depressed

Radium

Page 66: CSS in React - The Good, The Bad, and The Ugly

styles.btn

‘:hover’

styles.btn.depressed

Radium

Page 67: CSS in React - The Good, The Bad, and The Ugly

Radium

Page 68: CSS in React - The Good, The Bad, and The Ugly

Radium

Page 69: CSS in React - The Good, The Bad, and The Ugly

Radium

Page 70: CSS in React - The Good, The Bad, and The Ugly
Page 71: CSS in React - The Good, The Bad, and The Ugly

5,037

Page 72: CSS in React - The Good, The Bad, and The Ugly

ShoppingCart.js

VideoItem.js

global.css

Button.jsbutton.css

shopping-cart.cssShoppingCart.js

VideoItem.js video-item.css

button.js

Separation of Concerns

Page 73: CSS in React - The Good, The Bad, and The Ugly

ShoppingCart.js

VideoItem.js

global.css

Button.js

Languages

button.css

shopping-cart.cssShoppingCart.js

VideoItem.js video-item.css

button.js

Separation of Concerns

Page 74: CSS in React - The Good, The Bad, and The Ugly

ShoppingCart.js

VideoItem.js

global.css

Button.js

Languages Separation of Functionality

button.css

shopping-cart.cssShoppingCart.js

VideoItem.js video-item.css

button.js

Separation of Concerns

button.cssbutton.js

Page 75: CSS in React - The Good, The Bad, and The Ugly

ShoppingCart.js

VideoItem.js

global.css

Button.js

Languages Separation of Functionality

button.css

shopping-cart.cssShoppingCart.js

VideoItem.js video-item.css

button.js

Separation of Concerns

Page 76: CSS in React - The Good, The Bad, and The Ugly

ShoppingCart.js

VideoItem.js

global.css

Button.js

Languages Separation of Functionality

ShoppingCart.js

VideoItem.js

button.js

Separation of Concerns

Page 77: CSS in React - The Good, The Bad, and The Ugly

Aphrodite

Page 78: CSS in React - The Good, The Bad, and The Ugly

Regular Inline Styles

Aphrodite

Page 79: CSS in React - The Good, The Bad, and The Ugly

Regular Inline Styles Aphrodite Wraps Styles Object

Aphrodite

Page 80: CSS in React - The Good, The Bad, and The Ugly

Regular Inline Styles Aphrodite Wraps Styles Object

Aphrodite

Page 81: CSS in React - The Good, The Bad, and The Ugly

Rendered

Regular Inline Styles Aphrodite Wraps Styles Object

Aphrodite

Page 82: CSS in React - The Good, The Bad, and The Ugly

Rendered

Regular Inline Styles Aphrodite Wraps Styles Object

Aphrodite

Page 83: CSS in React - The Good, The Bad, and The Ugly

Rendered

Regular Inline Styles Aphrodite Wraps Styles Object

Aphrodite

Output

Page 84: CSS in React - The Good, The Bad, and The Ugly

Aphrodite

Page 85: CSS in React - The Good, The Bad, and The Ugly

Aphrodite

Page 86: CSS in React - The Good, The Bad, and The Ugly

Aphrodite

Page 87: CSS in React - The Good, The Bad, and The Ugly

Aphrodite

Page 88: CSS in React - The Good, The Bad, and The Ugly

5,037

2,627

Page 89: CSS in React - The Good, The Bad, and The Ugly

React CSS Modules

Page 90: CSS in React - The Good, The Bad, and The Ugly

React CSS Modules

}

Original .button CSS

Page 91: CSS in React - The Good, The Bad, and The Ugly

.button_btn_18iwj {

}

{ btn: “button_btn_18iwj” }

Generated CSS

JS maps classnames

React CSS Modules

}

Original .button CSS

Page 92: CSS in React - The Good, The Bad, and The Ugly

.button_btn_18iwj {

}

{ btn: “button_btn_18iwj” }

Generated CSS

JS maps classnames

React CSS Modules

}

Original .button CSS

Page 93: CSS in React - The Good, The Bad, and The Ugly

.button_btn_18iwj {

}

{ btn: “button_btn_18iwj” }

Generated CSS

JS maps classnames

React CSS Modules

}

Original .button CSS

Page 94: CSS in React - The Good, The Bad, and The Ugly

React CSS Modules

Page 95: CSS in React - The Good, The Bad, and The Ugly

React CSS Modules

Page 96: CSS in React - The Good, The Bad, and The Ugly

React CSS Modules

Page 97: CSS in React - The Good, The Bad, and The Ugly

React CSS Modules

Page 98: CSS in React - The Good, The Bad, and The Ugly

React CSS Modules

Page 99: CSS in React - The Good, The Bad, and The Ugly

React CSS Modules

Page 100: CSS in React - The Good, The Bad, and The Ugly

React CSS Modules

Page 101: CSS in React - The Good, The Bad, and The Ugly

React CSS Modules

Page 102: CSS in React - The Good, The Bad, and The Ugly

React CSS Modules

Page 103: CSS in React - The Good, The Bad, and The Ugly

5,037

2,627

3,414

Page 104: CSS in React - The Good, The Bad, and The Ugly

Styletron

Page 105: CSS in React - The Good, The Bad, and The Ugly

Styletron

Source style objects

Generated CSS

{ color: ‘#ec4800’ font: ‘bold 32px’ }

Page 106: CSS in React - The Good, The Bad, and The Ugly

Styletron

Source style objects

Generated CSS

{ font: ‘bold 32px’ text-align: ‘center’ }

{ color: ‘#ec4800’ font: ‘bold 32px’ }

Page 107: CSS in React - The Good, The Bad, and The Ugly

Styletron

Source style objects

Generated CSS

{ font: ‘bold 32px’ text-align: ‘center’ }

{ color: ‘#ec4800’ font: ‘bold 32px’ }

{ text-align: ‘center’ color: ‘#ec4800’ }

Page 108: CSS in React - The Good, The Bad, and The Ugly

Styletron

Source style objects

Generated CSS

{ font: ‘bold 32px’ text-align: ‘center’ }

{ color: ‘#ec4800’ font: ‘bold 32px’ }

{ text-align: ‘center’ color: ‘#ec4800’ }

.a { color: #ec4800 }

.b { font: bold 32px }

.c { text-align: center }

Page 109: CSS in React - The Good, The Bad, and The Ugly

Styletron

Source style objects

Generated CSS

{ font: ‘bold 32px’ text-align: ‘center’ }

{ color: ‘#ec4800’ font: ‘bold 32px’ }

{ text-align: ‘center’ color: ‘#ec4800’ }

.a { color: #ec4800 }

.b { font: bold 32px }

.c { text-align: center }

Page 110: CSS in React - The Good, The Bad, and The Ugly

Styletron

Source style objects

Generated CSS

{ font: ‘bold 32px’ text-align: ‘center’ }

{ color: ‘#ec4800’ font: ‘bold 32px’ }

{ text-align: ‘center’ color: ‘#ec4800’ }

.a { color: #ec4800 }

.b { font: bold 32px }

.c { text-align: center }

Page 111: CSS in React - The Good, The Bad, and The Ugly

Styletron

Source style objects

Generated CSS

{ font: ‘bold 32px’ text-align: ‘center’ }

{ color: ‘#ec4800’ font: ‘bold 32px’ }

{ text-align: ‘center’ color: ‘#ec4800’ }

.a { color: #ec4800 }

.b { font: bold 32px }

.c { text-align: center }

“a b”

“b c”

“b a”

Page 112: CSS in React - The Good, The Bad, and The Ugly

Styletron

Source style objects

Generated CSS

6 Rules

3 Rules

{ font: ‘bold 32px’ text-align: ‘center’ }

{ color: ‘#ec4800’ font: ‘bold 32px’ }

{ text-align: ‘center’ color: ‘#ec4800’ }

.a { color: #ec4800 }

.b { font: bold 32px }

.c { text-align: center }

“a b”

“b c”

“b a”

Page 113: CSS in React - The Good, The Bad, and The Ugly

.a

.b

.c

.d

.e

.f

.g

.h

.i

.j

.l

.btn

.btn:hover

.btn.depressed

Styletron

.a .b .c .d .e .f .g .h .i .j .j .k .l

.l:hover

.m .n .o

Page 114: CSS in React - The Good, The Bad, and The Ugly

.a

.b

.c

.d

.e

.f

.g

.h

.i

.j

.l

.btn

.btn:hover

.btn.depressed

Styletron

.a .b .c .d .e .f .g .h .i .j .j .k .l

.l:hover

.m .n .o

Page 115: CSS in React - The Good, The Bad, and The Ugly

Styletron

Page 116: CSS in React - The Good, The Bad, and The Ugly

Styletron

Page 117: CSS in React - The Good, The Bad, and The Ugly

Styletron

Page 118: CSS in React - The Good, The Bad, and The Ugly

5,037

2,627

3,414

1,472

Page 119: CSS in React - The Good, The Bad, and The Ugly

Styled Components

Page 120: CSS in React - The Good, The Bad, and The Ugly

JSHTMLElement

React Styled Components

Page 121: CSS in React - The Good, The Bad, and The Ugly

HTMLElementReact Component

React Styled Components

Page 122: CSS in React - The Good, The Bad, and The Ugly

HTMLElement StylesHTML

ElementReact Component

React Styled Components

Page 123: CSS in React - The Good, The Bad, and The Ugly

HTMLElement

HTMLElementStyled ComponentReact Component

React Styled Components

Page 124: CSS in React - The Good, The Bad, and The Ugly

Styled Components

StylesElement

Styled Component

Page 125: CSS in React - The Good, The Bad, and The Ugly

Styled Components

StylesElementElement

Styled Component

Page 126: CSS in React - The Good, The Bad, and The Ugly

Styled Components

StylesElement Styles

Styled Component

Page 127: CSS in React - The Good, The Bad, and The Ugly

Styled Components

StylesElement Styles

Styled Component

StyledButton

Page 128: CSS in React - The Good, The Bad, and The Ugly

Styled Components

StyledButton

Page 129: CSS in React - The Good, The Bad, and The Ugly

Styled Components

Rendered

StyledButton

Page 130: CSS in React - The Good, The Bad, and The Ugly

Styled Components

Output

Rendered

StyledButton

Page 131: CSS in React - The Good, The Bad, and The Ugly

Styled Components

Output

Rendered

StyledButton

Page 132: CSS in React - The Good, The Bad, and The Ugly

Styled Components

Page 133: CSS in React - The Good, The Bad, and The Ugly

5,037

2,627

3,414

1,472

5,174

Page 134: CSS in React - The Good, The Bad, and The Ugly

CSS IN REACT InnovationsNow & Future

Page 135: CSS in React - The Good, The Bad, and The Ugly

CSS IN REACT InnovationsNow & Future

CSS3 Variables

Page 136: CSS in React - The Good, The Bad, and The Ugly

CSS IN REACT InnovationsNow & Future

Typed CSS

Page 137: CSS in React - The Good, The Bad, and The Ugly

CSS IN REACT InnovationsNow & Future

Web Components

Page 138: CSS in React - The Good, The Bad, and The Ugly

CSS IN REACT InnovationsNow & Future

Vue.js & Scoped Styles

Page 139: CSS in React - The Good, The Bad, and The Ugly

- Bret Victor

Technology changes quickly, people’s minds change slowly. So it’s easy to adopt new technologies, it can be

hard to adopt new ways of thinking.

Page 140: CSS in React - The Good, The Bad, and The Ugly

Q&A

@joeseifi • https://github.com/joeshub/css-in-react