Skip to content

Commit

Permalink
Delete number input in rotary control
Browse files Browse the repository at this point in the history
  • Loading branch information
fatih-erikli committed Nov 14, 2023
1 parent be69fec commit 8a39624
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
24 changes: 2 additions & 22 deletions src/fontra/client/web-components/rotary-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { subVectors } from "../core/vector.js";
export class RotaryControl extends html.UnlitElement {
static styles = `
:host {
--knob-size: 2rem;
--knob-size: 1.4rem;
--thumb-size: calc(var(--knob-size) / 5);
}
Expand All @@ -31,10 +31,6 @@ export class RotaryControl extends html.UnlitElement {
gap: 0.4rem;
margin: 0.2rem;
}
.number-input {
width: 5rem;
}
`;

constructor() {
Expand Down Expand Up @@ -69,9 +65,6 @@ export class RotaryControl extends html.UnlitElement {
if (this.knob) {
this.knob.style.transform = `rotate(${this.value}deg)`;
}
if (this.numberInput) {
this.numberInput.value = this.value;
}
}

get value() {
Expand All @@ -80,20 +73,6 @@ export class RotaryControl extends html.UnlitElement {

render() {
return html.div({ class: "rotary-control" }, [
(this.numberInput = html.input({
class: "number-input",
type: "number",
step: "any",
required: "required",
min: 0,
max: 360,
value: this.value,
onchange: (event) => {
if (event.target.reportValidity()) {
this.value = event.target.valueAsNumber;
}
},
})),
(this.knob = html.div(
{
onwheel: (event) => {
Expand All @@ -102,6 +81,7 @@ export class RotaryControl extends html.UnlitElement {
? -1 * event.deltaX
: event.deltaY;
this.value = this.value + delta;
this.onChangeCallback(this.value);
},
class: "knob",
style: `transform: rotate(${this.value}deg);`,
Expand Down
18 changes: 10 additions & 8 deletions src/fontra/client/web-components/ui-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,17 @@ export class Form extends SimpleElement {
};
this._fieldGetters[fieldItem.key] = () => inputElement.value;
this._fieldSetters[fieldItem.key] = (value) => (inputElement.value = value);
valueElement.appendChild(inputElement);
valueElement.appendChild(
html.createDomElement("rotary-control", {
value: fieldItem.value,
onChangeCallback: (value) => {
inputElement.value = value;
this._fieldChanging(fieldItem.key, value);
},
})
html.div({ style: "display: flex" }, [
inputElement,
html.createDomElement("rotary-control", {
value: fieldItem.value,
onChangeCallback: (value) => {
inputElement.value = value;
this._fieldChanging(fieldItem.key, value);
},
}),
])
);
}

Expand Down

0 comments on commit 8a39624

Please sign in to comment.