This file contains hidden or 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
// class InputKnob | |
_drawState() { | |
this._container.style.setProperty('--angle', `${this.value}rad`); | |
} |
This file contains hidden or 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
class InputKnob extends HTMLElement { | |
constructor() { | |
super(); | |
this.attachShadow({ mode: 'open' }); | |
this.shadowRoot.appendChild(template.content.cloneNode(true)); | |
this._container = this.shadowRoot.getElementById('container'); | |
} // ✂️ rest of the class omitted | |
} |
This file contains hidden or 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
const template = document.createElement('template'); | |
template.innerHTML = ` | |
<style> | |
#container { | |
--angle: 0rad; | |
transform: rotate(var(--angle)); | |
} | |
</style> | |
<div id="container" part="container"> | |
<slot></slot> |
This file contains hidden or 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
input-knob::part(container) { | |
display: block; | |
background: #cadbbc; | |
border: 1rem dashed #356211; | |
box-shadow: 0.3rem 0.3rem 0.3rem rgba(0, 0, 0, 0.5); | |
width: 8rem; | |
height: 8rem; | |
} |
This file contains hidden or 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
<style> | |
#container { | |
--angle: 0rad; | |
transform: rotate(var(--angle)); | |
} | |
</style> | |
<div id="container" part="container"> | |
<slot></slot> | |
</div> |
This file contains hidden or 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
{ | |
--angle: 0rad; | |
transform: rotate(var(--angle)); | |
} |
This file contains hidden or 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
input-knob { | |
display: block; | |
background: #cadbbc; | |
border: 1rem dashed #356211; | |
box-shadow: 0.3rem 0.3rem 0.3rem rgba(0, 0, 0, 0.5); | |
width: 8rem; | |
height: 8rem; | |
} |
This file contains hidden or 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
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']; | |
} |
This file contains hidden or 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
const knob = document.querySelector('input-knob'); | |
knob.value = 2; |
This file contains hidden or 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
<input-knob value="1"></input-knob> |