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

61 wiersze
1.6 KiB
TypeScript
Czysty Zwykły widok Historia

import React from "react";
2021-03-28 11:38:32 +00:00
import { Checkbox } from "./checkbox";
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 type SymbolContextWidgetProps<T extends SvgSymbolContext> = {
ctx: T;
onChange: (value: T) => void;
children?: any;
extraButtons?: JSX.Element;
};
export function SymbolContextWidget<T extends SvgSymbolContext>({
ctx,
children,
onChange,
extraButtons,
}: SymbolContextWidgetProps<T>): JSX.Element {
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>{" "}
{extraButtons}
2021-03-28 11:38:32 +00:00
<Checkbox
label="Show specs"
value={ctx.showSpecs}
onChange={(showSpecs) => updateCtx({ showSpecs })}
/>
2021-02-19 03:13:01 +00:00
{ctx.uniformStrokeWidth !== undefined && (
<div className="thingy">
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 })}
/>
</div>
2021-02-19 03:13:01 +00:00
)}
2021-03-27 12:34:22 +00:00
</div>
);
}