Slide 1

Slide 1 text

Adam Onishi Financial Times @onishiweb Planes, trains, and CSS components

Slide 2

Slide 2 text

FINANCIAL TIMES @onishiweb

Slide 3

Slide 3 text

@onishiweb

Slide 4

Slide 4 text

1. Unify front-end styles across the FT 2. Reduce time spent repeating work @onishiweb

Slide 5

Slide 5 text

Components! @onishiweb

Slide 6

Slide 6 text

http://registry.origami.ft.com/components o-header o-table o-card

Slide 7

Slide 7 text

http://origami.ft.com/

Slide 8

Slide 8 text

Building components @onishiweb

Slide 9

Slide 9 text

@onishiweb

Slide 10

Slide 10 text

@onishiweb

Slide 11

Slide 11 text

1. Automobiles 2. Trains 3. Planes

Slide 12

Slide 12 text

1. CSS 2. CSS Modules 3. Web Components

Slide 13

Slide 13 text

The CSS way…

Slide 14

Slide 14 text

The current way… @onishiweb

Slide 15

Slide 15 text

The Sass/LESS way @onishiweb

Slide 16

Slide 16 text

The BEM way @onishiweb

Slide 17

Slide 17 text

The SMACSS way @onishiweb

Slide 18

Slide 18 text

The OOCSS way @onishiweb

Slide 19

Slide 19 text

The Atomic CSS way @onishiweb

Slide 20

Slide 20 text

@onishiweb • Naming convention • Namespacing • Reduce specificity • Easy to understand • Require discipline

Slide 21

Slide 21 text

The Origami way… @onishiweb

Slide 22

Slide 22 text

The BEM way @onishiweb

Slide 23

Slide 23 text

Specificity must be minimised. Use BEM… Origami spec http://origami.ft.com/docs/syntax/scss/

Slide 24

Slide 24 text

An example: @onishiweb

Slide 25

Slide 25 text

@onishiweb

Slide 26

Slide 26 text

Slide 27

Slide 27 text

.o-gallery__figure {} .o-gallery__figure__image {} .o-gallery__figure__caption {}

Slide 28

Slide 28 text

.o-gallery__figure {} .o-gallery__figure__image {} .o-gallery__figure__caption {} // Better .o-gallery__figure {} .o-gallery__image {} .o-gallery__caption {}

Slide 29

Slide 29 text

.o-gallery__control { position: absolute; top: 50%; width: 30px; height: 70px; } .o-gallery__control--left { left: 0; background-image: url(''), none; } .o-gallery__control--right { right: 0; background-image: url(''), none; }

Slide 30

Slide 30 text

this.controlLeft = document.createElement('button'); this.controlLeft.className = 'o-gallery__control o-gallery__control-- left';

Slide 31

Slide 31 text

Using Origami components @onishiweb

Slide 32

Slide 32 text

@import "o-assets/main"; @import "o-colors/main"; @import "o-icons/main"; @import "o-hoverable/main"; @import "o-gallery/main";

Slide 33

Slide 33 text

require('o-date'); require('o-header'); require('o-gallery');

Slide 34

Slide 34 text

Alice Bartlett Origami Lead, Financial Times @alicebartlett Can’t you make it more like Bootstrap? Considerations for building front end systems

Slide 35

Slide 35 text

What about HTML? @onishiweb

Slide 36

Slide 36 text

Customisation @onishiweb

Slide 37

Slide 37 text

/// General styling for the gallery @mixin oGallery { [...] } /// Styling for the gallery title @mixin oGalleryTitle { [...] }

Slide 38

Slide 38 text

The Cascade @onishiweb

Slide 39

Slide 39 text

The current Origami way… @onishiweb

Slide 40

Slide 40 text

1. CSS 2. CSS Modules 3. Web Components

Slide 41

Slide 41 text

Remix culture

Slide 42

Slide 42 text

@onishiweb

