joicomponents
Version:
Design patterns to build native web components
35 lines (29 loc) • 846 B
HTML
<template>
<style>
div { border: 4px solid green; }
</style>
<div>
<slot></slot>
</div>
</template>
<script type="module">
import {SlotchangeMixin} from "../../src/slot/SlotchangeMixin.js";
class GreenFrame extends SlotchangeMixin(HTMLElement) {
constructor() {
super();
this.attachShadow({mode: "open"});
const templ = document.querySelector("template").content.cloneNode(true);
this.shadowRoot.appendChild(templ);
}
slotchangeCallback(slot){
console.log(slot);
}
}
customElements.define("green-frame", GreenFrame);
document.addEventListener("DOMContentLoaded", function () {
const div = document.querySelector("div");
div.innerHTML = "<green-frame>¯\\_(ツ)_/¯</green-frame>";
});
</script>
<green-frame>¯\_(ツ)_/¯</green-frame>
<div>fill me up!</div>