Skip to content

Instantly share code, notes, and snippets.

@rowan-m
Created August 27, 2019 09:03
Show Gist options
  • Save rowan-m/7a8b6a9f0cc2e00c2a391357dba2483a to your computer and use it in GitHub Desktop.
Save rowan-m/7a8b6a9f0cc2e00c2a391357dba2483a to your computer and use it in GitHub Desktop.
class InputKnob extends HTMLElement {
constructor() {
// Nothing to do in here at the moment, but we do need to call the parent
// constructor
super();
}
// Watch for changes on the 'value' attribute
static get observedAttributes() {
return ['value'];
}
// Map the JavaScript property to the HTML attribute
get value() {
return this.hasAttribute('value') ? this.getAttribute('value') : 0;
}
set value(value) {
this.setAttribute('value', value);
}
// Respond to any changes to the observed attributes
attributeChangedCallback(attrName, oldVal, newVal) {
// nothing yet
}
}
// Map the class to an element name and make it available to the page!
window.customElements.define('input-knob', InputKnob);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment