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

CSS convo over lunch

CSS convo over lunch

The Yelp SeatMe friends invited me for lunch and we talked about CSS.

Giuseppe Gurgone

December 01, 2015
Tweet

More Decks by Giuseppe Gurgone

Other Decks in Programming

Transcript

  1. Structure Sparse Code organized by Technology assets/css/forms.css assets/js/checkbox.js view/partials.html tests/???

    docs??? => http://wiki/docs/forms#checkbox > fidn . -name checkbox* > sudo pip install thefuck
  2. Docs Reference for everybody Comprehensive, document every UI State Built

    in code examples One component at a time Generated Metalsmith.io, Jekyll
  3. Tests Enforce Structure, Docs, Conventions and other common practices [‘css’,

    ’js’, ’html’] .forEach(ext => assertFileExists(‘doc/’+ext+’.md’)) Image diffing on UI Components (state) All [CSS,] JavaScript, Partial tested
  4. Structure Organize by Components not Technology Docs Document every Component

    and Utility Tests Enforce documentation and best practices
  5. Preprocessors are awesome buttt… Non standard APIs Often overused, easily

    abused: That “With power comes great responsibility” thing Nesting #nav > li > .wrapper a:hover:before, #nav > li > .wrapper a:focus:before { … } #sidebar div.widget h2.title a span { … } ...
  6. PostCSS A tool for transforming styles with JS plugins. These

    plugins can support variables and mixins, transpile future CSS syntax, inline images, and more. :root { --Button-color: hotpink; } .Button { color: var(--Button-color); } postcss(customProperties()).process(css).css .Button { color: hotpink; }
  7. SUIT CSS is a reliable and testable styling methodology for

    component-based UI development developed by Nicolas Gallagher. suitcss.github.io
  8. SUIT CSS Naming Convention, Scoped Styles The SUIT CSS naming

    convention helps to scope component CSS and make your widgets render more predictably. .MyComponent {} .MyComponent.is-animating {} .MyComponent--modifier {} .MyComponent-part {} .MyComponent-anotherPart {}
  9. SUIT CSS vs BEM SUIT CSS is a flavor of

    BEM "Standard BEM" is also a poor choice for migrations, because .menu is going to collide with the legacy .menu code that has no isolated structure to it. Whereas the name .Menu won't, and it maps more obviously with associated JS functions and View code. PascalCase plays nice with React and JS components.
  10. Global Styles Hard to know in advance the context where

    our UI Components are going to be used. The effect of Global Styles is unpredictable Gotcha in the JavaScript world No Global typography, etc.
  11. One pattern, one Component Each component should implement a single

    part of the UI. Don't try to do too much. Each component should have a dedicated CSS file. Ideally your component's files are grouped together in a dedicated directory.
  12. One Element, one Component There should be a one-to-one replationship

    between HTML and CSS. .Review { color: #b4d455; } <div class=”Grid-cell”> <p class=”Review Grid-cell u-textBreak”> uh-may-zing </p> </div>
  13. Adapting to ancestral context Most components should not set their

    own width, margin, and positioning. By authoring a component to be full-width or inline, it can better adapt to the dimensions of an ancestral context.
  14. Copy/Paste Senõr Frontend Eng Styleguides are cool, Bootstrap is cool

    (?) Reusable CSS alone is not enough Build reusable UI Components: Templates, Partials, Presenter Pattern
  15. Future Proof :) Transpile, use Standards SUIT CSS :) Reliable

    Styling methodology Isolation & Composition :) Avoid dependencies & Global, Compose instead