Skip to content

Commit 97c6346

Browse files
committed
Fix outline layer rendering on top, and outline opacity prop name
1 parent d209720 commit 97c6346

7 files changed

Lines changed: 27 additions & 23 deletions

File tree

src/components/ShapeBase.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const ShapeBase = forwardRef<SVGSVGElement, ShapeProps>((props, ref) => {
3333
outlineCap,
3434
outlineJoin,
3535
outlineColor,
36-
strokeOpacity,
36+
outlineOpacity,
3737
...rest
3838
} = props;
3939

@@ -53,10 +53,20 @@ const ShapeBase = forwardRef<SVGSVGElement, ShapeProps>((props, ref) => {
5353
style={{
5454
overflow: outline ? "visible" : "initial",
5555
}}
56-
fillOpacity={strokeOpacity ? opacity : undefined}
57-
opacity={strokeOpacity ? undefined : opacity}
56+
fillOpacity={outlineOpacity ? opacity : undefined}
57+
opacity={outlineOpacity ? undefined : opacity}
5858
{...rest}
5959
className={`${defaultClassName} ${shapeId} ${className || ""}`}>
60+
{props.outline && (
61+
<Outline
62+
shape={shape}
63+
outline={outline as number}
64+
outlineFill={outlineColor}
65+
outlineJoin={outlineJoin}
66+
outlineCap={outlineCap}
67+
opacity={outlineOpacity}
68+
/>
69+
)}
6070
<ShapeMask
6171
shape={shape}
6272
noise={noise}
@@ -74,16 +84,6 @@ const ShapeBase = forwardRef<SVGSVGElement, ShapeProps>((props, ref) => {
7484
noiseScale={typeof noise === "number" ? defaultNoise : undefined}
7585
/>
7686
)}
77-
{props.outline && (
78-
<Outline
79-
shape={shape}
80-
outline={outline as number}
81-
outlineColor={outlineColor}
82-
outlineJoin={outlineJoin}
83-
outlineCap={outlineCap}
84-
opacity={strokeOpacity}
85-
/>
86-
)}
8787
</svg>
8888
);
8989
});

src/components/ShapeMask.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Gradient, MaskProps, ShapeElementTypes } from "../lib/types";
2-
import React, { cloneElement, Fragment, ReactSVGElement } from "react";
2+
import React, { cloneElement, Fragment } from "react";
33
import { angleToBoxCoords } from "../lib";
44
import { resolveGradientStops } from "../lib/utils/shape";
55

@@ -8,7 +8,7 @@ export const ShapeMask = (props: MaskProps) => {
88
let gradientBlur = props.blur;
99
let gradientShapes: ShapeElementTypes | ShapeElementTypes[] =
1010
props.gradientShapes || [];
11-
let shapeProp = props.shape;
11+
const shapeProp = props.shape;
1212
let shapeElement: ShapeElementTypes;
1313

1414
// Resolve mask gradient

src/components/ShapeOutline.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ export default function Outline(props: {
55
opacity?: number | string;
66
shape: MaskShape;
77
outline: number | string;
8-
outlineColor?: string;
8+
outlineFill?: string;
99
outlineJoin?: OutlineJoin;
1010
outlineCap?: OutlineCap;
1111
}) {
1212
const params = {
1313
fill: "none",
14-
stroke: props.outlineColor || "#000",
15-
strokeWidth: props.outline,
14+
stroke: props.outlineFill || "#000",
15+
strokeWidth: Number(props.outline) * 2,
1616
strokeLinejoin: props.outlineJoin || "bevel",
1717
strokeLinecap: props.outlineCap || "round",
1818
strokeOpacity: props.opacity || 1,

src/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
export { getRandomShape } from "./lib/shape";
1+
export {default as ShapeBase} from "./components/ShapeBase";
2+
3+
export { getRandomShape, createShapeComponent } from "./lib/shape";
24
export * from "./CoolShape";
35
export * from "./shapes";
46
export * from "./dynamicImports";
57
export { default as shapesData } from "./shapes/data";
68
export * from "./gradients";
79
export * from "./lib/types";
8-
export * from './lib/common';
10+
export * from './lib/common';
11+

src/lib/types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export interface OutlineProps {
7676
outlineColor: string;
7777
outlineCap: OutlineCap;
7878
outlineJoin: OutlineJoin;
79+
outlineOpacity: number | string
7980
}
8081

8182
export type GradientProp =

stats.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/shape.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ describe("Using create component function", () => {
4646
outlineColor: "red",
4747
outlineCap: "butt" as OutlineCap,
4848
outlineJoin: "mitter" as OutlineJoin,
49-
strokeOpacity: 10,
49+
outlineOpacity: 10,
5050
};
51-
const query = `[fill="none"][stroke="red"][stroke-width="2"][stroke-linecap="butt"][stroke-opacity="10"][stroke-linejoin="mitter"]`;
51+
const query = `[fill="none"][stroke="red"][stroke-width="4"][stroke-linecap="butt"][stroke-opacity="10"][stroke-linejoin="mitter"]`;
5252
const { getByTestId } = render(<Component data-testid={"shape"} {...outlineProps} />);
5353
const element = getByTestId("shape");
5454
// The shape component overflow sets to visible that make sure the outline doesn't clip

0 commit comments

Comments
 (0)