styling a design system based on bootstrap 4 and web
play

Styling a design system based on Bootstrap 4 and Web Components @ - PowerPoint PPT Presentation

qCON SP, APril 24th, 2017 Styling a design system based on Bootstrap 4 and Web Components @ andres galante Hola! @ andres galante pt_AR CSS MODULARITY qCON SP, APril 24th, 2017 Styling a design system based on Bootstrap 4 and Web


  1. qCON SP, APril 24th, 2017 Styling a design system based on Bootstrap 4 and Web Components @ andres galante

  2. 😋 Hola!

  3. @ andres galante

  4. 💪 pt_AR

  5. CSS MODULARITY qCON SP, APril 24th, 2017 Styling a design system based on Bootstrap 4 and Web Components @ andres galante

  6. Agenda Design Systems Good CSS Architecture CSS Specificity The PatternFly Use Case Q & A Shadow DOM

  7. Um argentino incomoda muita gente…

  8. LEt’s Sta r t… Design systems. The road to consistency and modularity.

  9. “A design system is everything that makes up your product.” – Mark Otto https://speakerdeck.com/mdo/build-your-own-bootstrap

  10. Consistency

  11. “...when things always behave the same, users don't have to worry about what will happen. Instead, they know what will happen based on earlier experiences” – Jakob Nielsen https://www.nngroup.com/articles/top-10-mistakes-web-design/

  12. 5 + 8 = ?

  13. 5 + 8 = 13

  14. 123 + 34 = ?

  15. 123 + 34 = 157

  16. 123 + 34 = ?

  17. 123 + 34 = 157

  18. Cache Memory

  19. Average attention span of a human: 2000: 12 seconds 2015: 8 seconds http://www.statisticbrain.com/attention-span-statistics/

  20. 9 seconds http://www.statisticbrain.com/attention-span-statistics/

  21. Modularity

  22. http://atomicdesign.bradfrost.com/chapter-4/

  23. http://atomicdesign.bradfrost.com/chapter-4/

  24. http://atomicdesign.bradfrost.com/chapter-4/

  25. CSS Villains Globally operating Dependent on location Very leaky Based on inheritance

  26. CSS Specificity

  27. CSS Specificity How the browsers decides which CSS declaration is the most relevant to apply to an element.

  28. CSS Specificity If one selector is more specific than another, it overrides it. If two selector share the same weight, the later one is applied.

  29. Selector Weight Selector Weight Example p { … } Type Selector 1 .success { … } Class Selectors 10 #header { … } ID Selectors 100 <p style=“color: red”> Inline Styles 1000

  30. p.success { color: green ; !important; }

  31. Demo Specificity

  32. Class 🔫 Type Selectors IDs 🔫 Class Inline styles 🔫 IDs !important 💤 all of them.

  33. https://stu fg andnonsense.co.uk/archives/css_specificity_wars.html

  34. good CSS ShadowDOM

  35. Web Components

  36. Web Components ShadowDOM HTML Imports Custom Elements HTML Templates https://www.w3.org/standards/techs/components#w3c_all

  37. Web Components Encapsulate all of their HTML and CSS. JavaScript behaviours are native on the browser.

  38. Shadow Dom

  39. Custom elements + Shadow DOM = Self contained HTML, CSS and JS

  40. CSS

  41. The ShadowRoot A shadow root is a document fragment that gets attached to a “host” element.

  42. Demo ShadowRoot

  43. Light DOM + Shadow DOM = Composed DOM LightDOM ShadowDOM <slot> <p>text<p> Distributed Node

  44. <slot> Placeholders inside your component that users can fill with their own markup.

  45. Demo Slots

  46. Stylin’ the Shadow DOM

  47. Life as a parent 💪 💪 💪 💪 Life Life Life

  48. CSS selectors from the outer page don’t apply inside your component. Styles defined inside don’t bleed out. They’re scoped to the host element.

  49. :host(<selector>) selector Allows you to target the host if it matches a <selector>. ::host-context(<selector>) selector Matches the component if it or any of its ancestors matches <selector>. :slotted(<compound-selector>) selector Matches nodes that are distributed into a <slot>

  50. Demo host and slotted selectors

  51. https://www.polymer-project.org/ https://www.webcomponents.org/

  52. http://caniuse.com/#feat=shadowdomv1

  53. https://developer.microsoft.com/en-us/microsoft-edge/platform/status/shadowdom/ https://platform-status.mozilla.org/#shadow-dom

  54. webcomponents.org

  55. Shadow DOM 👎 Excellent name 👎 Scoped Styles 🎊 👎 Modular components 👏 Bad browser support

  56. CSS GUIDELINES Let’s write really good CSS!

  57. 4 Rules to keep your CSS tidy Use a global namespace 1 Use BEM 2 Keep selectors flat 3 Write great CSS documentation 4

  58. 1 Use a namespace to avoid conflicts.

  59. .pf-masthead { color: white; }

  60. 2 BEM syntax {{block}}__{{element}}--{{modifier}} https://en.bem.info/methodology/

  61. Block .pf-masthead Element .pf-masthead__section Modifier .pf-masthead--inverse

  62. 3 Use flat Selector to avoid specificity issues. https://en.bem.info/methodology/

  63. 👎 Whenever possible don’t nest selectors 👎 Use classes, never IDs 👎 Never use !important

  64. 4 Write good CSS docs for a correct CSS implementation. https://github.com/patternfly/patternfly-css/blob/master/.github/DOCUMENTATION_TEMPLATE.md

  65. Class name: . classname Applied to: <element> Outcome: what does it do? Required: Yes or no Remarks: General remarks Accessibility: role, aria and a11y comments

  66. <header class=" pf-masthead ">

  67. Class name: . pf-masthead Applied to: <header> or <div> Outcome: Initiates a masthead Required: Yes Remarks: Always use it with the grid Accessibility: role=”navigation” , skip link, etc

  68. Lint CSS!

  69. https://houndci.com

  70. OOCSS & BEM 👎 Vanilla CSS 👎 Transparent structure 👎 Modular components 👏 It can go wrong really fast

  71. USE CASE PatternFly Putting everything together

  72. 👎 yes! Custom Elements: 👏 not now. Shadow DOM:

  73. https://patternfly-webcomponents.github.io/

  74. CSS PatternFly Guidelines https://github.com/patternfly/patternfly-css/blob/master/CODE-GUIDELINES.md

  75. Bootstrap 4 is awesome = happy me

  76. Demo PatternFly masthead

  77. …and they all live happily ever after.

  78. Muito Obrigado :) github.com/patternfly slack.patternfly.org patternfly.org @andresgalante

Recommend


More recommend