Last active
June 5, 2022 13:15
-
-
Save pinkhominid/21128775619699dc26df152479949cd0 to your computer and use it in GitHub Desktop.
Web Component starter
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
customElements.define('my-component', class extends HTMLElement { | |
static get observedAttributes() { | |
return [ | |
// attrs | |
]; | |
} | |
constructor() { | |
super(); | |
this.attachShadow({ mode: 'open' }); | |
this.render(); | |
} | |
attributeChangedCallback(name, oldValue, newValue) { | |
switch(name) { | |
// type converters | |
default: | |
this[name] = newValue; | |
} | |
this.render(); | |
} | |
render() { | |
this.shadowRoot.innerHTML = ` | |
<style> | |
:host { | |
display: block; | |
} | |
:host([hidden]) { | |
display: none !important; | |
} | |
</style> | |
<slot></slot> | |
`; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment