diff --git a/lib/pages/creature-page.tsx b/lib/pages/creature-page.tsx index 9283f0c..26939de 100644 --- a/lib/pages/creature-page.tsx +++ b/lib/pages/creature-page.tsx @@ -11,6 +11,7 @@ import { getAttachmentTransforms } from "../attach"; import { scalePointXY } from "../point"; import { Point } from "../../vendor/bezier-js"; import { Random } from "../random"; +import { SymbolContextWidget } from "../symbol-context-widget"; const SYMBOL_MAP = new Map( SvgVocabulary.map((symbol) => [symbol.name, symbol]) @@ -269,13 +270,13 @@ const AutoSizingSvg: React.FC<{ }; export const CreaturePage: React.FC<{}> = () => { - const [showSpecs, setShowSpecs] = useState(false); const [randomSeed, setRandomSeed] = useState(null); + const [symbolCtx, setSymbolCtx] = useState(createSvgSymbolContext()); const defaultCtx = useContext(CreatureContext); const ctx: CreatureContextType = { ...defaultCtx, - fill: showSpecs ? "none" : defaultCtx.fill, - showSpecs, + ...symbolCtx, + fill: symbolCtx.showSpecs ? "none" : symbolCtx.fill, }; const creature = randomSeed === null @@ -285,16 +286,7 @@ export const CreaturePage: React.FC<{}> = () => { return ( <>

Creature!

-

- -

+

diff --git a/lib/pages/vocabulary-page.tsx b/lib/pages/vocabulary-page.tsx index 4cf1ebf..dfa7c0f 100644 --- a/lib/pages/vocabulary-page.tsx +++ b/lib/pages/vocabulary-page.tsx @@ -7,6 +7,7 @@ import { } from "../svg-symbol"; import { SvgVocabulary } from "../svg-vocabulary"; import { SvgSymbolContext } from "../svg-symbol"; +import { SymbolContextWidget } from "../symbol-context-widget"; type SvgSymbolProps = { data: SvgSymbolData; @@ -35,38 +36,12 @@ const SvgSymbol: React.FC = (props) => { }; export const VocabularyPage: React.FC<{}> = () => { - const [stroke, setStroke] = useState("#000000"); - const [fill, setFill] = useState("#ffffff"); - const [showSpecs, setShowSpecs] = useState(false); - const ctx = createSvgSymbolContext({ stroke, fill, showSpecs }); + const [ctx, setCtx] = useState(createSvgSymbolContext()); return ( <>

Mystic Symbolic Vocabulary

-

- - setStroke(e.target.value)} - id="stroke" - />{" "} - - setFill(e.target.value)} - id="fill" - />{" "} - -

+ {SvgVocabulary.map((symbolData) => (
void; +}> = ({ ctx, onChange }) => { + const updateCtx = (updates: Partial) => { + onChange({ ...ctx, ...updates }); + }; + + return ( +

+ + updateCtx({ stroke: e.target.value })} + id="stroke" + />{" "} + + updateCtx({ fill: e.target.value })} + id="fill" + />{" "} + +

+ ); +};