Factor out numeric-slider.tsx.

pull/59/head
Atul Varma 2021-03-27 07:24:15 -04:00
rodzic c7d1092cda
commit fbca3b65ba
4 zmienionych plików z 48 dodań i 46 usunięć

Wyświetl plik

@ -0,0 +1,35 @@
import React from "react";
import { float } from "./util";
export type NumericSliderProps = {
id: string;
label: string;
onChange: (value: number) => void;
value: number;
min: number;
max: number;
step: number;
valueSuffix?: string;
};
export const NumericSlider: React.FC<NumericSliderProps> = (props) => {
return (
<p>
<label htmlFor={props.id}>{props.label}: </label>
<input
type="range"
id={props.id}
min={props.min}
max={props.max}
value={props.value}
step={props.step}
onChange={(e) => props.onChange(float(e.target.value))}
/>
<span>
{" "}
{props.value}
{props.valueSuffix}
</span>
</p>
);
};

Wyświetl plik

@ -21,6 +21,7 @@ import {
import { HoverDebugHelper } from "../hover-debug-helper"; import { HoverDebugHelper } from "../hover-debug-helper";
import { svgScale, SvgTransforms } from "../svg-transform"; import { svgScale, SvgTransforms } from "../svg-transform";
import { ColorWidget } from "../color-widget"; import { ColorWidget } from "../color-widget";
import { NumericSlider } from "../numeric-slider";
const DEFAULT_BG_COLOR = "#858585"; const DEFAULT_BG_COLOR = "#858585";
@ -209,19 +210,18 @@ export const CreaturePage: React.FC<{}> = () => {
/>{" "} />{" "}
</SymbolContextWidget> </SymbolContextWidget>
<p> <p>
<label htmlFor="complexity">Random creature complexity: </label> <NumericSlider
<input id="complexity"
type="range" label="Random creature complexity"
min={0} min={0}
max={MAX_COMPLEXITY_LEVEL} max={MAX_COMPLEXITY_LEVEL}
step={1} step={1}
value={complexity} value={complexity}
onChange={(e) => { onChange={(value) => {
setComplexity(parseInt(e.target.value)); setComplexity(value);
newRandomSeed(); newRandomSeed();
}} }}
/>{" "} />
{complexity}
</p> </p>
<p> <p>
<label> <label>

Wyświetl plik

@ -1,5 +1,6 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { ColorWidget } from "../color-widget"; import { ColorWidget } from "../color-widget";
import { NumericSlider } from "../numeric-slider";
const WAVE_STROKE = "#79beda"; const WAVE_STROKE = "#79beda";
const WAVE_FILL = "#2b7c9e"; const WAVE_FILL = "#2b7c9e";
@ -62,37 +63,6 @@ const WAVE_PARALLAX_SCALE_VELOCITY = 1.25;
const WAVE_PARALLAX_TRANSLATE_VELOCITY = 30; const WAVE_PARALLAX_TRANSLATE_VELOCITY = 30;
const WAVE_PARALLAX_TRANSLATE_ACCEL = 10; const WAVE_PARALLAX_TRANSLATE_ACCEL = 10;
const NumericSlider: React.FC<{
id: string;
label: string;
onChange: (value: number) => void;
value: number;
min: number;
max: number;
step: number;
valueSuffix?: string;
}> = (props) => {
return (
<p>
<label htmlFor={props.id}>{props.label}</label>
<input
type="range"
id={props.id}
min={props.min}
max={props.max}
value={props.value}
step={props.step}
onChange={(e) => props.onChange(parseFloat(e.target.value))}
/>
<span>
{" "}
{props.value}
{props.valueSuffix}
</span>
</p>
);
};
const Waves: React.FC<{}> = () => { const Waves: React.FC<{}> = () => {
const [stroke, setStroke] = useState(WAVE_STROKE); const [stroke, setStroke] = useState(WAVE_STROKE);
const [fill, setFill] = useState(WAVE_FILL); const [fill, setFill] = useState(WAVE_FILL);

Wyświetl plik

@ -1,7 +1,7 @@
import React from "react"; import React from "react";
import { ColorWidget } from "./color-widget"; import { ColorWidget } from "./color-widget";
import { NumericSlider } from "./numeric-slider";
import { SvgSymbolContext, swapColors } from "./svg-symbol"; import { SvgSymbolContext, swapColors } from "./svg-symbol";
import { float } from "./util";
export const SymbolContextWidget: React.FC<{ export const SymbolContextWidget: React.FC<{
ctx: SvgSymbolContext; ctx: SvgSymbolContext;
@ -41,18 +41,15 @@ export const SymbolContextWidget: React.FC<{
{ctx.uniformStrokeWidth !== undefined && ( {ctx.uniformStrokeWidth !== undefined && (
<> <>
<br /> <br />
<label htmlFor="strokeWidth">Stroke width: </label> <NumericSlider
<input id="strokeWidth"
type="range" label="Stroke width"
min={0} min={0}
max={3} max={3}
step={0.1} step={0.1}
value={ctx.uniformStrokeWidth} value={ctx.uniformStrokeWidth}
onChange={(e) => onChange={(uniformStrokeWidth) => updateCtx({ uniformStrokeWidth })}
updateCtx({ uniformStrokeWidth: float(e.target.value) })
}
/>{" "} />{" "}
{ctx.uniformStrokeWidth}{" "}
</> </>
)} )}
</p> </p>