From 269c48ee95cd09b3d66e0cbb483d84bc774158ac Mon Sep 17 00:00:00 2001 From: Akalanka Perera Date: Sun, 25 Aug 2024 22:53:06 +0530 Subject: [PATCH] Fix: workspace zoom --- .../core/{switch/index.tsx => switch.tsx} | 2 - src/components/core/switch/twin-switch.tsx | 66 ------------------- src/components/workspace/index.tsx | 2 +- 3 files changed, 1 insertion(+), 69 deletions(-) rename src/components/core/{switch/index.tsx => switch.tsx} (95%) delete mode 100644 src/components/core/switch/twin-switch.tsx diff --git a/src/components/core/switch/index.tsx b/src/components/core/switch.tsx similarity index 95% rename from src/components/core/switch/index.tsx rename to src/components/core/switch.tsx index 3ac3e70..d33294c 100644 --- a/src/components/core/switch/index.tsx +++ b/src/components/core/switch.tsx @@ -2,8 +2,6 @@ import * as React from "react"; import * as SwitchPrimitives from "@radix-ui/react-switch"; import { twMerge } from "tailwind-merge"; -export { default as TwinSwitch } from "./twin-switch"; - const Switch = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef diff --git a/src/components/core/switch/twin-switch.tsx b/src/components/core/switch/twin-switch.tsx deleted file mode 100644 index 751aec0..0000000 --- a/src/components/core/switch/twin-switch.tsx +++ /dev/null @@ -1,66 +0,0 @@ -import { useEffect, useRef, useState } from "react"; -import { twMerge } from "tailwind-merge"; - -const padding = "px-4 py-[3px]"; - -const valueStyles = "z-50 pointer-events-none transition-all duration-medium"; - -interface ITwinSwitchProps extends Omit, "onChange"> { - values: string[]; - selectedValue?: string; - onChange?: (value: string) => void; - handleClassName?: string; -} - -const TwinSwitch = ({ values = [], selectedValue, onChange, handleClassName, ...props }: ITwinSwitchProps) => { - const [selected, setSelected] = useState(values[0]); - const [handleStyles, setHandleStyles] = useState({}); - - const value1Ref = useRef(); - const value2Ref = useRef(); - - useEffect(() => { - if (selectedValue && selectedValue !== selected) toggle(); - }, [selectedValue]); - - const toggle = () => { - const newValue = values.find((value) => value !== selected); - setSelected(newValue); - setHandleStyles({ - transform: `translateX(${newValue === values[0] ? 0 : value1Ref.current.offsetWidth}px)`, - width: `${newValue === values[0] ? value1Ref.current.offsetWidth : value2Ref.current.offsetWidth}px`, - height: value1Ref.current.offsetHeight - }); - onChange?.(newValue); - }; - - return ( -
- - {values[0]} - - - {values[1]} - -
- {selected} -
-
- ); -}; - -export default TwinSwitch; diff --git a/src/components/workspace/index.tsx b/src/components/workspace/index.tsx index 3d64802..044dc15 100644 --- a/src/components/workspace/index.tsx +++ b/src/components/workspace/index.tsx @@ -58,7 +58,7 @@ export const Workspace: React.FC = (props) => { style={props.styles?.workspace?.root?.properties} > - + {images.map((e) => (