if you are viewing this presentation in a pdf please stop
play

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


  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/ 1

  2. 1 Maintainable CSS with visual regression testing and functional CSS Sebastian Witowski 2

  3. Problems of CSS Cascading Style Sheets Hard to maintain large �les (�ghting speci�city with IDs and !important) Duplicated and unused code 3 . 1

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

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

  6. CSS is hard to refactor 4

  7. How can we solve this problem? 5

  8. We can write tests for CSS 6 . 1

  9. Find 5 differences... 6 . 2

  10. ...100 times 6 . 3

  11. Visual regression test 6 . 4

  12. PhantomCSS  6 . 5

  13. spectre  6 . 6

  14. percy.io  6 . 7

  15. Other tools Needle (for Python)  dpxdt (for Python)  6 . 8

  16. Challenges of visual regression testing: Dynamic content (changing number or random blog post) Sharing tests with your team (di�erent OS, di�erent graphic card, di�erent con�guration) 7

  17. Writing maintainable CSS OOCSS BEM SMACSS 8 . 1

  18. Object Oriented CSS 1. Separate style from structure .button { width: ...; height: ...; overflow: ...; } ... .alert { border: ...; background: ...; color: ...; } 8 . 2

  19. Object Oriented CSS 2. Separate content from container // BAD .sidebar h3 { font­family: ...; font­size: ...; } // GOOD .fancy­header { font­family: ...; font­size: ...; } 8 . 3

  20. Block, Element, Modi�er 8 . 4

  21. Scalable and Modular Architecture for CSS (SMACSS) Base Layout Module State Theme 8 . 5

  22. Functional CSS 9

  23. <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> 10 . 1

  24. .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%; } } 10 . 2

  25. 10 . 2 <p class="f6">...</p> ↓ <p class="f5">...</p> 10 . 3

  26. Functional CSS is: Pure (no side e�ects) Composable Immutable Transparent (rem vs em) 11

  27. Frameworks Tachyons  Basscss  12

  28. The good parts Modifying existing styling is easier No more wrestling with the speci�city Very easy to add themes Coding is faster Encourages HTML components ( Tachyons components  ) Encourages design consistency Cache-friendly Faster websites 13 . 1

  29. The bad parts "It's just replacing duplicated CSS rules with duplicated CSS classes!" 13 . 2

  30. .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; } 13 . 3

  31. 13 . 3 <p class="dn ...">...</p> <div class="dn ...">...</div> <li class="dn ...">...</li> <div class="dn ...">...</div> <span class="dn ...">...</span> <article class="dn ...">...</article> 13 . 4

  32. 13 . 4 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 13 . 5

  33. No more writing CSS? .pixel­perfect­button { font­size: 18px; margin: 47px; padding­top: 153px; } 14 . 1

  34. 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; } 14 . 2

  35. Functional CSS is not a silver bullet 15 . 1

  36. 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> as 15 . 2

  37. Thank you Questions? 16

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend