Skip to content

Commit 44653ef

Browse files
committed
Feat: added shape color input
1 parent 397b333 commit 44653ef

File tree

7 files changed

+62
-42
lines changed

7 files changed

+62
-42
lines changed

src/components/controls/select/shape.jsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ const ShapeSelectControls = () => {
7373
}}
7474
/>
7575
)}
76-
7776
<ControlInput
78-
id="shape-color-input"
79-
label="Color"
77+
id="shape-stroke-input"
78+
label="Stroke"
8079
defaultValue={rgbToHex(d3Extended.select(firstElement).style("stroke"))}
8180
type="color"
8281
onChange={(e) => {
@@ -85,6 +84,17 @@ const ShapeSelectControls = () => {
8584
});
8685
}}
8786
/>
87+
<ControlInput
88+
id="shape-fill-input"
89+
label="Fill"
90+
defaultValue={rgbToHex(d3Extended.select(firstElement).style("color"))}
91+
type="color"
92+
onChange={(e) => {
93+
selectedElementIds.forEach((id) => {
94+
d3Extended.selectById(id).style("color", e.target.value);
95+
});
96+
}}
97+
/>
8898
</div>
8999
</div>
90100
);

src/components/core/switch/twin-switch.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const TwinSwitch = ({ values = [], selectedValue, onChange, handleClassName, ...
5252
<div
5353
className={twMerge(
5454
padding,
55-
"absolute flex justify-center items-center bg-blue-600 splash after:opacity-[0.2] rounded-full transition-all duration-medium",
55+
"!absolute flex justify-center items-center bg-blue-600 splash after:opacity-[0.2] rounded-full transition-all duration-medium",
5656
handleClassName
5757
)}
5858
style={handleStyles}

src/components/workspace/elements/seat.jsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,31 @@ export const seatSize = 28;
88
export const seatLabelFontSize = seatSize / 3;
99

1010
const Seat = forwardRef(({ x, y, id, label, categories, category, status, ...props }, ref) => {
11-
let textX = x - seatLabelFontSize / 3.5;
12-
13-
const labelLength = label?.toString()?.length ?? 0;
11+
const categoryObject = useMemo(() => categories?.find?.((c) => c.id === category), [categories, category]);
1412

15-
if (labelLength >= 2) textX -= (seatLabelFontSize / 2.75) * (labelLength - 1);
13+
const textX = useMemo(() => {
14+
let value = (+ref.current?.getAttribute("cx") || x) - seatLabelFontSize / 3.5;
15+
const labelLength = label?.toString()?.length ?? 0;
16+
if (labelLength >= 2) value -= (seatLabelFontSize / 2.75) * (labelLength - 1);
17+
return value;
18+
}, [ref, label, x]);
1619

17-
const categoryObject = useMemo(() => categories?.find?.((c) => c.id === category), [categories, category]);
20+
const textY = useMemo(() => {
21+
return (+ref.current?.getAttribute("cy") || y) + seatLabelFontSize / 2.75;
22+
}, [ref, label, y]);
1823

1924
useEffect(() => {
2025
if (ref.current) {
2126
const seat = d3Extended.select(ref.current);
2227
const seatLabel = d3Extended.selectById(`${id}-label`);
2328
const status = seat.attr(dataAttributes.status);
2429
if (status === SeatStatus.Unavailable || status === SeatStatus.Reserved) {
25-
seat.style("color", seatStatusColors[status].background, "important");
26-
seatLabel?.style("stroke", seatStatusColors[status].label, "important");
30+
seat.style("color", seatStatusColors[status].background);
31+
seatLabel?.style("stroke", seatStatusColors[status].label);
2732
} else {
2833
if (categoryObject) {
29-
seat.style("color", categoryObject.color, "important");
30-
seatLabel?.style("stroke", categoryObject.textColor, "important");
34+
seat.style("color", categoryObject.color);
35+
seatLabel?.style("stroke", categoryObject.textColor);
3136
}
3237
}
3338
}
@@ -49,7 +54,7 @@ const Seat = forwardRef(({ x, y, id, label, categories, category, status, ...pro
4954
<text
5055
id={`${id}-label`}
5156
x={textX}
52-
y={y + seatLabelFontSize / 2.75}
57+
y={textY}
5358
fontSize={seatLabelFontSize}
5459
fontWeight={200}
5560
letterSpacing={1}

src/components/workspace/elements/shape.jsx

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,44 @@ export const resizableRectangle = {
1111
height: 100
1212
};
1313

14-
const Shape = forwardRef(({ x, y, id, name, width, height, rx, resizable, className, color, ...props }, ref) => {
15-
if (name === "RectangleHorizontal") {
14+
const Shape = forwardRef(
15+
({ x, y, id, name, width, height, rx, resizable, className, stroke, color, ...props }, ref) => {
16+
if (name === "RectangleHorizontal") {
17+
return (
18+
<rect
19+
ref={ref}
20+
id={id}
21+
x={x}
22+
y={y}
23+
width={width ?? resizableRectangle.width}
24+
height={height ?? resizableRectangle.height}
25+
rx={rx ?? 15}
26+
className={twMerge(className, resizable && "resizable")}
27+
stroke={stroke}
28+
style={{ color: color ?? "transparent" }}
29+
{...{ [dataAttributes.shape]: "RectangleHorizontal" }}
30+
{...props}
31+
/>
32+
);
33+
}
34+
const Icon = lucide[name];
1635
return (
17-
<rect
18-
ref={ref}
36+
<Icon
1937
id={id}
38+
ref={ref}
2039
x={x}
2140
y={y}
22-
width={width ?? resizableRectangle.width}
23-
height={height ?? resizableRectangle.height}
24-
rx={rx ?? 15}
25-
className={twMerge(className, "fill-transparent", resizable && "resizable")}
26-
stroke={color}
27-
{...{ [dataAttributes.shape]: "RectangleHorizontal" }}
41+
width={width ?? shapeSize}
42+
height={height ?? shapeSize}
43+
className={twMerge(className, "stroke-[0.75]")}
44+
stroke={stroke}
45+
style={{ color: color ?? "transparent" }}
46+
{...{ [dataAttributes.shape]: name }}
2847
{...props}
2948
/>
3049
);
3150
}
32-
const Icon = lucide[name];
33-
return (
34-
<Icon
35-
id={id}
36-
ref={ref}
37-
x={x}
38-
y={y}
39-
width={width ?? shapeSize}
40-
height={height ?? shapeSize}
41-
className={twMerge(className, "stroke-[0.75] fill-transparent")}
42-
stroke={color}
43-
{...{ [dataAttributes.shape]: name }}
44-
{...props}
45-
/>
46-
);
47-
});
51+
);
4852

4953
Shape.displayName = "Shape";
5054

src/components/workspace/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export const Workspace = () => {
3434
y: elem.y,
3535
isSelected: selectedElementIds.includes(elem.id),
3636
label: elem.label,
37-
color: elem.color
37+
color: elem.color,
38+
stroke: elem.stroke
3839
}),
3940
[selectedElementIds]
4041
);

src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export const getImageDimensions = async (base64File) => {
7171

7272
export const rgbToHex = (rgb: string) => {
7373
if (!rgb) return "";
74+
if (rgb.includes("transparent")) return "#ffffff00";
7475
function componentToHex(c) {
7576
const hex = Number(c).toString(16);
7677
return hex.length == 1 ? "0" + hex : hex;

tailwind.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import animate from "tailwindcss-animate";
22

33
/** @type {import('tailwindcss').Config} */
44
export default {
5-
important: true,
65
darkMode: ["class"],
76
content: ["./src/**/*.{js,ts,jsx,tsx,mdx,stories.js,css}"],
87
theme: {

0 commit comments

Comments
 (0)