css-in-js and drupal sitting in a tree… · 2019-04-11 · css-in-js and drupal sitting in a tree...

36
CSS-in-JS and Drupal sitting in a tree… John Albin Wilkins @JohnAlbin

Upload: others

Post on 28-Jun-2020

19 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

CSS-in-JS and Drupalsitting in a tree…

John Albin Wilkins @JohnAlbin

Page 2: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

CSS-in-JS and Drupal sitting in a tree…TALKING POINTS

© Amazee Labs 2019. All Rights Reserved.

1 How we picked a CSS-in-JS project

2 Why we picked CSS Modules

3 Cool features of CSS Modules

4 A quick configuration

Page 3: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

John Albin WilkinsSenior Front-end Developer

© Amazee Labs 2019. All Rights Reserved.

2017 Amazee Labs

2004 Drupal

1997 CSS

1993 Web

Page 4: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

@JohnAlbin, 2011

’dI ❤

Page 5: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

TRADITIONAL WEBSITEALL-IN-ONE

Page 6: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

TRADITIONAL WEBSITESass-ified

Page 7: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

DECOUPLED WEBSITEILLUSTRATED

"

Page 8: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

LET'S EXPLORE CSS-IN-JS

Page 9: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

68+ CSS-IN-JS PROJECTS:CHOOSE ONE

Aphroditebabel-plugin-css-in-js

babel-plugin-pre-style react-styled

classy

csjs

css-constructorcss-light

css-loadercss-ns

cssobj

cssx

cxs

emotion

es-css-modules

freestyler

glamor

glamorous

hyperstyles

i-css

electron-css

react-css-builder

j2c

react-css-componentsreact-css-modules

react-cssomreact-fela

react-free-style

react-inline-css

react-inline-style

react-inline

react-jss

react-look

react-native-web

react-statics-stylesreact-styl

react-style

react-styleable

react-stylematic

react-themereact-vstyle

reactcss

restyles

scope-styles

smart-css

stile

stilr

stylable

style-it

styled-components

styled-jsx

styletron-react

styling

superstyle

hiccup-css

typestyleuranium

Page 10: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

– CSS in a object literal ( JavaScript Object )

– CSS in a template literal ( JavaScript String )

– CSS in a file ( CSS File )

3 API APPROACHES:CHOOSE ONE

Page 11: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

CSS IN A OBJECT LITERALJAVASCRIPT OBJECT

Page 12: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

CSS IN A TEMPLATE LITERALJAVASCRIPT STRING

Page 13: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

CSS IN A FILECSS FILE

Page 14: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

FEATURE COMPARISONEVALUATION CRITERIA

CSS inobject literal

CSS intemplate literal

CSS infile

locally scoped class names

cross-component composition

dead code elimination

nested rulesets

sharedJS / CSS variables

multi-platform

JS projects only

JS projects only

$

Page 15: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS
Page 16: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

LOCALLY-SCOPED CLASS NAMESOLD RULES FOR BEM NAMING

.callToAction { }

.callToAction--title { }

.callToAction--link { }

.fancyList { }

.fancyList--title { }

.fancyList--link { }

callToAction.css fancyList.css

Page 17: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

LOCALLY-SCOPED CLASS NAMESNO MORE BEM RULES

.Wrapper { }

.Title { }

.Link { }

.Wrapper { }

.Title { }

.Link { }

callToAction.css fancyList.css

Page 18: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

LOCALLY-SCOPED CLASS NAMESi.e. ENSURE UNIQUE GLOBAL CLASS NAMES

. fdc03d { }

.79ec33 { }

.6e4c6d { }

.62e171 { }

.24c42e { }

.df8be2 { }

callToAction.css fancyList.css

Page 19: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

LOCALLY-SCOPED CLASS NAMESMAPPING KNOWN CLASS NAMES TO AUTO-GENERATED ONES

Page 20: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

CROSS-COMPONENT COMPOSITIONSHARING CSS ACROSS COMPONENTS

Page 21: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

● When you add a component to a page, it adds the HTML, CSS, JS, etc. to the page.

● When you DO NOT add a component to a page,the HTML, CSS, JS, etc. is NOT added to the page.

● The eslint-plugin-css-modules pluginwill find unused class names in your component.

DEAD-CODE ELIMINATIONAUTOMATIC REMOVAL OF UNUSED CSS

Page 22: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

NESTED RULESETSNO MORE DUPLICATE SELECTORS

Page 23: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

NESTED RULESETSNO MORE DUPLICATE SELECTORS

https://drafts.csswg.org/css-nesting-1

Page 24: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

WHY @NEST IS NEEDEDBROWSER PERFORMANCE AND LOOK-AHEAD PARSING

Page 25: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

SHARING CSS / JS VARIABLESWRITE VALUES ONCE, USE THEM EVERYWHERE

CSS, JS, or JSON My.CSS

importFrom

Page 26: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

SHARING CSS / JS VARIABLESWRITE VALUES ONCE, USE THEM EVERYWHERE

CSS, JS, or JSON My.CSS

exportTo

Page 27: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

SHARING CSS / JS VARIABLESWRITE VALUES ONCE, USE THEM EVERYWHERE

Page 28: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

MULTI-PLATFORM SUPPORTEVERY PLATFORM WORKS WITH CSS FILES

+ + +

+ANY CMS

ANY JS FRAMEWORK

OR + + +

+ +

Page 29: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

CSS Modules= webpack loader plugin

+ PostCSS

Page 30: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

POSTCSS.CONFIG.JSAMAZEE'S CONFIGURATION (WORK IN PROGRESS)

Page 31: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

EXPERIMENTAL CSS, TODAYpostcss-preset-env

https://cssdb.org

Page 32: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

@JohnAlbin, 2019

Page 33: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

THANK YOU

Page 34: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

QUESTIONS AND MAYBE ANSWERS

Page 35: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

Join us for contribution opportunities

Friday, April 12, 2019

Mentored

Contributions

9:00-18:00

Room: 602

First Time Contributor Workshop

General

Contributions

9:00-12:00

Room: 606

9:00-18:00

Room: 6A

#DrupalContributions

Page 36: CSS-in-JS and Drupal sitting in a tree… · 2019-04-11 · CSS-in-JS and Drupal sitting in a tree ... CMS ANY JS FRAMEWORK OR + + + + + CSS Modules = webpack loader plugin + PostCSS

What did you think?

Locate this session at the DrupalCon Seattle website:http://seattle2019.drupal.org/schedule

Take the Survey!https://www.surveymonkey.com/r/DrupalConSeattle