Skip to content

Commit c69a59e

Browse files
committed
Feat: added more element style overrides
1 parent 9e13aaf commit c69a59e

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

src/components/workspace/elements/index.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { memo, useEffect, useRef } from "react";
1+
import { memo, useEffect, useMemo, useRef } from "react";
22
import * as d3 from "d3";
33
import { isEqual } from "lodash";
44
import { twMerge } from "tailwind-merge";
55
import { dataAttributes } from "@/constants";
66
import { store } from "@/store";
77
import { clearAndSelectElements, deselectElement, selectElement } from "@/store/reducers/editor";
8-
import { STKMode } from "@/types";
8+
import { ISTKProps, STKMode } from "@/types";
99
import { Tool } from "../../toolbar/data";
1010
import {
1111
ElementType,
@@ -24,6 +24,8 @@ export const Element = ({ type = ElementType.Seat, id, x = 250, y = 250, isSelec
2424

2525
const Element = elements[type] as any;
2626

27+
const styles = (consumer as ISTKProps).styles?.elements;
28+
2729
useEffect(() => {
2830
if (!ref.current || consumer.mode !== STKMode.Designer) return;
2931
const node = d3.select(ref.current);
@@ -58,6 +60,17 @@ export const Element = ({ type = ElementType.Seat, id, x = 250, y = 250, isSelec
5860
}
5961
};
6062

63+
const stylemap = useMemo(
64+
() => ({
65+
[ElementType.Text]: styles?.text,
66+
[ElementType.Shape]: styles?.shape,
67+
[ElementType.Polyline]: styles?.shape,
68+
[ElementType.Image]: styles?.image,
69+
[ElementType.Seat]: styles?.seat
70+
}),
71+
[styles]
72+
);
73+
6174
return (
6275
<Element
6376
id={id}
@@ -74,7 +87,8 @@ export const Element = ({ type = ElementType.Seat, id, x = 250, y = 250, isSelec
7487
: type === ElementType.Text
7588
? "text-unselected"
7689
: "element-unselected",
77-
!props.color && type !== ElementType.Text && "text-white"
90+
!props.color && type !== ElementType.Text && "text-white",
91+
isSelected ? stylemap[type]?.selected?.className : stylemap[type]?.unselected?.className
7892
)}
7993
onClick={onClick}
8094
consumer={consumer}

src/components/workspace/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useCallback, useLayoutEffect } from "react";
22
import { useSelector } from "react-redux";
3+
import { twMerge } from "tailwind-merge";
34
import { ids } from "@/constants";
45
import { store } from "@/store";
56
import { initializeElements, sync } from "@/store/reducers/editor";
@@ -52,7 +53,14 @@ export const Workspace: React.FC<ISTKProps> = (props) => {
5253
);
5354

5455
return (
55-
<div id={ids.workspaceContainer} className="w-full h-full relative border border-b-0 border-black">
56+
<div
57+
id={ids.workspaceContainer}
58+
className={twMerge(
59+
"w-full h-full relative border border-b-0 border-black",
60+
props.styles?.workspace?.root?.className
61+
)}
62+
style={props.styles?.workspace?.root?.properties}
63+
>
5664
<svg id={ids.workspace} className="w-full h-full">
5765
<g>
5866
{seats.map((e) => (

src/types/styles.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,19 @@ export interface IStyles {
2929
meta?: IStyle;
3030
};
3131
elements?: {
32-
all?: {
32+
booth?: {
3333
selected?: IStyle;
3434
unselected?: IStyle;
3535
};
36-
seats?: {
36+
seat?: {
37+
selected?: IStyle;
38+
unselected?: IStyle;
39+
};
40+
shape?: {
41+
selected?: IStyle;
42+
unselected?: IStyle;
43+
};
44+
image?: {
3745
selected?: IStyle;
3846
unselected?: IStyle;
3947
};

0 commit comments

Comments
 (0)