mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-11 16:26:20 +00:00
Text fields with inputs do the right thing
This commit is contained in:
@@ -26,7 +26,7 @@ export default class ResizerOptions extends Component<Props, State> {
|
|||||||
|
|
||||||
form?: HTMLFormElement;
|
form?: HTMLFormElement;
|
||||||
|
|
||||||
reportOptions() {
|
private reportOptions() {
|
||||||
const width = this.form!.width as HTMLInputElement;
|
const width = this.form!.width as HTMLInputElement;
|
||||||
const height = this.form!.height as HTMLInputElement;
|
const height = this.form!.height as HTMLInputElement;
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ export default class ResizerOptions extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
onChange(event: Event) {
|
private onChange() {
|
||||||
this.reportOptions();
|
this.reportOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,19 +54,23 @@ export default class ResizerOptions extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
onWidthInput(event: Event) {
|
private onWidthInput() {
|
||||||
if (!this.state.maintainAspect) return;
|
if (this.state.maintainAspect) {
|
||||||
|
const width = inputFieldValueAsNumber(this.form!.width);
|
||||||
|
this.form!.height.value = Math.round(width / this.props.aspect);
|
||||||
|
}
|
||||||
|
|
||||||
const width = inputFieldValueAsNumber(this.form!.width);
|
this.reportOptions();
|
||||||
this.form!.height.value = Math.round(width / this.props.aspect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
onHeightInput(event: Event) {
|
private onHeightInput() {
|
||||||
if (!this.state.maintainAspect) return;
|
if (this.state.maintainAspect) {
|
||||||
|
const height = inputFieldValueAsNumber(this.form!.height);
|
||||||
|
this.form!.width.value = Math.round(height * this.props.aspect);
|
||||||
|
}
|
||||||
|
|
||||||
const height = inputFieldValueAsNumber(this.form!.height);
|
this.reportOptions();
|
||||||
this.form!.width.value = Math.round(height * this.props.aspect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render({ options, isVector }: Props, { maintainAspect }: State) {
|
render({ options, isVector }: Props, { maintainAspect }: State) {
|
||||||
@@ -95,7 +99,6 @@ export default class ResizerOptions extends Component<Props, State> {
|
|||||||
type="number"
|
type="number"
|
||||||
min="1"
|
min="1"
|
||||||
value={'' + options.width}
|
value={'' + options.width}
|
||||||
onChange={this.onChange}
|
|
||||||
onInput={this.onWidthInput}
|
onInput={this.onWidthInput}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
@@ -108,7 +111,7 @@ export default class ResizerOptions extends Component<Props, State> {
|
|||||||
type="number"
|
type="number"
|
||||||
min="1"
|
min="1"
|
||||||
value={'' + options.height}
|
value={'' + options.height}
|
||||||
onChange={this.onChange}
|
onInput={this.onHeightInput}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<label class={style.optionInputFirst}>
|
<label class={style.optionInputFirst}>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { h, Component } from 'preact';
|
|||||||
import * as style from './style.scss';
|
import * as style from './style.scss';
|
||||||
import RangeInputElement from '../../custom-els/RangeInput';
|
import RangeInputElement from '../../custom-els/RangeInput';
|
||||||
import '../../custom-els/RangeInput';
|
import '../../custom-els/RangeInput';
|
||||||
import { linkRef } from '../../lib/initial-util';
|
import { linkRef, bind } from '../../lib/initial-util';
|
||||||
|
|
||||||
interface Props extends JSX.HTMLAttributes {}
|
interface Props extends JSX.HTMLAttributes {}
|
||||||
interface State {}
|
interface State {}
|
||||||
@@ -10,6 +10,14 @@ interface State {}
|
|||||||
export default class Range extends Component<Props, State> {
|
export default class Range extends Component<Props, State> {
|
||||||
rangeWc?: RangeInputElement;
|
rangeWc?: RangeInputElement;
|
||||||
|
|
||||||
|
@bind
|
||||||
|
private onTextInput(event: Event) {
|
||||||
|
const input = event.target as HTMLInputElement;
|
||||||
|
this.rangeWc!.value = input.value;
|
||||||
|
const { onInput } = this.props;
|
||||||
|
if (onInput) onInput(event);
|
||||||
|
}
|
||||||
|
|
||||||
render(props: Props) {
|
render(props: Props) {
|
||||||
const {
|
const {
|
||||||
children,
|
children,
|
||||||
@@ -17,7 +25,7 @@ export default class Range extends Component<Props, State> {
|
|||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
value, min, max, onInput,
|
value, min, max,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -29,7 +37,7 @@ export default class Range extends Component<Props, State> {
|
|||||||
value={value}
|
value={value}
|
||||||
min={min}
|
min={min}
|
||||||
max={max}
|
max={max}
|
||||||
onInput={onInput}
|
onInput={this.onTextInput}
|
||||||
/>
|
/>
|
||||||
<div class={style.rangeWcContainer}>
|
<div class={style.rangeWcContainer}>
|
||||||
<range-input
|
<range-input
|
||||||
|
|||||||
Reference in New Issue
Block a user