Skip to content

Commit 9a18235

Browse files
author
Sebastian Schürmann
committed
feature(component-webaudio): wa-knob has a svg base visual now
1 parent 8cd5ebc commit 9a18235

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

packages/component-webaudio/src/wa-knob.ts

+44-4
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,54 @@ class WAKnob extends HTMLElement {
6565

6666
private render() {
6767
if (!this.shadowRoot) return;
68+
69+
// Calculate rotation angle based on value
70+
const range = this._max - this._min;
71+
const normalizedValue = (this._value - this._min) / range;
72+
const angle = normalizedValue * 270 - 135; // -135 to +135 degrees range
73+
6874
this.shadowRoot.innerHTML = `
69-
<div class='webaudio-knob-body' tabindex='1' touch-action='none'>
70-
<div class='webaudioctrl-tooltip'></div>
71-
<div part="label" class="webaudioctrl-label">
75+
<style>
76+
.knob-body {
77+
width: 60px;
78+
height: 60px;
79+
display: flex;
80+
flex-direction: column;
81+
align-items: center;
82+
}
83+
.knob-svg {
84+
width: 100%;
85+
height: 100%;
86+
}
87+
.knob-base {
88+
fill: #444;
89+
stroke: #666;
90+
stroke-width: 2;
91+
}
92+
.knob-indicator {
93+
stroke: #fff;
94+
stroke-width: 2;
95+
stroke-linecap: round;
96+
}
97+
.ctrl-label {
98+
margin-top: 5px;
99+
text-align: center;
100+
}
101+
</style>
102+
<div class='knob-body'>
103+
<svg class="knob-svg" viewBox="0 0 60 60">
104+
<circle class="knob-base" cx="30" cy="30" r="25"/>
105+
<line class="knob-indicator"
106+
x1="30"
107+
y1="30"
108+
x2="30"
109+
y2="10"
110+
transform="rotate(${angle}, 30, 30)"/>
111+
</svg>
112+
<div part="label" class="ctrl-label">
72113
<slot></slot>
73114
</div>
74115
</div>
75-
<div>Value: ${this._value} (Min: ${this._min}, Max: ${this._max})</div>
76116
`;
77117
}
78118

0 commit comments

Comments
 (0)