SlideShare a Scribd company logo
Web Components
It's all rainbows and
unicorns! Is it?
Sara HARKOUSSE
BlendWebMix
Lyon, 26, 27 October 2017
1
SARA HARKOUSSE
@Sara_harkousse
Tech Lead, front-end Web developer at Dassault Systèmes
3D design & PLM software
Electronics and Computer Science Engineer by training
About me
#BlendWebMix #webcomponents 2
Women in Tech
Duchess France
@duchessfr
duchess-france.org
Elles bougent (Girls on The Move)
@ellesbougent
ellesbougent.com
#BlendWebMix #webcomponents @Sara_harkousse 3
Web Components
It's all rainbows and
unicorns! Is it?
4
"The web components revolution"
"A Tectonic shift for web development"
"Web components are a game changer"
Web components'
public image
#BlendWebMix #webcomponents @Sara_harkousse 5
Web components'
public image
#BlendWebMix #webcomponents @Sara_harkousse
"The broken promise of Web Components"
6
Motivation
#BlendWebMix #webcomponents @Sara_harkousse
Modular architecture
Filterable
Product Table
Search Bar Product Table
Product
Row
Product
Category
Row
7
Angular 4.0 Component
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `<h1>Hello {{name}}</h1>`
})
export class AppComponent { name = 'Angular'; }
<my-app><h1>Hello Angular</h1></my-app>
https://embed.plnkr.co/?show=preview&show=app%2Fapp.component.ts
#BlendWebMix #webcomponents @Sara_harkousse
Ember 2.16.0 Component
<article class="blog-post">
<h1>{{title}}</h1>
<p>{{yield}}</p>
<p>Edit title: {{input type="text" value=title}}</p>
</article>
{{#each model as |post|}}
{{#blog-post title=post.title}}
{{post.body}}
{{/blog-post}}
{{/each}}
https://guides.emberjs.com/v2.12.0/components/defining-a-component/
Polymer 2.0 Element
// Define the class for a new element called custom-element
class CustomElement extends Polymer.Element {
static get is() { return "custom-element"; }
constructor() {
super();
this.textContent = "I'm a custom-element.";
}
}
// Register the new element with the browser
customElements.define(CustomElement.is, CustomElement);
<custom-element></custom-element>
http://plnkr.co/edit/PaCt2M?p=preview
8
#BlendWebMix #webcomponents @Sara_harkousse
Frameworks make it
hard to get along
9
#BlendWebMix #webcomponents @Sara_harkousse
Harmony happens
when there is less
learning curve
10
Browser support
use webcomponents.js
#BlendWebMix #webcomponents @Sara_harkousse 11
Refresher on web
components
Web components are a set of web platform APIs
that allow you to create new custom, reusable,
encapsulated HTML tags to use in web apps.”
#BlendWebMix #webcomponents @Sara_harkousse 12
Refresher on web
components
#BlendWebMix #webcomponents @Sara_harkousse
HTML Template Tag
HTML Imports
Custom Elements
Shadow DOM
13
HTML Template Tag
#BlendWebMix #webcomponents @Sara_harkousse
<template id="template">
<div id="container">
<img class="webcomponents" src="logo.svg">
</div>
</template>
14
HTML Template Tag Usage
#BlendWebMix #webcomponents @Sara_harkousse
var template = document.querySelector('#template');
var clone = template.content.cloneNode(true);
var host = document.querySelector('#host');
host.appendChild(clone);
15
HTML Template Tag
#BlendWebMix #webcomponents @Sara_harkousse
A way to add inert DOM elements to your document
Not something that's going to revolutionize your apps
No two-way data binding, no binding at all
16
HTML Imports
#BlendWebMix #webcomponents @Sara_harkousse
<link rel="import" href="component.html">
<link rel="stylesheet" href="style.css">
<div id="container">
<img class="rotate" src="logo.svg">
</div>
<script src="script.js"></script>
17
How to get my
component?
#BlendWebMix #webcomponents @Sara_harkousse
var link = document.querySelector('link[rel="import"]');
var content = link.import;
// Grab DOM from component.html's document.
var el = content.querySelector('#container');
var clone = el.cloneNode(true);
var host = document.querySelector('#host');
host.appendChild(clone);
18
#BlendWebMix #webcomponents @Sara_harkousse
HTML Import
requires a polyfill
ES module?
19
#BlendWebMix #webcomponents @Sara_harkousse
ES module
// export feature
export const Component = // …
// import feature
import {Component} from '../components/cutom-component.js';
20
#BlendWebMix #webcomponents @Sara_harkousse
Shadow DOM
A tiny document
exists inside of a host element
21
#BlendWebMix #webcomponents @Sara_harkousse
Key concepts
Isolated DOM
Scoped CSS
22
#BlendWebMix #webcomponents @Sara_harkousse
Shadow DOM
requires a polyfill
Hard to polyfill
23
#BlendWebMix #webcomponents @Sara_harkousse
Use/Don't
use
Shadow
DOM?
callback() {
// Use it
this.root = this.attachShadow({mode: 'open'});
var template = document.querySelector('#template');
var clone = document.importNode(template.content, true);
this.root.appendChild(clone);
}
callback() {
// Don't Use it
this.root = this;
var template = document.querySelector('#template');
var clone = document.importNode(template.content, true);
this.root.appendChild(clone);
}
24
#BlendWebMix #webcomponents @Sara_harkousse
Use/Don't use
Shadow DOM?
/* Use it */
:host {
color: red;
}
/* Don't use it */
custom-component {
color: red;
}
25
#BlendWebMix #webcomponents @Sara_harkousse
Use AND Don't use
Shadow DOM
if (shadowflag){
this.root = this.attachShadow({mode: 'open'});
} else {
this.root = this;
}
custom-component, :host {
color: red;
}
26
#BlendWebMix #webcomponents @Sara_harkousse
Custom Elements
class CustomButton extends HTMLElement {...}
window.customElements.define('custom-button', CustomButton);
<custom-button></custom-button>
Acts like a div
27
#BlendWebMix #webcomponents @Sara_harkousse
Custom Elements
class CustomButton extends HTMLButtonElement {...}
window.customElements.define('custom-button', CustomButton, {extends: 'button'});
<button is="custom-button" disabled>My button!</button>
Acts like a real button
28
#BlendWebMix #webcomponents @Sara_harkousse
Custom Elements
Namespace
Dash (-) rule
29
#BlendWebMix #webcomponents @Sara_harkousse
Custom Elements
ES6 Class
class Custom-component extends HTMLElement {
constructor() {
super(); // always call super() first in the ctor.
...
}
connectedCallback() {
...
}
disconnectedCallback() {
...
}
attributeChangedCallback(attrName, oldVal, newVal) {
...
}
}
30
#BlendWebMix #webcomponents @Sara_harkousse
Component example
Bootstrap Progress Bar
<div class="progress">
<div class="progress-bar" style="width: 60%;">
60%
</div>
</div>
31
window.customElements.define('progress-bar', ProgressBar);
// Use
<progress-bar></progress-bar>
Component example
https://jsfiddle.net/sara_harkousse/kwwe75yy/
class ProgressBar extends HTMLElement {
constructor() {
super(); // always call super() first in the ctor.
this.shadow = this.attachShadow({mode: 'open'});
this._complete = 0;
}
get complete() {
return this._complete;
}
set complete(val) {
this.setAttribute('complete', val);
}
static get observedAttributes() {
return ['complete'];
}
attributeChangedCallback(name, oldval, newval) {
var innerBar = this.shadow.querySelector('.progress-bar-inner');
switch(name) {
case 'complete':
this._complete = parseInt(newval, 10) || 0;
innerBar.style.width = this.complete + '%';
innerBar.innerHTML = this.complete + '%';
}
}
connectedCallback() {
var template = `<div class="progress-bar">
<div class="progress-bar-inner">${this.complete}%</div>
</div>`;
this.shadow.innerHTML = template;
}
}
#BlendWebMix #webcomponents @Sara_harkousse 32
#BlendWebMix #webcomponents @Sara_harkousse
Components
on a page <!doctype html>
<html lang="en">
<head>
<link rel="import" href="/imports/productRow.html">
</head>
<body>
<custom-navbar style="compact"></custom-navbar>
<custom-toolbar style="full"></custom-toolbar>
<custom-pagecontent>
<custom-input attr="val"></custom-input>
<progress-bar></progress-bar>
</custom-pagecontent>
<script>
document.querySelector('custom-input').dispatchEvent(new CustomEvent('customevent', {
detail: { prop: true }
}));
document.querySelector('progress-bar').addEventListener(
'customevent', function () {
// do something
}
});
</script>
</body>
</html>
33
#BlendWebMix #webcomponents @Sara_harkousse
Takeaway
Template tag? yeah! why not?
Use ES module instead of HTML Imports
Use Shadom DOM with a flag
Custom Elements?? Go, Go, Go
34
#BlendWebMix #webcomponents @Sara_harkousse
Takeaway
You will understand some of the design decisions of
major frameworks if you learn about custom
elements
35
#BlendWebMix #webcomponents
Thanks for listening!
Follow for slides
@Sara_harkousse
https://github.com/SaraHarkousse
36

More Related Content

PDF
Introduction to Web Components
PDF
Taiwan Web Standards Talk 2011
PDF
Web Components & Polymer 1.0 (Webinale Berlin)
PDF
LESS
PDF
Google’s PRPL Web development pattern
PDF
Unlock the next era of UI design with Polymer
PPTX
Introduction to html 5
PDF
Beyond CSS Architecture
Introduction to Web Components
Taiwan Web Standards Talk 2011
Web Components & Polymer 1.0 (Webinale Berlin)
LESS
Google’s PRPL Web development pattern
Unlock the next era of UI design with Polymer
Introduction to html 5
Beyond CSS Architecture

Similar to Web Components: It’s all rainbows and unicorns! Is it? par Sara HARKOUSSE (20)

PDF
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
PDF
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
PPTX
Web components Introduction
PDF
Web components the future is here
PPTX
Web Components
PDF
The Time for Vanilla Web Components has Arrived
PPTX
Introduction to Web Components & Polymer Workshop - U of I WebCon
PPTX
Web Components: Introduction and Practical Use Cases
PDF
Introduction to Web Components
PDF
Web Components v1
PPT
Reaching for the Future with Web Components and Polymer
PDF
Web components are the future of the web - Take advantage of new web technolo...
PDF
Devoxx France - Web Components, Polymer et Material Design
PPTX
Web Components: The Future of Web Development is Here
PDF
Web component driven development
PDF
Introduction to Web Components & Polymer Workshop - JS Interactive
PDF
KharkivJS: Flaws of the Web Components in 2019 and how to address them
PPTX
Web Components
PPTX
An Introduction to Web Components
PDF
Web components and friends
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
Web components Introduction
Web components the future is here
Web Components
The Time for Vanilla Web Components has Arrived
Introduction to Web Components & Polymer Workshop - U of I WebCon
Web Components: Introduction and Practical Use Cases
Introduction to Web Components
Web Components v1
Reaching for the Future with Web Components and Polymer
Web components are the future of the web - Take advantage of new web technolo...
Devoxx France - Web Components, Polymer et Material Design
Web Components: The Future of Web Development is Here
Web component driven development
Introduction to Web Components & Polymer Workshop - JS Interactive
KharkivJS: Flaws of the Web Components in 2019 and how to address them
Web Components
An Introduction to Web Components
Web components and friends
Ad

More from La Cuisine du Web (20)

PDF
Kit de survie du marketeur au bois dormant – Digitalisation du marketing par ...
PDF
Objets connectés : adapter la technologie aux usages, et pas l’inverse ! par ...
PDF
Manager l’innovation : est-ce contradictoire, pertinent, nécessaire ?… par Ma...
PDF
Tour d’horizon de l’écosystème React-ien par Guillaume BESSON
PDF
Stream processing en mémoire avec Hazelcast Jet par Claire VILLARD
PDF
Programming is Fun par Francis BELLANGER
PDF
La démarche communautaire au coeur de la croissance de votre entreprise par H...
PDF
Qui est ton client ? par Audrey JULIENNE
PDF
Cloaking is not a crime par Patrick VALIBUS
PDF
Electron, une alternative intéressante ? par Florent MOIGNARD
PDF
CSS orienté objet par Lenny ROUANET
PDF
Automatiser la mise en production d’un site web par Nicolas KANDEL
PPTX
Design Sprints : Créons un monde meilleur ! par Jelto VON SCHUCKMANN
PDF
Fontes variables, la matrice typographique par Malou VERLOMME
PDF
Le design agile : 6 techniques pour designer de façon plus agile par Matthieu...
PPSX
Réalité virtuelle et augmentée, ces nouvelles technologies au service de la f...
PDF
Audio procédural : la révolution WebAssembly ! par Yann ORLAREY
PDF
A la rencontre de Kafka, le log distribué par Florian GARCIA
PDF
Voyage au centre du cerveau humain ou comment manipuler des données binaires ...
PDF
Ciel mon smartphone ! par Damien GOSSET
Kit de survie du marketeur au bois dormant – Digitalisation du marketing par ...
Objets connectés : adapter la technologie aux usages, et pas l’inverse ! par ...
Manager l’innovation : est-ce contradictoire, pertinent, nécessaire ?… par Ma...
Tour d’horizon de l’écosystème React-ien par Guillaume BESSON
Stream processing en mémoire avec Hazelcast Jet par Claire VILLARD
Programming is Fun par Francis BELLANGER
La démarche communautaire au coeur de la croissance de votre entreprise par H...
Qui est ton client ? par Audrey JULIENNE
Cloaking is not a crime par Patrick VALIBUS
Electron, une alternative intéressante ? par Florent MOIGNARD
CSS orienté objet par Lenny ROUANET
Automatiser la mise en production d’un site web par Nicolas KANDEL
Design Sprints : Créons un monde meilleur ! par Jelto VON SCHUCKMANN
Fontes variables, la matrice typographique par Malou VERLOMME
Le design agile : 6 techniques pour designer de façon plus agile par Matthieu...
Réalité virtuelle et augmentée, ces nouvelles technologies au service de la f...
Audio procédural : la révolution WebAssembly ! par Yann ORLAREY
A la rencontre de Kafka, le log distribué par Florian GARCIA
Voyage au centre du cerveau humain ou comment manipuler des données binaires ...
Ciel mon smartphone ! par Damien GOSSET
Ad

Recently uploaded (20)

PDF
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
PDF
Dr. Enrique Segura Ense Group - A Self-Made Entrepreneur And Executive
PDF
Power and position in leadershipDOC-20250808-WA0011..pdf
PDF
COST SHEET- Tender and Quotation unit 2.pdf
PPTX
Probability Distribution, binomial distribution, poisson distribution
PPT
Data mining for business intelligence ch04 sharda
PDF
Deliverable file - Regulatory guideline analysis.pdf
PDF
Ôn tập tiếng anh trong kinh doanh nâng cao
DOCX
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
PPTX
Lecture (1)-Introduction.pptx business communication
PDF
Training And Development of Employee .pdf
PPTX
New Microsoft PowerPoint Presentation - Copy.pptx
PDF
Reconciliation AND MEMORANDUM RECONCILATION
DOCX
Business Management - unit 1 and 2
PPTX
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
DOCX
unit 1 COST ACCOUNTING AND COST SHEET
PPTX
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
PPTX
AI-assistance in Knowledge Collection and Curation supporting Safe and Sustai...
PDF
Types of control:Qualitative vs Quantitative
PDF
A Brief Introduction About Julia Allison
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
Dr. Enrique Segura Ense Group - A Self-Made Entrepreneur And Executive
Power and position in leadershipDOC-20250808-WA0011..pdf
COST SHEET- Tender and Quotation unit 2.pdf
Probability Distribution, binomial distribution, poisson distribution
Data mining for business intelligence ch04 sharda
Deliverable file - Regulatory guideline analysis.pdf
Ôn tập tiếng anh trong kinh doanh nâng cao
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
Lecture (1)-Introduction.pptx business communication
Training And Development of Employee .pdf
New Microsoft PowerPoint Presentation - Copy.pptx
Reconciliation AND MEMORANDUM RECONCILATION
Business Management - unit 1 and 2
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
unit 1 COST ACCOUNTING AND COST SHEET
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
AI-assistance in Knowledge Collection and Curation supporting Safe and Sustai...
Types of control:Qualitative vs Quantitative
A Brief Introduction About Julia Allison

Web Components: It’s all rainbows and unicorns! Is it? par Sara HARKOUSSE

  • 1. Web Components It's all rainbows and unicorns! Is it? Sara HARKOUSSE BlendWebMix Lyon, 26, 27 October 2017 1
  • 2. SARA HARKOUSSE @Sara_harkousse Tech Lead, front-end Web developer at Dassault Systèmes 3D design & PLM software Electronics and Computer Science Engineer by training About me #BlendWebMix #webcomponents 2
  • 3. Women in Tech Duchess France @duchessfr duchess-france.org Elles bougent (Girls on The Move) @ellesbougent ellesbougent.com #BlendWebMix #webcomponents @Sara_harkousse 3
  • 4. Web Components It's all rainbows and unicorns! Is it? 4
  • 5. "The web components revolution" "A Tectonic shift for web development" "Web components are a game changer" Web components' public image #BlendWebMix #webcomponents @Sara_harkousse 5
  • 6. Web components' public image #BlendWebMix #webcomponents @Sara_harkousse "The broken promise of Web Components" 6
  • 7. Motivation #BlendWebMix #webcomponents @Sara_harkousse Modular architecture Filterable Product Table Search Bar Product Table Product Row Product Category Row 7
  • 8. Angular 4.0 Component import { Component } from '@angular/core'; @Component({ selector: 'my-app', template: `<h1>Hello {{name}}</h1>` }) export class AppComponent { name = 'Angular'; } <my-app><h1>Hello Angular</h1></my-app> https://embed.plnkr.co/?show=preview&show=app%2Fapp.component.ts #BlendWebMix #webcomponents @Sara_harkousse Ember 2.16.0 Component <article class="blog-post"> <h1>{{title}}</h1> <p>{{yield}}</p> <p>Edit title: {{input type="text" value=title}}</p> </article> {{#each model as |post|}} {{#blog-post title=post.title}} {{post.body}} {{/blog-post}} {{/each}} https://guides.emberjs.com/v2.12.0/components/defining-a-component/ Polymer 2.0 Element // Define the class for a new element called custom-element class CustomElement extends Polymer.Element { static get is() { return "custom-element"; } constructor() { super(); this.textContent = "I'm a custom-element."; } } // Register the new element with the browser customElements.define(CustomElement.is, CustomElement); <custom-element></custom-element> http://plnkr.co/edit/PaCt2M?p=preview 8
  • 10. #BlendWebMix #webcomponents @Sara_harkousse Harmony happens when there is less learning curve 10
  • 11. Browser support use webcomponents.js #BlendWebMix #webcomponents @Sara_harkousse 11
  • 12. Refresher on web components Web components are a set of web platform APIs that allow you to create new custom, reusable, encapsulated HTML tags to use in web apps.” #BlendWebMix #webcomponents @Sara_harkousse 12
  • 13. Refresher on web components #BlendWebMix #webcomponents @Sara_harkousse HTML Template Tag HTML Imports Custom Elements Shadow DOM 13
  • 14. HTML Template Tag #BlendWebMix #webcomponents @Sara_harkousse <template id="template"> <div id="container"> <img class="webcomponents" src="logo.svg"> </div> </template> 14
  • 15. HTML Template Tag Usage #BlendWebMix #webcomponents @Sara_harkousse var template = document.querySelector('#template'); var clone = template.content.cloneNode(true); var host = document.querySelector('#host'); host.appendChild(clone); 15
  • 16. HTML Template Tag #BlendWebMix #webcomponents @Sara_harkousse A way to add inert DOM elements to your document Not something that's going to revolutionize your apps No two-way data binding, no binding at all 16
  • 17. HTML Imports #BlendWebMix #webcomponents @Sara_harkousse <link rel="import" href="component.html"> <link rel="stylesheet" href="style.css"> <div id="container"> <img class="rotate" src="logo.svg"> </div> <script src="script.js"></script> 17
  • 18. How to get my component? #BlendWebMix #webcomponents @Sara_harkousse var link = document.querySelector('link[rel="import"]'); var content = link.import; // Grab DOM from component.html's document. var el = content.querySelector('#container'); var clone = el.cloneNode(true); var host = document.querySelector('#host'); host.appendChild(clone); 18
  • 19. #BlendWebMix #webcomponents @Sara_harkousse HTML Import requires a polyfill ES module? 19
  • 20. #BlendWebMix #webcomponents @Sara_harkousse ES module // export feature export const Component = // … // import feature import {Component} from '../components/cutom-component.js'; 20
  • 21. #BlendWebMix #webcomponents @Sara_harkousse Shadow DOM A tiny document exists inside of a host element 21
  • 22. #BlendWebMix #webcomponents @Sara_harkousse Key concepts Isolated DOM Scoped CSS 22
  • 23. #BlendWebMix #webcomponents @Sara_harkousse Shadow DOM requires a polyfill Hard to polyfill 23
  • 24. #BlendWebMix #webcomponents @Sara_harkousse Use/Don't use Shadow DOM? callback() { // Use it this.root = this.attachShadow({mode: 'open'}); var template = document.querySelector('#template'); var clone = document.importNode(template.content, true); this.root.appendChild(clone); } callback() { // Don't Use it this.root = this; var template = document.querySelector('#template'); var clone = document.importNode(template.content, true); this.root.appendChild(clone); } 24
  • 25. #BlendWebMix #webcomponents @Sara_harkousse Use/Don't use Shadow DOM? /* Use it */ :host { color: red; } /* Don't use it */ custom-component { color: red; } 25
  • 26. #BlendWebMix #webcomponents @Sara_harkousse Use AND Don't use Shadow DOM if (shadowflag){ this.root = this.attachShadow({mode: 'open'}); } else { this.root = this; } custom-component, :host { color: red; } 26
  • 27. #BlendWebMix #webcomponents @Sara_harkousse Custom Elements class CustomButton extends HTMLElement {...} window.customElements.define('custom-button', CustomButton); <custom-button></custom-button> Acts like a div 27
  • 28. #BlendWebMix #webcomponents @Sara_harkousse Custom Elements class CustomButton extends HTMLButtonElement {...} window.customElements.define('custom-button', CustomButton, {extends: 'button'}); <button is="custom-button" disabled>My button!</button> Acts like a real button 28
  • 29. #BlendWebMix #webcomponents @Sara_harkousse Custom Elements Namespace Dash (-) rule 29
  • 30. #BlendWebMix #webcomponents @Sara_harkousse Custom Elements ES6 Class class Custom-component extends HTMLElement { constructor() { super(); // always call super() first in the ctor. ... } connectedCallback() { ... } disconnectedCallback() { ... } attributeChangedCallback(attrName, oldVal, newVal) { ... } } 30
  • 31. #BlendWebMix #webcomponents @Sara_harkousse Component example Bootstrap Progress Bar <div class="progress"> <div class="progress-bar" style="width: 60%;"> 60% </div> </div> 31
  • 32. window.customElements.define('progress-bar', ProgressBar); // Use <progress-bar></progress-bar> Component example https://jsfiddle.net/sara_harkousse/kwwe75yy/ class ProgressBar extends HTMLElement { constructor() { super(); // always call super() first in the ctor. this.shadow = this.attachShadow({mode: 'open'}); this._complete = 0; } get complete() { return this._complete; } set complete(val) { this.setAttribute('complete', val); } static get observedAttributes() { return ['complete']; } attributeChangedCallback(name, oldval, newval) { var innerBar = this.shadow.querySelector('.progress-bar-inner'); switch(name) { case 'complete': this._complete = parseInt(newval, 10) || 0; innerBar.style.width = this.complete + '%'; innerBar.innerHTML = this.complete + '%'; } } connectedCallback() { var template = `<div class="progress-bar"> <div class="progress-bar-inner">${this.complete}%</div> </div>`; this.shadow.innerHTML = template; } } #BlendWebMix #webcomponents @Sara_harkousse 32
  • 33. #BlendWebMix #webcomponents @Sara_harkousse Components on a page <!doctype html> <html lang="en"> <head> <link rel="import" href="/imports/productRow.html"> </head> <body> <custom-navbar style="compact"></custom-navbar> <custom-toolbar style="full"></custom-toolbar> <custom-pagecontent> <custom-input attr="val"></custom-input> <progress-bar></progress-bar> </custom-pagecontent> <script> document.querySelector('custom-input').dispatchEvent(new CustomEvent('customevent', { detail: { prop: true } })); document.querySelector('progress-bar').addEventListener( 'customevent', function () { // do something } }); </script> </body> </html> 33
  • 34. #BlendWebMix #webcomponents @Sara_harkousse Takeaway Template tag? yeah! why not? Use ES module instead of HTML Imports Use Shadom DOM with a flag Custom Elements?? Go, Go, Go 34
  • 35. #BlendWebMix #webcomponents @Sara_harkousse Takeaway You will understand some of the design decisions of major frameworks if you learn about custom elements 35
  • 36. #BlendWebMix #webcomponents Thanks for listening! Follow for slides @Sara_harkousse https://github.com/SaraHarkousse 36