-
-
Save danleyb2/326d01526c43777a13b5decf0aa64e03 to your computer and use it in GitHub Desktop.
custom element with shadow dom
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
export default class CustomElement extends HTMLElement { | |
constructor() { | |
super() | |
this.$shadow = this.attachShadow() | |
this.$shadow.innerHTML = this.render() | |
} | |
connectedCallback() {} | |
disconnectedCallback() {} | |
render() { | |
return ` | |
${this.styles()} | |
<div>Custom Element</div> | |
` | |
} | |
styles() { | |
return ` | |
<style> | |
:host { | |
display: flex; | |
} | |
:host([hidden]) { | |
display: none; | |
} | |
</style> | |
` | |
} | |
} | |
customElements.define('custom-element', CustomElement) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment