Factor out getColor().
rodzic
a135b6930b
commit
2b0d69bb87
|
@ -32,21 +32,27 @@ type SvgSymbolProps = {
|
||||||
|
|
||||||
const px = (value: number) => `${value}px`;
|
const px = (value: number) => `${value}px`;
|
||||||
|
|
||||||
|
function getColor(
|
||||||
|
ctx: SvgSymbolContext,
|
||||||
|
color: string | undefined
|
||||||
|
): string | undefined {
|
||||||
|
switch (color) {
|
||||||
|
case STROKE_REPLACEMENT_COLOR:
|
||||||
|
return ctx.stroke;
|
||||||
|
case FILL_REPLACEMENT_COLOR:
|
||||||
|
return ctx.fill;
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
function reactifySvgSymbolElement(
|
function reactifySvgSymbolElement(
|
||||||
ctx: SvgSymbolContext,
|
ctx: SvgSymbolContext,
|
||||||
el: SvgSymbolElement,
|
el: SvgSymbolElement,
|
||||||
key: number
|
key: number
|
||||||
): JSX.Element {
|
): JSX.Element {
|
||||||
let { fill, stroke } = el.props;
|
let { fill, stroke } = el.props;
|
||||||
if (fill === STROKE_REPLACEMENT_COLOR) {
|
fill = getColor(ctx, fill);
|
||||||
// The fill represents a "shadow" area, so use our stroke color here.
|
stroke = getColor(ctx, stroke);
|
||||||
fill = ctx.stroke;
|
|
||||||
} else if (fill === FILL_REPLACEMENT_COLOR) {
|
|
||||||
fill = ctx.fill;
|
|
||||||
}
|
|
||||||
if (stroke === STROKE_REPLACEMENT_COLOR) {
|
|
||||||
stroke = ctx.stroke;
|
|
||||||
}
|
|
||||||
return React.createElement(
|
return React.createElement(
|
||||||
el.tagName,
|
el.tagName,
|
||||||
{
|
{
|
||||||
|
|
Ładowanie…
Reference in New Issue