Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Styling React components

Styling React components

CSS has come a long way from the inline styles in 96 to the inline styles in 2016, wait wut?

Let's take a journey and see what did we learn along the way and what's the best way to style your React components

Siddharth Kshetrapal

December 03, 2016
Tweet

More Decks by Siddharth Kshetrapal

Other Decks in Technology

Transcript

  1. There are only two hard things in Computer Science: cache

    invalidation and naming things. - Phil Karlton
  2. Learnings from 1996 - 2013 Language for writing styles -

    CSS Separation of content and styles in DOM Semantic HTML = Good names for elements Isolation Components Co-location
  3. Language for writing styles - CSS Separation of content and

    styles Semantic HTML = Good names for elements Isolation Components Co-location No :hover :focus! 1. The React documentation way - Inline Styles
  4. 1. The React documentation way - Inline Styles Language for

    writing styles - CSS Separation of content and styles Semantic HTML = Good names for elements Isolation Components Co-location Advanced logic
  5. Content (HTML), styling (CSS) and interactions (JS) in one file.

    If you’re using React, you have access to a more powerful construct than CSS class names, you have components - Micheal Chan, @chantastic What’s so great about co-location anyways?
  6. Content (HTML), styling (CSS) and interactions (JS) in one file.

    - Convenience - Independent entity - Include a component and everything just works™ - Share + reuse components across pages and applications What’s so great about co-location anyways?
  7. Language for writing styles - CSS Separation of content and

    styles Isolation Co-location Advanced logic 2. Radium - better inline styles
  8. 3. Good old CSS Language for writing styles - CSS

    Separation of content and styles Isolation Co-location Advanced logic
  9. 4. CSS Modules Language for writing styles - CSS Separation

    of content and styles Isolation Co-location Advanced logic
  10. 5. Aphrodite Language for writing styles - CSS Separation of

    content and styles Isolation Co-location Advanced logic Uses !important
  11. 6. Glamor Language for writing styles - CSS (beta) Separation

    of content and styles Isolation Co-location Advanced logic
  12. Language for writing styles - CSS Separation of content and

    styles Isolation Co-location Advanced logic Enforces container/presentation pattern 7. styled-components
  13. Real CSS Conventions over configuration (styled-components, zeit/next) Simple API -

    css constructor - attaches styles to highest element in render() Future/Feature request