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

Shedding Light on the Shadow Dom

Dave
June 01, 2016

Shedding Light on the Shadow Dom

We have many problems that exist in modern CSS architecture including a lack of encapsulation, no facility to accurately remove dead code and of course, specificity conflicts.

I will explain how the Shadow Dom specification can help to solve them by crafting reusable components using various pseudo selectors and slots. I'll also show you how to create an API for your components that consumers can access using CSS Custom Properties.

Dave

June 01, 2016
Tweet

Other Decks in Technology

Transcript

  1. <div id="notification"> <h3>New Message in #customer-support</h3> <p>Have you guys thought

    about using Web Components yet?</p> <button>Reply</button> </div>
  2. root.innerHTML = ` <div class="wrapper"> <button> <svg> ... </svg> <span>Close</span>

    </button> <content></content> <p>1 minute ago</p> </div>`;
  3. \

  4. root.innerHTML = ` <div class="wrapper"> <button> <svg> ... </svg> <span>Close</span>

    </button> <slot name="heading"></slot> <slot></slot> <slot name="action"></slot> <p>1 minute ago</p> </div>`;
  5. \

  6. root.innerHTML = '<style> ... button {\ /* Styles */ }\

    p {\ /* Styles */ }\ ... </style>';
  7. root.innerHTML = `<style> ... ::content h3, ::content p { color:

    #fff; margin-top: 0; padding-top: 0; } ... </style>`;
  8. root.innerHTML = `<style> ... ::slotted h3, ::slotted p { color:

    #fff; margin-top: 0; padding-top: 0; }\ ... </style>`;
  9. root.innerHTML = `<style> ... button svg { fill: var(--notification-close-button-color, #fff);

    height: var(--notification-close-button-size, 1.5rem); width: var(--notification-button-size, 1.5rem); } p { color: var(--notification-text-color, #fff); text-align: right; } ... </style>`;
  10. Can I use it? Chrome - Yes Opera - Yes

    Firefox - Feature Flag Safari - In Progress Edge - Vote for it