Slide 43

Slide 43 text

The CSS Modules way…

Slide 44

Slide 44 text

What is CSS Modules? @onishiweb

Slide 45

Slide 45 text

[CSS where] all class names and animation names are scoped locally by default CSS Modules Spec https://github.com/css-modules/css-modules

Slide 46

Slide 46 text

.gallery { } .wrapper { } .content { } .slide { }

Slide 47

Slide 47 text

._gallery_1rsuk_1 { } ._wrapper_1rsuk_7 { } ._content_1rsuk_13 { } ._slide_1rsuk_25 { }

Slide 48

Slide 48 text

Values and composes @onishiweb

Slide 49

Slide 49 text

@value primary: red; .btn-primary { background: white; border: 1px solid primary; color: primary; }

Slide 50

Slide 50 text

@value aliceblue: red; @value relative: absolute;

Slide 51

Slide 51 text

.btn-primary { background: white; border: 1px solid red; color: red; } .btn-secondary { composes: btn-primary; border-color: blue; color: blue; }

Slide 52

Slide 52 text

Slide 53

Slide 53 text

Truly component only CSS @onishiweb

Slide 54

Slide 54 text

Requires a build step @onishiweb

Slide 55

Slide 55 text

@onishiweb • Webpack • Browserify • Babel • PostCSS • JSPM

Slide 56

Slide 56 text

An example: @onishiweb

Slide 57

Slide 57 text

@onishiweb

Slide 58

Slide 58 text

No more .html @onishiweb

Slide 59

Slide 59 text

  • # This is an image caption

Slide 60

Slide 60 text

CSS > JSON > HTML @onishiweb

Slide 61

Slide 61 text

What about the JavaScript? @onishiweb

Slide 62

Slide 62 text

this.controlLeft = document.createElement('button'); this.controlLeft.className = className('styles', 'control-left');

Slide 63

Slide 63 text

Great in a JavaScript world @onishiweb

Slide 64

Slide 64 text

Atomic CSS Modules @onishiweb

Slide 65

Slide 65 text

.M-10 { margin: 10px; } .Fl-start { float: left; } .Mend-10 { margin-right: 10px; } .Fz-s { font-size: smaller; }

Slide 66

Slide 66 text

.tabs { composes: width-100 from 'size'; composes: reset from 'list'; composes: flex from 'display'; /* tablet and up */ composes: block from 'display/tablet'; } .item { composes: inline-block from 'display'; composes: solid top-reset right-reset bottom left-reset from 'border'; composes: top bottom from 'padding'; composes: pointer from 'cursor'; composes: ui all from 'transition'; }

Slide 67

Slide 67 text

We decided to solve the main Atomic CSS-related problems using the power of CSS Modules, getting all the benefits of both solutions. Michele Bertoli https://medium.com/yplan-eng/atomic-css-modules-cb44d5993b27#.p7jtpneoh

Slide 68

Slide 68 text

Is Origami going to use CSS Modules? @onishiweb

Slide 69

Slide 69 text

No.

Slide 70

Slide 70 text

First Class Styles - Mark Dalgleish Front Trends 2016 https://www.youtube.com/watch?v=KmtgJ1d4zuY

Slide 71

Slide 71 text

The alternative way… @onishiweb

Slide 72

Slide 72 text

Delayed 1. Automobiles 2. Trains 3.

Slide 73

Slide 73 text

1. CSS 2. CSS Modules 3. Web Components

Slide 74

Slide 74 text

The Web Components way…

Slide 75

Slide 75 text

@onishiweb • Custom elements • Shadow DOM • Templates • HTML imports/JavaScript modules

Slide 76

Slide 76 text

Custom Elements @onishiweb

Slide 77

Slide 77 text

Slide 78

Slide 78 text

class OGallery extends HTMLElement { constructor() { super(); [...] } [...] } customElements.define('o-gallery', OGallery);

Slide 79

