Skip to content

Commit

Permalink
Feat: added more element style overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 committed Feb 29, 2024
1 parent 9e13aaf commit c69a59e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
20 changes: 17 additions & 3 deletions src/components/workspace/elements/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { memo, useEffect, useRef } from "react";
import { memo, useEffect, useMemo, useRef } from "react";
import * as d3 from "d3";
import { isEqual } from "lodash";
import { twMerge } from "tailwind-merge";
import { dataAttributes } from "@/constants";
import { store } from "@/store";
import { clearAndSelectElements, deselectElement, selectElement } from "@/store/reducers/editor";
import { STKMode } from "@/types";
import { ISTKProps, STKMode } from "@/types";
import { Tool } from "../../toolbar/data";
import {
ElementType,
Expand All @@ -24,6 +24,8 @@ export const Element = ({ type = ElementType.Seat, id, x = 250, y = 250, isSelec

const Element = elements[type] as any;

const styles = (consumer as ISTKProps).styles?.elements;

useEffect(() => {
if (!ref.current || consumer.mode !== STKMode.Designer) return;
const node = d3.select(ref.current);
Expand Down Expand Up @@ -58,6 +60,17 @@ export const Element = ({ type = ElementType.Seat, id, x = 250, y = 250, isSelec
}
};

const stylemap = useMemo(
() => ({
[ElementType.Text]: styles?.text,
[ElementType.Shape]: styles?.shape,
[ElementType.Polyline]: styles?.shape,
[ElementType.Image]: styles?.image,
[ElementType.Seat]: styles?.seat
}),
[styles]
);

return (
<Element
id={id}
Expand All @@ -74,7 +87,8 @@ export const Element = ({ type = ElementType.Seat, id, x = 250, y = 250, isSelec
: type === ElementType.Text
? "text-unselected"
: "element-unselected",
!props.color && type !== ElementType.Text && "text-white"
!props.color && type !== ElementType.Text && "text-white",
isSelected ? stylemap[type]?.selected?.className : stylemap[type]?.unselected?.className
)}
onClick={onClick}
consumer={consumer}
Expand Down
10 changes: 9 additions & 1 deletion src/components/workspace/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useLayoutEffect } from "react";
import { useSelector } from "react-redux";
import { twMerge } from "tailwind-merge";
import { ids } from "@/constants";
import { store } from "@/store";
import { initializeElements, sync } from "@/store/reducers/editor";
Expand Down Expand Up @@ -52,7 +53,14 @@ export const Workspace: React.FC<ISTKProps> = (props) => {
);

return (
<div id={ids.workspaceContainer} className="w-full h-full relative border border-b-0 border-black">
<div
id={ids.workspaceContainer}
className={twMerge(
"w-full h-full relative border border-b-0 border-black",
props.styles?.workspace?.root?.className
)}
style={props.styles?.workspace?.root?.properties}
>
<svg id={ids.workspace} className="w-full h-full">
<g>
{seats.map((e) => (
Expand Down
12 changes: 10 additions & 2 deletions src/types/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ export interface IStyles {
meta?: IStyle;
};
elements?: {
all?: {
booth?: {
selected?: IStyle;
unselected?: IStyle;
};
seats?: {
seat?: {
selected?: IStyle;
unselected?: IStyle;
};
shape?: {
selected?: IStyle;
unselected?: IStyle;
};
image?: {
selected?: IStyle;
unselected?: IStyle;
};
Expand Down

0 comments on commit c69a59e

Please sign in to comment.