Last active
May 4, 2023 14:05
-
-
Save AVGP/d693b4954a1e004c298e to your computer and use it in GitHub Desktop.
A simple web component boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<style> | |
</style> | |
</template> | |
<script> | |
var Element = null; | |
(function(currentScript) { | |
var elemPrototype = Object.create(HTMLDivElement.prototype); // pick the appropriate prototype for your element! | |
// Private properties | |
// Public Properties | |
// Helpers | |
// Lifecycle callbacks | |
elemPrototype.createdCallback = function() { | |
this.root = this.createShadowRoot(); | |
var tplContent = currentScript.ownerDocument.querySelector('template').content, | |
node = document.importNode(tplContent, true); | |
this.root.appendChild(node); | |
}; | |
elemPrototype.attachedCallback = function() { | |
}; | |
Element = document.registerElement('my-element', { prototype: elemPrototype }); | |
}(document.currentScript || document._currentScript)); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment