Skip to content

Commit dd9771d

Browse files
committed
Patch: removed dependency on framer motion
1 parent 9337cf5 commit dd9771d

File tree

6 files changed

+35
-43
lines changed

6 files changed

+35
-43
lines changed

bun.lockb

-2.27 KB
Binary file not shown.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
"@reduxjs/toolkit": "2.1.0",
6565
"class-variance-authority": "0.7.0",
6666
"d3": "7.8.5",
67-
"framer-motion": "10.14.0",
6867
"lodash": "4.17.21",
6968
"lucide-react": "0.316.0",
7069
"react-loader-spinner": "5.3.4",

src/components/controls/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ const Controls = ({ options, styles }: IControlProps) => {
5959
)}
6060
>
6161
<AnimatedSwitcher
62-
show
63-
customKey={ControlComponent.name}
62+
key={ControlComponent.name}
6463
component={<ControlComponent options={options} styles={styles} />}
6564
/>
6665
</div>

src/components/core/animated-switcher.tsx

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
1-
import { LazyMotion, domAnimation, m as motion } from "framer-motion";
1+
import { useEffect, useState } from "react";
22
import { twMerge } from "tailwind-merge";
33

44
interface AnimatedSwitcherProps {
5-
customKey?: string;
5+
key?: string;
66
component: React.ReactNode;
7-
alternateComponent?: React.ReactNode;
8-
show: boolean;
97
className?: string;
108
style?: React.CSSProperties;
119
duration?: number;
1210
}
1311

14-
const AnimatedSwitcher = ({
15-
customKey,
16-
component,
17-
alternateComponent,
18-
show,
19-
className,
20-
style,
21-
duration
22-
}: AnimatedSwitcherProps) => {
12+
const AnimatedSwitcher = ({ key, component, className, style, duration = 0.3 }: AnimatedSwitcherProps) => {
13+
const [opacity, setOpacity] = useState(0);
14+
const [currentComponent, setCurrentComponent] = useState(component);
15+
16+
useEffect(() => {
17+
setOpacity(0);
18+
setTimeout(() => {
19+
setCurrentComponent(component);
20+
setOpacity(1);
21+
}, (duration / 2) * 1000);
22+
}, [key]);
23+
2324
return (
24-
<LazyMotion features={domAnimation}>
25-
<motion.div
26-
key={customKey ?? (show ? "component" : "alternateComponent")}
27-
className={twMerge("w-full h-full", className)}
28-
initial={{ opacity: 0 }}
29-
animate={{ opacity: 1 }}
30-
transition={{ duration: duration ?? 0.3 }}
31-
style={style}
32-
exit={{ opacity: 0 }}
33-
>
34-
{show ? component : alternateComponent}
35-
</motion.div>
36-
</LazyMotion>
25+
<div
26+
key={key}
27+
className={twMerge("w-full h-full", className)}
28+
style={{ ...style, transitionDuration: `${duration / 2}s`, opacity }}
29+
>
30+
{currentComponent}
31+
</div>
3732
);
3833
};
3934

src/components/footer.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ const Footer: React.FC<ISTKProps> = ({ options: { showFooter = true } = {}, ...p
1919
<span className={twMerge("text-sm", styles?.title?.className)} style={styles?.title?.properties}>
2020
React Seat Toolkit
2121
</span>
22-
<AnimatedSwitcher
23-
show={!!selectedTool}
24-
customKey={selectedTool}
25-
className={twMerge("absolute top-[0.4rem] left-5 text-xs", styles?.meta?.className)}
26-
style={styles?.meta?.properties}
27-
component={<span>{tools[selectedTool]?.description}</span>}
28-
alternateComponent={null}
29-
duration={0.2}
30-
/>
22+
{selectedTool && (
23+
<AnimatedSwitcher
24+
key={selectedTool}
25+
className={twMerge("absolute top-[0.4rem] left-5 text-xs", styles?.meta?.className)}
26+
style={styles?.meta?.properties}
27+
component={<span>{tools[selectedTool]?.description}</span>}
28+
duration={0.2}
29+
/>
30+
)}
3131
</div>
3232
);
3333
};

src/components/workspace/grid.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { default as GridLines } from "@mezh-hq/react-gridlines";
22
import { useSelector } from "react-redux";
3-
import { AnimatedSwitcher } from "../core";
43

54
const Grid = () => {
65
const grid = useSelector((state: any) => state.editor.grid);
76
if (!grid) return null;
87
return (
9-
<AnimatedSwitcher
10-
show={grid}
11-
component={<GridLines className="w-full h-full opacity-20" cellWidth={44} strokeWidth={2} />}
12-
className="absolute top-0 left-0 pointer-events-none"
8+
<GridLines
9+
className="w-full h-full absolute top-0 left-0 pointer-events-none opacity-20"
10+
cellWidth={44}
11+
strokeWidth={2}
1312
/>
1413
);
1514
};

0 commit comments

Comments
 (0)