A presentation at Bilbostack 2019 in in Bilbao, Biscay, Spain by Belén Albeza
Belén Albeza @ladybenko
From documents to apps
This is a web I made in 1999, in my early teens. I opened it with the latest Firefox version and it looks the same it looked back in the day. We see this as normal, but I cannot say the same about other software I developed only a few years ago – some of my games and mobile apps can no longer be used with modern devices.
Now it’s 2019. I’m working in the Firefox DevTools team, making developer tools for Firefox using HTML, CSS, and JS – the same stack I’ve been using all this time!
It’s 2019 We can’t style a dropdown 💃, nor we do have a <carrousel>
, or <toolbar>
tags… but we have games, VR experiences, multimedia players, etc. that are built on HTML, CSS and JS.
Reusable UI widgets
<User username="desatranques">
=>
<span class="user">
<img class="user__avatar"
src="desatranques.png">
Desatranques Jaén
</span>
customElements.define(
'x-user',
class extends HTMLElement {
constructor() {
super();
// ...
}
}
);
=>
<x-user>
Shadow DOM is not new…
JS framework:
<span class="user">
<img class="user__avatar"
src="desatranques.png">
Desatranques Jaén
</span>
Web Components:
<x-user>
#shadow-root
<span class="user">
<img class="user__avatar"
src="desatranques.png">
Desatranques Jaén
</span>
</x-user>
customElements.define(
'x-user',
class extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML =
'<span class="user">...</span>';
}
}
);
https://belen-albeza.github.io/webcomponents-examples/wc-simple.html
<template id="user-tpl">
<style>
.user { border: 1px solid black; }
</style>
<span class="user">
<img src="avatar.png">Anonymous
</span>
</template>
const template = document.querySelector('#user-tpl');
this.attachShadow({ mode: 'open' });
this.shadowRoot.appendChild(
template.content.cloneNode(true));
https://belen-albeza.github.io/webcomponents-examples/wc-template.html
<x-message level=“success”> <p>Once upon a time…</p> </x-message>
https://belen-albeza.github.io/webcomponents-examples/wc-slots.html
// which attributes to watch
static get observedAttributes() {
return ['username'];
}
// callback for changes
attributeChangedCallback(attr, oldValue, value) {
// re-render component here
// …
}
https://belen-albeza.github.io/webcomponents-examples/wc-attrs.html
https://belen-albeza.github.io/webcomponents-examples/wc-styles.html
So… can I ditch React? 🤔
No.
https://custom-elements-everywhere.com/
--target wc
flaghttps://belen-albeza.github.io/webcomponents-examples/wc-vue.html
https://belen-albeza.github.io/ webcomponents-examples/
Belén Albeza @ladybenko
The following resources were mentioned during the presentation or are useful additional information.
Github repository with the demos and examples
Here’s what was said about this presentation on social media.
Charlas como la de @ladybenko hoy en la #BilboStack2019 hacen que una tecnología nueva como los WebComponents se entiendan de forma sencilla y rápida, incluso para desarrolladores ajenos al front. Gracias! pic.twitter.com/Lsi9Le3tHr
— Javier Provecho (@javierprovecho) January 26, 2019