mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-13 09:17:20 +00:00
# Conflicts: # codecs/cpp.Dockerfile # codecs/imagequant/example.html # codecs/webp/dec/webp_dec.d.ts # codecs/webp/dec/webp_dec.js # codecs/webp/dec/webp_dec.wasm # codecs/webp/enc/webp_enc.d.ts # codecs/webp/enc/webp_enc.js # codecs/webp/enc/webp_enc.wasm # package-lock.json # package.json # src/codecs/tiny.webp # src_old/codecs/encoders.ts # src_old/codecs/processor-worker/tiny.avif # src_old/codecs/processor-worker/tiny.webp # src_old/codecs/tiny.webp # src_old/components/compress/index.tsx # src_old/lib/util.ts # src_old/sw/util.ts
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import { h, Component } from 'preact';
|
|
import * as style from './style.scss';
|
|
import RangeInputElement from '../../custom-els/RangeInput';
|
|
import '../../custom-els/RangeInput';
|
|
import { linkRef, bind } from '../../lib/initial-util';
|
|
|
|
interface Props extends JSX.HTMLAttributes {}
|
|
interface State {}
|
|
|
|
export default class Range extends Component<Props, State> {
|
|
rangeWc?: RangeInputElement;
|
|
|
|
@bind
|
|
private onTextInput(event: Event) {
|
|
const input = event.target as HTMLInputElement;
|
|
const value = input.value.trim();
|
|
if (!value) return;
|
|
this.rangeWc!.value = input.value;
|
|
const { onInput } = this.props;
|
|
if (onInput) onInput(event);
|
|
}
|
|
|
|
render(props: Props) {
|
|
const { children, ...otherProps } = props;
|
|
|
|
const { value, min, max, step } = props;
|
|
|
|
return (
|
|
<label class={style.range}>
|
|
<span class={style.labelText}>{children}</span>
|
|
{/* On interaction, Safari gives focus to the first element in the label, so the
|
|
<range-input> is deliberately first. */}
|
|
<div class={style.rangeWcContainer}>
|
|
<range-input
|
|
ref={linkRef(this, 'rangeWc')}
|
|
class={style.rangeWc}
|
|
{...otherProps}
|
|
/>
|
|
</div>
|
|
<input
|
|
type="number"
|
|
class={style.textInput}
|
|
value={value}
|
|
min={min}
|
|
max={max}
|
|
step={step}
|
|
onInput={this.onTextInput}
|
|
/>
|
|
</label>
|
|
);
|
|
}
|
|
}
|