import React, { useState } from "react"; import { Random } from "./random"; import { createRandomColorPalette } from "./random-colors"; import { SvgCompositionContext } from "./svg-composition-context"; type SvgCompositionColors = Pick< SvgCompositionContext, "background" | "fill" | "stroke" >; function createRandomCompositionColors(): SvgCompositionColors { const [background, stroke, fill] = createRandomColorPalette(3); return { background, stroke, fill }; } export type RandomizerWidgetProps = { onColorsChange: (changes: SvgCompositionColors) => void; onSymbolsChange: (rng: Random) => void; }; export const RandomizerWidget: React.FC = (props) => { type RandType = "colors" | "symbols" | "colors and symbols"; const [randType, setRandType] = useState("colors and symbols"); const randomize = () => { if (randType === "colors" || randType === "colors and symbols") { props.onColorsChange(createRandomCompositionColors()); } if (randType === "symbols" || randType === "colors and symbols") { props.onSymbolsChange(new Random(Date.now())); } }; const makeRadio = (kind: RandType) => ( ); return (
Randomizer {makeRadio("colors")} {makeRadio("symbols")} {makeRadio("colors and symbols")}
); };