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

Wyświetl plik

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