Skip to content

Commit bef7313

Browse files
committed
Feat: added polyline color controls
1 parent 44653ef commit bef7313

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

src/components/controls/select/index.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useSelector } from "react-redux";
33
import { ElementType } from "@/components/workspace/elements";
44
import { dataAttributes } from "@/constants";
55
import { default as GeneralSelectControls } from "./general";
6+
import { default as PolylineSelectControls } from "./polyline";
67
import { default as SeatSelectControls } from "./seats";
78
import { default as ShapeSelectControls } from "./shape";
89
import { default as TextSelectControls } from "./text";
@@ -14,6 +15,7 @@ const SelectControls = () => {
1415
const firstElementType = document.getElementById(selectedElementIds[0])?.getAttribute?.(dataAttributes.elementType);
1516
if (firstElementType === ElementType.Text) return TextSelectControls;
1617
if (firstElementType === ElementType.Shape) return ShapeSelectControls;
18+
if (firstElementType === ElementType.Polyline) return PolylineSelectControls;
1719
if (firstElementType === ElementType.Image) return Fragment;
1820
return SeatSelectControls;
1921
}, [selectedElementIds]);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { useSelector } from "react-redux";
2+
import { d3Extended, rgbToHex } from "@/utils";
3+
import { default as ControlInput } from "../control-input";
4+
5+
const PolylineSelectControls = () => {
6+
const selectedElementIds = useSelector((state) => state.editor.selectedElementIds);
7+
8+
const firstElement = document.getElementById(selectedElementIds[0]);
9+
10+
return (
11+
<div className="flex flex-col gap-4 py-1">
12+
<div className="grid grid-cols-3 items-center gap-4">
13+
<ControlInput
14+
id="polyline-stroke-input"
15+
label="Stroke"
16+
defaultValue={rgbToHex(d3Extended.select(firstElement).style("stroke"))}
17+
type="color"
18+
onChange={(e) => {
19+
selectedElementIds.forEach((id) => {
20+
d3Extended.selectById(id).style("stroke", e.target.value);
21+
});
22+
}}
23+
/>
24+
<ControlInput
25+
id="polyline-fill-input"
26+
label="Fill"
27+
defaultValue={rgbToHex(d3Extended.select(firstElement).style("color"))}
28+
type="color"
29+
onChange={(e) => {
30+
selectedElementIds.forEach((id) => {
31+
d3Extended.selectById(id).style("color", e.target.value);
32+
});
33+
}}
34+
/>
35+
</div>
36+
</div>
37+
);
38+
};
39+
40+
export default PolylineSelectControls;

src/components/controls/select/seats/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ const SeatSelectControls = () => {
4848
textColor = category.textColor;
4949
}
5050
}
51-
seat.style("color", color, "important");
52-
seatLabel?.style("stroke", textColor, "important");
51+
seat.style("color", color);
52+
seatLabel?.style("stroke", textColor);
5353
});
5454
}}
5555
className="flex justify-between gap-2 my-1"

src/components/workspace/elements/polyline.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { forwardRef } from "react";
22
import { twMerge } from "tailwind-merge";
33

4-
const Polyline = forwardRef(({ id, points, ...props }, ref) => {
4+
const Polyline = forwardRef(({ id, points, color, stroke, ...props }, ref) => {
55
return (
66
<polyline
77
ref={ref}
88
id={id}
99
points={points.map((p) => `${p.x},${p.y}`).join(" ")}
1010
{...props}
11-
className={twMerge(props.className, "fill-transparent")}
11+
style={{ color: color ?? "transparent", stroke }}
12+
className={twMerge(props.className)}
1213
/>
1314
);
1415
});

src/components/workspace/elements/shape.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ const Shape = forwardRef(
2424
height={height ?? resizableRectangle.height}
2525
rx={rx ?? 15}
2626
className={twMerge(className, resizable && "resizable")}
27-
stroke={stroke}
28-
style={{ color: color ?? "transparent" }}
27+
style={{ color: color ?? "transparent", stroke }}
2928
{...{ [dataAttributes.shape]: "RectangleHorizontal" }}
3029
{...props}
3130
/>
@@ -41,8 +40,7 @@ const Shape = forwardRef(
4140
width={width ?? shapeSize}
4241
height={height ?? shapeSize}
4342
className={twMerge(className, "stroke-[0.75]")}
44-
stroke={stroke}
45-
style={{ color: color ?? "transparent" }}
43+
style={{ color: color ?? "transparent", stroke }}
4644
{...{ [dataAttributes.shape]: name }}
4745
{...props}
4846
/>

0 commit comments

Comments
 (0)