Adrian Faciu
Principal software engineer. Focused on front-end. Learning something new each day. Building things at WeVideo.
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
Datepicker
Grid
Typeahead
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
element name
A class object
built-in element (optionally)
@adrianfaciu
customElements.define(
'word-count',
WordCount,
{ extends: 'p' },
);
@adrianfaciu
@adrianfaciu
let shadow = elementRef.attachShadow({mode: 'open'});
let shadow = elementRef.attachShadow({mode: 'closed'});
@adrianfaciu
@adrianfaciu
@adrianfaciu
<template id="my-paragraph">
<p>My paragraph</p>
</template>
@adrianfaciu
let template = document.getElementById('my-paragraph');
let templateContent = template.content;
document.body.appendChild(templateContent);
@adrianfaciu
<template>
<p>
<slot name="my-text">My default text</slot>
</p>
</template>
@adrianfaciu
<my-paragraph>
<span slot="my-text">
Let's have some different text!
</span>
</my-paragraph>
@adrianfaciu
@adrianfaciu
caniuse.com
@adrianfaciu
caniuse.com
@adrianfaciu
caniuse.com
@adrianfaciu
@adrianfaciu
@adrianfaciu
chromestatus.com
@adrianfaciu
@adrianfaciu
@adrianfaciu
class PopUpInfo extends HTMLElement {
constructor() {
// Always call super first in constructor
super();
// Create a shadow root
var shadow = this.attachShadow({mode: 'open'});
// write element functionality in here
...
}
}
@adrianfaciu
customElements.define('popup-info', PopUpInfo);
@adrianfaciu
<div>
<popup-info></popup-info>
</div>
@adrianfaciu
// Create spans
var wrapper = document.createElement('span');
wrapper.setAttribute('class','wrapper');
var icon = document.createElement('span');
icon.setAttribute('class','icon');
icon.setAttribute('tabindex', 0);
var info = document.createElement('span');
info.setAttribute('class','info');
@adrianfaciu
// Take attribute content and put it inside the span
var text = this.getAttribute('text');
info.textContent = text;
@adrianfaciu
// Insert icon
var imgUrl;
if(this.hasAttribute('img')) {
imgUrl = this.getAttribute('img');
} else {
imgUrl = 'img/default.png';
}
var img = document.createElement('img');
img.src = imgUrl;
icon.appendChild(img);
@adrianfaciu
// Create some CSS to apply to the shadow dom
var style = document.createElement('style');
style.textContent = '.wrapper {' +
// CSS truncated for brevity
@adrianfaciu
// attach the created elements to the shadow dom
shadow.appendChild(style);
shadow.appendChild(wrapper);
wrapper.appendChild(icon);
wrapper.appendChild(info);
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
render() {
return html`<p>Hello, ${this.name}!</p>`;
}
@adrianfaciu
bundlephobia.com
@adrianfaciu
import { LitElement, html, property, customElement }
from 'lit-element';
@customElement('simple-greeting')
export class SimpleGreeting extends LitElement {
@property() name = 'World';
render() {
return html`<p>Hello, ${this.name}!</p>`;
}
}
<simple-greeting name="Everyone"></simple-greeting>
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
import { Component, Prop, h }
from '@stencil/core';
@Component({
tag: 'my-first-component',
})
export class MyComponent {
@Prop() name: string;
render() {
return (
<p>
My name is {this.name}
</p>
);
}
}
@adrianfaciu
<my-first-component name="Max"></my-first-component>
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
@adrianfaciu
slides.com/adrianfaciu/webcomponents
By Adrian Faciu
Talk about Web Components at CodeCamp Timisoara, Oct 19, 2019
Principal software engineer. Focused on front-end. Learning something new each day. Building things at WeVideo.