Skip to content

Instantly share code, notes, and snippets.

const header = document.createElement('header');
const shadowRoot = header.attachShadow({mode: 'open'});
shadowRoot.innerHTML = '<h1>Hello Shadow DOM</h1>';
osui-card:not(:defined) {
/* Pre-style, give layout, replicate card's eventual styles, etc. */
opacity: 0;
transition: opacity 0.3s ease-in-out;
}
<button is="osui-button"></button>
class OSUIButton extends HTMLButtonElement {…}
customElements.define('osui-button', OSUIButton {extends: 'button'});
class CardSectioned extends Card {…}
customElements.define('osui-card-sectioned', CardSectioned );
class Card extends HTMLElement {
// A getter/setter for a disabled property.
get disabled() {
return this.hasAttribute('disabled');
}
constructor() {
// Always call super() first! This is specific to Custom Element and required by the spec.
super();
class Card extends HTMLElement {}
customElements.define('osui-card', Card);
<osui-card></osui-card>
const template = document.querySelector('template');
const node = document.importNode(template.content, true);
document.body.appendChild(node);
<template>
<h1>Hello world</h1>
</template>