Last active
September 12, 2022 12:00
-
-
Save argyleink/ce927517e6b54aa67af0923512cac1be 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