1- import { memo , useEffect , useRef } from "react" ;
1+ import { memo , useEffect , useMemo , useRef } from "react" ;
22import * as d3 from "d3" ;
33import { isEqual } from "lodash" ;
44import { twMerge } from "tailwind-merge" ;
55import { dataAttributes } from "@/constants" ;
66import { store } from "@/store" ;
77import { clearAndSelectElements , deselectElement , selectElement } from "@/store/reducers/editor" ;
8- import { STKMode } from "@/types" ;
8+ import { ISTKProps , STKMode } from "@/types" ;
99import { Tool } from "../../toolbar/data" ;
1010import {
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 }
0 commit comments