Slide 79 text

const oGallery = document.createElement('o-gallery'); document.body.appendChild(oGallery); // Show the next slide oGallery.nextSlide();

Slide 80

Slide 80 text

Templates @onishiweb

Slide 81

Slide 81 text

Slide 82

Slide 82 text

HTML Imports @onishiweb

Slide 83

Slide 83 text

Slide 84

Slide 84 text

JavaScript modules @onishiweb

Slide 85

Slide 85 text

Shadow DOM

Slide 86

Slide 86 text

This is where things get spooky and weird! Soledad Penades https://www.youtube.com/watch?v=2vWgJ7w3hu0

Slide 87

Slide 87 text

@onishiweb

Slide 88

Slide 88 text

Creating a Shadow DOM @onishiweb

Slide 89

Slide 89 text

// Attaches a shadow-root to your element const shadow = this.attachShadow({mode: 'open'});

Slide 90

Slide 90 text

// Attaches a shadow Root to your element const shadowRoot = this.attachShadow({mode: 'open'}); // Get the custom template, clone it const template = document.querySelector('#o-gallery'); const clone = this.importNode(template, true); // Insert it into our shadow DOM shadowRoot.appendChild(clone);

Slide 91

Slide 91 text

Slots @onishiweb

Slide 92

Slide 92 text

Slide 93

Slide 93 text

Delayed plane

Slide 94

Slide 94 text

Styling web components @onishiweb

Slide 95

Slide 95 text

:host { background-color: #333; } .slide { margin: 0; } img { display: block; } .caption { color: #fff; }

Slide 96

Slide 96 text

Fully encapsulated styles @onishiweb

Slide 97

Slide 97 text

::host and ::host-context @onishiweb

Slide 98

Slide 98 text

::host(.theme-reverse) { background-color: #fff1e0; } ::host-context(.streams) { /* styles */ }

Slide 99

Slide 99 text

::slotted @onishiweb

Slide 100

Slide 100 text

::slotted img { display: block; margin: 0; }

Slide 101

Slide 101 text

Customising Web Components @onishiweb

Slide 102

Slide 102 text

Custom properties @onishiweb

Slide 103

Slide 103 text

.caption { color: var(--caption-color, white); }

Slide 104

Slide 104 text

CSS Mixins @onishiweb

Slide 105

Slide 105 text

.caption { --caption-styles: { color: red; font-size: 14px; }; } .caption { @apply(--caption-styles); }

Slide 106

Slide 106 text

What this means for Origami @onishiweb

Slide 107

Slide 107 text

We can start serving markup @onishiweb

Slide 108

Slide 108 text

https://github.com/Polymer/vulcanize Bundling HTML imports

Slide 109

Slide 109 text

https://github.com/Polymer/vulcanize HTTP/2?

Slide 110

Slide 110 text

Using Web Components today @onishiweb

Slide 111

Slide 111 text

The road to v1… @onishiweb

Slide 112

Slide 112 text

http://jonrimmer.github.io/are-we-componentized-yet/

Slide 113

Slide 113 text

Polyfill @onishiweb

Slide 114

Slide 114 text

Libraries @onishiweb

Slide 115

Slide 115 text

@onishiweb • Polymer • x-tag • Bosonic

Slide 116

Slide 116 text

Beware! Here be dragons…

Slide 117

Slide 117 text

http://webcomponents.org/

Slide 118

Slide 118 text

https://developers.google.com/web/fundamentals/primers/customelements/

Slide 119

Slide 119 text

Web Components are here!

Slide 120

Slide 120 text

Almost…

Slide 121

Slide 121 text

Honestly, like really close…

Slide 122

Slide 122 text

1. Automobiles 2. Trains 3. Planes

Slide 123

Slide 123 text

1. CSS 2. CSS Modules 3. Web Components

Slide 124

Slide 124 text

Adam Onishi Financial Times @onishiweb Thank you!