Skip to content

Commit 6d99763

Browse files
committed
fix: zero-width rectangles no longer error
1 parent 0aabe33 commit 6d99763

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/primitives/Rectangle.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
import React from "react";
1+
import React from 'react';
22
//
33

44
const defaultStyle = {
55
strokeWidth: 0,
6-
fill: "#333",
6+
fill: '#333',
77
opacity: 1,
88
rx: 0,
9-
ry: 0
9+
ry: 0,
1010
};
1111

12-
export default function Rectangle ({ style, opacity = 1, x1, y1, x2, y2, ...rest }) {
12+
export default function Rectangle({
13+
style,
14+
opacity = 1,
15+
x1,
16+
y1,
17+
x2,
18+
y2,
19+
...rest
20+
}) {
1321
const resolvedStyle = {
1422
...defaultStyle,
15-
...style
23+
...style,
1624
};
1725

1826
const xStart = Math.min(x1, x2);
@@ -26,10 +34,10 @@ export default function Rectangle ({ style, opacity = 1, x1, y1, x2, y2, ...rest
2634
return (
2735
<rect
2836
{...rest}
29-
x={xStart}
30-
y={yStart}
31-
width={width}
32-
height={height}
37+
x={Number.isNaN(xStart) ? 0 : xStart}
38+
y={Number.isNaN(yStart) ? 0 : yStart}
39+
width={Number.isNaN(width) ? 0 : width}
40+
height={Number.isNaN(height) ? 0 : height}
3341
style={resolvedStyle}
3442
/>
3543
);

0 commit comments

Comments
 (0)