Created
May 15, 2017 15:06
-
-
Save vinyll/d21cf269d8e2554f2aa54d9bbae44a57 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 Component extends HTMLElement { | |
constructor(tagName) { | |
super() | |
this.innerHTML = this.render(tagName) | |
} | |
} | |
class XHello extends Component { | |
render(tagName='h1') { | |
return `<${tagName}>${this.getAttribute('name')}</${tagName}>` | |
} | |
} | |
window.customElements.define('x-hello', XHello) | |
class XWorld extends XHello { | |
render() { | |
return ` | |
${super.render('h2')} | |
<style> | |
h2 {color: ${this.getAttribute('color')} | |
</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