mysticsymbolic.github.io/lib/symbol-context-widget.tsx

55 wiersze
1.4 KiB
TypeScript
Czysty Zwykły widok Historia

import React from "react";
2021-03-27 11:14:42 +00:00
import { ColorWidget } from "./color-widget";
2021-03-27 11:24:15 +00:00
import { NumericSlider } from "./numeric-slider";
2021-03-06 00:38:25 +00:00
import { SvgSymbolContext, swapColors } from "./svg-symbol";
export const SymbolContextWidget: React.FC<{
ctx: SvgSymbolContext;
onChange: (value: SvgSymbolContext) => void;
children?: any;
}> = ({ ctx, children, onChange }) => {
const updateCtx = (updates: Partial<SvgSymbolContext>) => {
onChange({ ...ctx, ...updates });
};
return (
2021-03-27 12:34:22 +00:00
<div className="thingy">
{children}
2021-03-27 11:14:42 +00:00
<ColorWidget
label="Stroke"
value={ctx.stroke}
onChange={(stroke) => updateCtx({ stroke })}
/>{" "}
2021-03-27 11:14:42 +00:00
<ColorWidget
label="Fill"
value={ctx.fill}
onChange={(fill) => updateCtx({ fill })}
/>{" "}
2021-03-06 00:38:25 +00:00
<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>
2021-02-19 03:13:01 +00:00
{ctx.uniformStrokeWidth !== undefined && (
<>
<br />
2021-03-27 11:24:15 +00:00
<NumericSlider
label="Stroke width"
min={0}
2021-02-19 03:13:01 +00:00
max={3}
step={0.1}
value={ctx.uniformStrokeWidth}
2021-03-27 11:24:15 +00:00
onChange={(uniformStrokeWidth) => updateCtx({ uniformStrokeWidth })}
2021-02-19 03:13:01 +00:00
/>{" "}
</>
)}
2021-03-27 12:34:22 +00:00
</div>
);
};