Skip to content

Instantly share code, notes, and snippets.

@vinyll
Last active May 9, 2017 08:07
Show Gist options
  • Save vinyll/bbec11b08ed9dfd183521a9245580573 to your computer and use it in GitHub Desktop.
Save vinyll/bbec11b08ed9dfd183521a9245580573 to your computer and use it in GitHub Desktop.
<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