Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ build
*.log
storybook-static
custom-elements.json
.idea
49 changes: 49 additions & 0 deletions src/potentiometer-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ export class PotentiometerElement extends LitElement {
word-spacing: 0px;
fill: #ffffff;
}
.hide-input {
position: absolute;
clip: rect(0 0 0 0);
width: 1px;
height: 1px;
margin: -1px;
}
input:focus + svg #knob {
stroke: #ccdae3;
}
`;
}

Expand All @@ -53,12 +63,28 @@ export class PotentiometerElement extends LitElement {
const knobDeg = (this.endDegree - this.startDegree) * percent + this.startDegree;

return html`
<input
tabindex="0"
type="range"
class="hide-input"
max="${this.max}"
min="${this.min}"
value="${this.value}"
step="${this.step}"
aria-valuemin="${this.min}"
aria-valuenow="${this.value}"
@focus="${() => this.setFilter('0.3')}"
@blur="${() => this.setFilter('0')}"
@input="${this.onValueChange}"
/>
<svg
role="slider"
width="20mm"
height="20mm"
version="1.1"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
@click="${this.focusInput}"
@mousedown=${this.down}
@mousemove=${this.move}
@mouseup=${this.up}
Expand All @@ -69,6 +95,11 @@ export class PotentiometerElement extends LitElement {
'--knob-angle': knobDeg + 'deg',
})}
>
<defs>
<filter id="outline">
<feDropShadow id="glow" dx="0" dy="0" stdDeviation="0" flood-color="cyan" />
</filter>
</defs>
<rect
x=".15"
y=".15"
Expand All @@ -81,6 +112,7 @@ export class PotentiometerElement extends LitElement {
/>
<rect x="5.4" y=".70" width="9.1" height="1.9" fill="#ccdae3" stroke-width=".15" />
<ellipse
filter="url(#outline)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about controlling this filter directly from CSS? then you don't really need the input event listeners and updating the stdDeviation from JS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always better - will fix :)

id="knob"
cx="9.91"
cy="8.18"
Expand Down Expand Up @@ -120,6 +152,23 @@ export class PotentiometerElement extends LitElement {
`;
}

private focusInput() {
const inputEl: HTMLInputElement | null | undefined = this.shadowRoot?.querySelector(
'.hide-input'
);
inputEl?.focus();
}

setFilter(value: string) {
const glowFilter = this.shadowRoot?.querySelector('#glow');
glowFilter?.setAttribute('stdDeviation', value);
}

private onValueChange(event: KeyboardEvent) {
const target = event.target as HTMLInputElement;
this.updateValue(parseFloat(target.value));
}

private down(event: MouseEvent) {
if (event.button === 0 || window.navigator.maxTouchPoints) {
this.pressed = true;
Expand Down