Schalk Venter
🔧 Front-end Development / 🎨 UI Design / 🌍 Social Good / ❤️ Destigmatising mental illness
"What we need to remember, though, is that the Web, as we know it now, is a fleeting thing. [...] The Web will be understood not as screenfuls of text and graphics but as a transport mechanism, the ether through which interactivity happens."
Darcy DiNucci
Print Magazine (1999)
Custom Elements
HTML Templates
Shadow DOM
Custom Elements
HTML Templates
Shadow DOM
Shadow DOM
HTML Templates
Custom Elements
<div>Hello World!</div>
const element = document.createElement('div')
element.appendChild(document.createTextNode('Hello World'))
console.log(element instanceof HTMLElement) // true
document.body.appendChild(element)
<div>Hello World!</div>
<my-element>Hello World</my-element>
console.log(element instanceof HTMLElement) // true
<hello-world>Look mom, no framework!</hello-world>
const input = createRef<HTMLInputElement>()
<hello-world>I'm a real HTML Element!</hello-world>
// console.log(element instanceof HelloWorld) // true
class HelloWorld extends HTMLElement {
constructor() { super() }
}
customElement.define('hello-world', HelloWorld)
const input = createRef<HTMLInputElement>()
const template = document.createElement("template");
template.innerHTML = `
<style>
p { border: 1px solid magenta }
</style>
<h2>Encapsulation Time!</h2>
<p>
I should be the only border,
and not be blue
</p>
<slot></slot>
`;
class HelloWorld extends HTMLElement {
inner = this.attachShadow({ mode: 'closed '})
constructor() { super() }
onConnectedCallback() {
super();
const content = template.content.cloneNode(true);
this.inner.appendChild(content);
}
}
customElement.define('hello-world', HelloWorld)
<style>
p {
color: blue;
}
</style>
<h1>Example Page</h1>
<p>I should be blue</p>
<hello-world></hello-world>
<hello-world>
<h2>I'm inside</h2>
<p>But I'm also blue</p>
</hello-world>
<p>I should also be blue</p>
By Schalk Venter
HTML goes brrrrrrrrrrrr
🔧 Front-end Development / 🎨 UI Design / 🌍 Social Good / ❤️ Destigmatising mental illness