If you are viewing this presentation in a PDF, please stop and open - - PowerPoint PPT Presentation

if you are viewing this presentation in a pdf please stop
SMART_READER_LITE
LIVE PREVIEW

If you are viewing this presentation in a PDF, please stop and open - - PowerPoint PPT Presentation

If you are viewing this presentation in a PDF, please stop and open the slides in browser (slides in the browser look way better): https://switowski.github.io/functional-css-talk/ 1 1 Maintainable CSS with visual regression testing and


slide-1
SLIDE 1

1

If you are viewing this presentation in a PDF, please stop and open the slides in browser (slides in the browser look way better): https://switowski.github.io/functional-css-talk/

slide-2
SLIDE 2

1 2

Maintainable CSS

with visual regression testing and functional CSS

Sebastian Witowski

slide-3
SLIDE 3

3 . 1

Problems of CSS

Cascading Style Sheets Hard to maintain large les (ghting specicity with IDs and !important) Duplicated and unused code

slide-4
SLIDE 4

3 . 2

Duplicated CSS

<div class="menu">...</div> ... <div class="navigation">...</div> .header2 { font­size: 24px; } ... h2 { font­size: 24px; }

slide-5
SLIDE 5

3 . 3

Unused CSS

.menu { font­size: 16px; } ... # Chained selectors and cascading .menu ul li.active { font­size: 2em; }

slide-6
SLIDE 6

4

CSS is hard to refactor

slide-7
SLIDE 7

5

How can we solve this problem?

slide-8
SLIDE 8

6 . 1

We can write tests for CSS

slide-9
SLIDE 9

6 . 2

Find 5 differences...

slide-10
SLIDE 10

6 . 3

...100 times

slide-11
SLIDE 11

6 . 4

Visual regression test

slide-12
SLIDE 12

6 . 5

PhantomCSS 

slide-13
SLIDE 13

6 . 6

spectre 

slide-14
SLIDE 14

6 . 7

percy.io 

slide-15
SLIDE 15

6 . 8

Other tools

Needle (for Python)  dpxdt (for Python) 

slide-16
SLIDE 16

7

Challenges of visual regression testing:

Dynamic content (changing number or random blog post) Sharing tests with your team (dierent OS, dierent graphic card, dierent conguration)

slide-17
SLIDE 17

8 . 1

Writing maintainable CSS

OOCSS BEM SMACSS

slide-18
SLIDE 18

8 . 2

Object Oriented CSS

  • 1. Separate style from structure

.button { width: ...; height: ...;

  • verflow: ...;

} ... .alert { border: ...; background: ...; color: ...; }

slide-19
SLIDE 19

8 . 3

Object Oriented CSS

  • 2. Separate content from container

// BAD .sidebar h3 { font­family: ...; font­size: ...; } // GOOD .fancy­header { font­family: ...; font­size: ...; }

slide-20
SLIDE 20

8 . 4

Block, Element, Modier

slide-21
SLIDE 21

8 . 5

Scalable and Modular Architecture for CSS (SMACSS)

Base Layout Module State Theme

slide-22
SLIDE 22

9

Functional CSS

slide-23
SLIDE 23

10 . 1

<article class="br2 ba dark­gray b­­black­10 mv4 w­100 w­50­m w­25­l mw5 center"> <img src="http://placekitten.com/g/600/300" class="db w­100 br2 br­­top"> <div class="pa2 ph3­ns pb3­ns"> <div class="dt w­100 mt1"> <div class="dtc"> <h1 class="f5 f4­ns mv0">Cat</h1> </div> <div class="dtc tr"> <h2 class="f5 mv0">$1,000</h2> </div> </div> <p class="f6 lh­copy measure mt2 mid­gray">...</p> </div> </article>

slide-24
SLIDE 24

10 . 2

