Auto-generate id attributes by default.

pull/59/head
Atul Varma 2021-03-27 08:11:07 -04:00
rodzic 4bd30bb2a5
commit a19a560b8f
6 zmienionych plików z 27 dodań i 46 usunięć

Wyświetl plik

@ -1,20 +1,25 @@
import React from "react"; import React from "react";
import { slugify } from "./util";
type ColorWidgetProps = { type ColorWidgetProps = {
label: string; label: string;
value: string; value: string;
onChange: (value: string) => void; onChange: (value: string) => void;
id: string; id?: string;
}; };
export const ColorWidget: React.FC<ColorWidgetProps> = (props) => ( export const ColorWidget: React.FC<ColorWidgetProps> = (props) => {
<> const id = props.id || slugify(props.label);
<label htmlFor={props.id}>{props.label}: </label>
<input return (
id={props.id} <>
type="color" <label htmlFor={id}>{props.label}: </label>
value={props.value} <input
onChange={(e) => props.onChange(e.target.value)} id={id}
/> type="color"
</> value={props.value}
); onChange={(e) => props.onChange(e.target.value)}
/>
</>
);
};

Wyświetl plik

@ -1,8 +1,8 @@
import React from "react"; import React from "react";
import { float } from "./util"; import { float, slugify } from "./util";
export type NumericSliderProps = { export type NumericSliderProps = {
id: string; id?: string;
label: string; label: string;
onChange: (value: number) => void; onChange: (value: number) => void;
value: number; value: number;
@ -13,12 +13,14 @@ export type NumericSliderProps = {
}; };
export const NumericSlider: React.FC<NumericSliderProps> = (props) => { export const NumericSlider: React.FC<NumericSliderProps> = (props) => {
const id = props.id || slugify(props.label);
return ( return (
<p> <p>
<label htmlFor={props.id}>{props.label}: </label> <label htmlFor={id}>{props.label}: </label>
<input <input
type="range" type="range"
id={props.id} id={id}
min={props.min} min={props.min}
max={props.max} max={props.max}
value={props.value} value={props.value}

Wyświetl plik

@ -199,16 +199,10 @@ export const CreaturePage: React.FC<{}> = () => {
<> <>
<h1>Creature!</h1> <h1>Creature!</h1>
<SymbolContextWidget ctx={symbolCtx} onChange={setSymbolCtx}> <SymbolContextWidget ctx={symbolCtx} onChange={setSymbolCtx}>
<ColorWidget <ColorWidget label="Background" value={bgColor} onChange={setBgColor} />{" "}
label="Background"
id="bgColor"
value={bgColor}
onChange={setBgColor}
/>{" "}
</SymbolContextWidget> </SymbolContextWidget>
<p> <p>
<NumericSlider <NumericSlider
id="complexity"
label="Random creature complexity" label="Random creature complexity"
min={0} min={0}
max={MAX_COMPLEXITY_LEVEL} max={MAX_COMPLEXITY_LEVEL}

Wyświetl plik

@ -69,12 +69,7 @@ export const MandalaPage: React.FC<{}> = () => {
<> <>
<h1>Mandala!</h1> <h1>Mandala!</h1>
<SymbolContextWidget ctx={symbolCtx} onChange={setSymbolCtx}> <SymbolContextWidget ctx={symbolCtx} onChange={setSymbolCtx}>
<ColorWidget <ColorWidget label="Background" value={bgColor} onChange={setBgColor} />{" "}
label="Background"
id="bgColor"
value={bgColor}
onChange={setBgColor}
/>{" "}
</SymbolContextWidget> </SymbolContextWidget>
<p> <p>
<SvgSymbolWidget <SvgSymbolWidget
@ -84,7 +79,6 @@ export const MandalaPage: React.FC<{}> = () => {
choices={SvgVocabulary} choices={SvgVocabulary}
/> />
<NumericSlider <NumericSlider
id="radius"
label="Radius" label="Radius"
value={radius} value={radius}
onChange={setRadius} onChange={setRadius}
@ -93,7 +87,6 @@ export const MandalaPage: React.FC<{}> = () => {
step={1} step={1}
/> />
<NumericSlider <NumericSlider
id="symbols"
label="Numer of symbols" label="Numer of symbols"
value={numSymbols} value={numSymbols}
onChange={setNumSymbols} onChange={setNumSymbols}

Wyświetl plik

@ -108,16 +108,10 @@ const Waves: React.FC<{}> = () => {
{waves} {waves}
</svg> </svg>
<p> <p>
<ColorWidget <ColorWidget value={stroke} onChange={setStroke} label="Stroke" />{" "}
id="stroke" <ColorWidget value={fill} onChange={setFill} label="Fill" />
value={stroke}
onChange={setStroke}
label="Stroke"
/>{" "}
<ColorWidget id="fill" value={fill} onChange={setFill} label="Fill" />
</p> </p>
<NumericSlider <NumericSlider
id="numWaves"
label="Number of waves" label="Number of waves"
min={1} min={1}
max={NUM_WAVES * 2} max={NUM_WAVES * 2}
@ -126,7 +120,6 @@ const Waves: React.FC<{}> = () => {
onChange={setNumWaves} onChange={setNumWaves}
/> />
<NumericSlider <NumericSlider
id="duration"
label="Cycle duration" label="Cycle duration"
min={0.1} min={0.1}
max={3} max={3}
@ -136,7 +129,6 @@ const Waves: React.FC<{}> = () => {
valueSuffix="s" valueSuffix="s"
/> />
<NumericSlider <NumericSlider
id="initialYVel"
label="Initial y-velocity" label="Initial y-velocity"
min={1} min={1}
max={WAVE_PARALLAX_TRANSLATE_VELOCITY * 4} max={WAVE_PARALLAX_TRANSLATE_VELOCITY * 4}
@ -145,7 +137,6 @@ const Waves: React.FC<{}> = () => {
onChange={setInitialYVel} onChange={setInitialYVel}
/> />
<NumericSlider <NumericSlider
id="yAccel"
label="Y-acceleration" label="Y-acceleration"
min={1} min={1}
max={WAVE_PARALLAX_TRANSLATE_ACCEL * 2} max={WAVE_PARALLAX_TRANSLATE_ACCEL * 2}
@ -154,7 +145,6 @@ const Waves: React.FC<{}> = () => {
onChange={setYAccel} onChange={setYAccel}
/> />
<NumericSlider <NumericSlider
id="scaleVel"
label="Scale velocity" label="Scale velocity"
min={1.0} min={1.0}
max={2} max={2}

Wyświetl plik

@ -16,13 +16,11 @@ export const SymbolContextWidget: React.FC<{
<p> <p>
{children} {children}
<ColorWidget <ColorWidget
id="stroke"
label="Stroke" label="Stroke"
value={ctx.stroke} value={ctx.stroke}
onChange={(stroke) => updateCtx({ stroke })} onChange={(stroke) => updateCtx({ stroke })}
/>{" "} />{" "}
<ColorWidget <ColorWidget
id="fill"
label="Fill" label="Fill"
value={ctx.fill} value={ctx.fill}
onChange={(fill) => updateCtx({ fill })} onChange={(fill) => updateCtx({ fill })}
@ -42,7 +40,6 @@ export const SymbolContextWidget: React.FC<{
<> <>
<br /> <br />
<NumericSlider <NumericSlider
id="strokeWidth"
label="Stroke width" label="Stroke width"
min={0} min={0}
max={3} max={3}