Last active
May 9, 2017 08:07
-
-
Save vinyll/bbec11b08ed9dfd183521a9245580573 to your computer and use it in GitHub Desktop.
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
<meta charset=utf-8> | |
<script src=https://gitcdn.xyz/repo/webcomponents/custom-elements/master/custom-elements.min.js></script> | |
<x-hello name=Native></x-hello> | |
<x-world name=Component color=red></x-world> | |
<script> | |
class XHello extends HTMLElement { | |
constructor(tagName) { | |
super() | |
const container = document.createElement(tagName || 'h1') | |
container.textContent = this.getAttribute('name') | |
this.appendChild(container) | |
} | |
} | |
window.customElements.define('x-hello', XHello); | |
class XWorld extends XHello { | |
constructor() { | |
super('h2') | |
const style = document.createElement('style') | |
style.innerHTML = `h2 {color: ${this.getAttribute('color')}}` | |
this.appendChild(style) | |
} | |
} | |
window.customElements.define('x-world', XWorld); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment