tags • Create reusable components using nothing more than vanilla JS / HTML / CSS • Combines the features offered by most modern browsers • An approach to modernizing HTML @hardikpthv class FrontManiaDrawer extends HTMLElement { ... } window.customElements.define('front-mania-drawer', FrontManiaDrawer); front-mania-drawer.js <front-mania-drawer></front-mania-drawer> index.html
◦ CSS:!important (specificity) ◦ CSS Containment What is it? @hardikpthv • Shadow DOM is the rescuer: ◦ Support for the scoped style ◦ Neither tools nor naming conventions ◦ Self-contained component • An option to provide HTML and CSS to your custom element • Just like a DOM, but not a DOM. (Isolation from DOM tree, although it’s a part of it.)
you write HTML templates in JavaScript using `template literals` • Lazily rendered • Possible to style, bind to attributes, properties, and add event listeners lit-html @hardikpthv // Import lit-html import {html, render} from 'lit-html'; // Define a template const eventTemplate = (eventName) => html`<h1>Welcome to ${eventName}</h1>`; // Render the template to the document render(eventTemplate('FrontMania'), document.body); index.js
lightweight web components • Work in any web page with any framework • Uses lit-html to render • Reactive properties, async updates for elements, life cycle hooks. LitElement @hardikpthv import { LitElement, html } from 'lit-element'; class FrontManiaDrawer extends LitElement { render(){ ... } } customElements.define('front-mania-drawer', FrontManiaDrawer); front-mania-drawer.js