Skip to content

Instantly share code, notes, and snippets.

@danleyb2
Forked from argyleink/custom.element.js
Created December 12, 2019 17:23
Show Gist options
  • Save danleyb2/326d01526c43777a13b5decf0aa64e03 to your computer and use it in GitHub Desktop.
Save danleyb2/326d01526c43777a13b5decf0aa64e03 to your computer and use it in GitHub Desktop.
custom element with shadow dom
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