2021-02-17 13:07:04 +00:00
|
|
|
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";
|
2021-02-17 13:07:04 +00:00
|
|
|
|
|
|
|
export const SymbolContextWidget: React.FC<{
|
|
|
|
ctx: SvgSymbolContext;
|
|
|
|
onChange: (value: SvgSymbolContext) => void;
|
2021-02-20 16:38:04 +00:00
|
|
|
children?: any;
|
|
|
|
}> = ({ ctx, children, onChange }) => {
|
2021-02-17 13:07:04 +00:00
|
|
|
const updateCtx = (updates: Partial<SvgSymbolContext>) => {
|
|
|
|
onChange({ ...ctx, ...updates });
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2021-03-27 12:34:22 +00:00
|
|
|
<div className="thingy">
|
2021-02-20 16:38:04 +00:00
|
|
|
{children}
|
2021-03-27 11:14:42 +00:00
|
|
|
<ColorWidget
|
|
|
|
label="Stroke"
|
|
|
|
value={ctx.stroke}
|
|
|
|
onChange={(stroke) => updateCtx({ stroke })}
|
2021-02-17 13:07:04 +00:00
|
|
|
/>{" "}
|
2021-03-27 11:14:42 +00:00
|
|
|
<ColorWidget
|
|
|
|
label="Fill"
|
|
|
|
value={ctx.fill}
|
|
|
|
onChange={(fill) => updateCtx({ fill })}
|
2021-02-17 13:07:04 +00:00
|
|
|
/>{" "}
|
2021-03-06 00:38:25 +00:00
|
|
|
<button onClick={() => updateCtx(swapColors(ctx))}>
|
|
|
|
Swap stroke/fill
|
|
|
|
</button>{" "}
|
2021-02-17 13:07:04 +00:00
|
|
|
<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"
|
2021-02-20 16:41:41 +00:00
|
|
|
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>
|
2021-02-17 13:07:04 +00:00
|
|
|
);
|
|
|
|
};
|