.ba { border­style: solid; border­width: 1px; } .b­­black­10 { border­color: rgba(0, 0, 0, .1); } .br2 { border­radius: .25rem; } .br­­top { border­bottom­left­radius: 0; border­bottom­right­radius: 0; } .db { display: block; } .dt { display: table; } .dtc { display: table­cell; } .lh­copy { line­height: 1.6; } .mw5 { max­width: 16rem; } .w­100 { width: 100%; } .dark­gray { color: #333; } .mid­gray { color: #555; } .pa2 { padding: .5rem; } .mt1 { margin­top: .25rem; } .mt2 { margin­top: .5rem; } .mv0 { margin­top: 0; margin­bottom: 0; } .mv4 { margin­top: 2rem; margin­bottom: 2rem; } .tr { text­align: right; } .f5 { font­size: 1rem; } .f6 { font­size: .875rem; } .measure { max­width: 30em; } .center { margin­right: auto; margin­left: auto; } @media screen and (min­width: 30em) { .pb3­ns { padding­bottom: 1rem; } .ph3­ns { padding­left: 1rem; padding­right: 1rem; } .f4­ns { font­size: 1.25rem; } } @media screen and (min­width: 30em) and (max­width: 60em) { .w­50­m { width: 50%; } } @media screen and (min­width: 60em) { .w­25­l { width: 25%; } }

slide-25
SLIDE 25

10 . 2 10 . 3

<p class="f6">...</p>

<p class="f5">...</p>

slide-26
SLIDE 26

11

Functional CSS is:

Pure (no side eects) Composable Immutable Transparent (rem vs em)

slide-27
SLIDE 27

12

Frameworks

Tachyons  Basscss 

slide-28
SLIDE 28

13 . 1

The good parts

Modifying existing styling is easier No more wrestling with the specicity Very easy to add themes Coding is faster Encourages HTML components ( ) Encourages design consistency Cache-friendly Faster websites Tachyons components 

slide-29
SLIDE 29

13 . 2

The bad parts

"It's just replacing duplicated CSS rules with duplicated CSS classes!"

slide-30
SLIDE 30

13 . 3

.table­list­triage { display: none; } .triage­mode .table­list­non­triage, .triage­mode .table­list­filters { display: none; } .boxed­group­list>li.approved .btn­sm, .boxed­group­list>li.rejected .btn­sm { display: none; } .repo­list .participation­graph.disabled { display: none; } .payment­methods .selected­payment­method { display: none; } .payment­methods.paypal­logged­in .paypal­sign­in { display: none; } .payment­methods.has­paypal­account .paypal­sign­in { display: none; } .currency­container .local­currency, .currency­container .local­currency­block { display: none; } .currency­container.open .default­currency { display: none; } .plan­chooser­repo­menu .price­label { display: none; }

slide-31
SLIDE 31

13 . 3 13 . 4

<p class="dn ...">...</p> <div class="dn ...">...</div> <li class="dn ...">...</li> <div class="dn ...">...</div> <span class="dn ...">...</span> <article class="dn ...">...</article>

slide-32
SLIDE 32

13 . 4 13 . 5

The bad parts

"It's just replacing duplicated CSS rules with duplicated CSS classes!" Updating existing components can be a pain Won't work with non-functional frameworks

slide-33
SLIDE 33

14 . 1

No more writing CSS?

.pixel­perfect­button { font­size: 18px; margin: 47px; padding­top: 153px; }

slide-34
SLIDE 34

14 . 2

It's ok to write CSS

.modal { position: fixed; top: 50%; left: 50%; ­webkit­transform: translate(­50%,­50%); ­ms­transform: translate(­50%,­50%); transform: translate(­50%,­50%); *width: 600px; *margin­left: ­300px; *top: 50px; }

slide-35
SLIDE 35

15 . 1

Functional CSS is not a silver bullet

slide-36
SLIDE 36

15 . 2

as

CSS bloat vs HTML bloat

<div class="sidebar">...</div>

+

sidebar { float: left; margin­right: 10px; width: 25%; }

vs.

<div class="float­left margin­right­1 width­25">...</div>

slide-37
SLIDE 37

16

Thank you

Questions?