Skip to content

Instantly share code, notes, and snippets.

@vinyll
Created May 15, 2017 15:06
Show Gist options
  • Save vinyll/d21cf269d8e2554f2aa54d9bbae44a57 to your computer and use it in GitHub Desktop.
Save vinyll/d21cf269d8e2554f2aa54d9bbae44a57 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 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