Factor out checkbox.tsx.

pull/63/head
Atul Varma 2021-03-28 07:38:32 -04:00
rodzic 131c1f31cb
commit c76bcc2d5a
3 zmienionych plików z 32 dodań i 16 usunięć

20
lib/checkbox.tsx 100644
Wyświetl plik

@ -0,0 +1,20 @@
import React from "react";
type CheckboxProps = {
label: string;
onChange: (value: boolean) => void;
value: boolean;
};
export const Checkbox: React.FC<CheckboxProps> = (props) => {
return (
<label>
<input
type="checkbox"
checked={props.value}
onChange={(e) => props.onChange(e.target.checked)}
/>{" "}
{props.label}
</label>
);
};

Wyświetl plik

@ -23,6 +23,7 @@ import { svgScale, SvgTransform } from "../svg-transform";
import { ColorWidget } from "../color-widget"; import { ColorWidget } from "../color-widget";
import { NumericSlider } from "../numeric-slider"; import { NumericSlider } from "../numeric-slider";
import { DEFAULT_BG_COLOR } from "../colors"; import { DEFAULT_BG_COLOR } from "../colors";
import { Checkbox } from "../checkbox";
/** Symbols that can be the "root" (i.e., main body) of a creature. */ /** Symbols that can be the "root" (i.e., main body) of a creature. */
const ROOT_SYMBOLS = SvgVocabulary.items.filter( const ROOT_SYMBOLS = SvgVocabulary.items.filter(
@ -209,14 +210,11 @@ export const CreaturePage: React.FC<{}> = () => {
/> />
</div> </div>
<div className="thingy"> <div className="thingy">
<label> <Checkbox
<input label="Randomly invert symbols"
type="checkbox" value={randomlyInvert}
checked={randomlyInvert} onChange={setRandomlyInvert}
onChange={(e) => setRandomlyInvert(e.target.checked)} />
/>
Randomly invert symbols
</label>
</div> </div>
<div className="thingy"> <div className="thingy">
<button accessKey="r" onClick={newRandomSeed}> <button accessKey="r" onClick={newRandomSeed}>

Wyświetl plik

@ -1,4 +1,5 @@
import React from "react"; import React from "react";
import { Checkbox } from "./checkbox";
import { ColorWidget } from "./color-widget"; import { ColorWidget } from "./color-widget";
import { NumericSlider } from "./numeric-slider"; import { NumericSlider } from "./numeric-slider";
import { SvgSymbolContext, swapColors } from "./svg-symbol"; import { SvgSymbolContext, swapColors } from "./svg-symbol";
@ -28,14 +29,11 @@ export const SymbolContextWidget: React.FC<{
<button onClick={() => updateCtx(swapColors(ctx))}> <button onClick={() => updateCtx(swapColors(ctx))}>
Swap stroke/fill Swap stroke/fill
</button>{" "} </button>{" "}
<label> <Checkbox
<input label="Show specs"
type="checkbox" value={ctx.showSpecs}
checked={ctx.showSpecs} onChange={(showSpecs) => updateCtx({ showSpecs })}
onChange={(e) => updateCtx({ showSpecs: e.target.checked })} />
/>{" "}
Show specs
</label>
{ctx.uniformStrokeWidth !== undefined && ( {ctx.uniformStrokeWidth !== undefined && (
<> <>
<br /> <br />