by @leocaseiro
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
In Jun 2015, I was using SMACSS
Scalable Modular Architecture for CSS
smacss.com
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
React: CSS in your JS by Christopher Chedeau
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
attachShadow
ShadowRoot
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
HTML Templates
slides.com/leocaseiro/web-components
Custom Elements
Shadow DOM
class WordCount extends HTMLElement {
constructor() {
// Always call super first in constructor
super();
// Element functionality written in here
}
}
slides.com/leocaseiro/web-components
class WordCount extends HTMLParagraphElement {
// ...
}
customElements.define('word-count', WordCount, { extends: 'p' });
<word-count></word-count>
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
update.onclick = function() {
// Randomly update square's attributes
square.setAttribute('l', random(50, 200));
square.setAttribute('c', `rgb(${random(0, 255)}, ${random(0, 255)}, ${random(0, 255)})`);
};
// Create a shadow root
var shadow = this.attachShadow({ mode: 'open' });
// Create some CSS to apply to the shadow dom
var style = document.createElement('style');
style.textContent = `
.custom {
color: red
}
`;
// attach the created elements to the shadow dom
shadow.appendChild(style);
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
<template id="my-paragraph">
<p>My paragraph</p>
</template>
let template = document.getElementById('my-paragraph');
let templateContent = template.content;
document.body.appendChild(templateContent);
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
Be aware, that popular languages and libraries get replaced
iframes, table layouts, css float layout, ...
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components
slides.com/leocaseiro/web-components