From f2bbe06a8950b7a37ad87c6b244b31afe4811861 Mon Sep 17 00:00:00 2001 From: zojgame Date: Thu, 11 Apr 2024 15:57:48 +0500 Subject: [PATCH] marks animation fixed --- src/components/DistanceCircle.tsx | 4 +- src/components/Mark.tsx | 106 +++++++++++++++++------------- src/components/MarksContainer.tsx | 6 +- 3 files changed, 67 insertions(+), 49 deletions(-) diff --git a/src/components/DistanceCircle.tsx b/src/components/DistanceCircle.tsx index 0e6e8d7..a1c2578 100644 --- a/src/components/DistanceCircle.tsx +++ b/src/components/DistanceCircle.tsx @@ -15,9 +15,9 @@ const DistanceCircle = ({ selectedRange }: DistanceCircleProps) => { }, [setScreenWidth]); return ( -
+
>; + hoveredMark: string; mark: MarkType; width: number; height: number; icon: React.ReactNode; } -const Mark = ({ isFiltered, width, height, icon, mark }: MarkProps) => { - const [isHovered, setIsHovered] = useState(false); +const Mark = ({ + isFiltered, + width, + height, + icon, + mark, + setHoveredMark, + hoveredMark, +}: MarkProps) => { + const [textWidth, setTextWidth] = useState(0); + const textRef = useRef | null>(null); + + useLayoutEffect(() => { + if (!textRef.current) return; + const _textWidth = (textRef.current as unknown as SVGSVGElement).getBBox() + .width; + setTextWidth(_textWidth); + }, []); + function handleOnMouseEnter(): void { - setIsHovered(true); + setHoveredMark(mark.id); } function handleOnMouseLeave(): void { - setIsHovered(false); + setHoveredMark(""); } return ( - + - + + {mark.label} @@ -61,33 +100,8 @@ const Mark = ({ isFiltered, width, height, icon, mark }: MarkProps) => { rx="28.4444" fill="#002347" /> - {icon} + {icon} - // - // - // - // {icon} - // ); }; diff --git a/src/components/MarksContainer.tsx b/src/components/MarksContainer.tsx index 2fddb89..4a5c069 100644 --- a/src/components/MarksContainer.tsx +++ b/src/components/MarksContainer.tsx @@ -1,6 +1,7 @@ +import { useState } from "react"; +import { isMobile } from "react-device-detect"; import Mark from "./Mark"; import { Mark as MarkType } from "../types/Mark"; -import { isMobile } from "react-device-detect"; import MarkEducationIcon from "./icons/marks/MarkEducationIcon"; import MarkFoodIcon from "./icons/marks/MarkFoodIcon"; import MarkHeathyIcon from "./icons/marks/MarkHeathyIcon"; @@ -28,6 +29,7 @@ function MarksContainer({ markWidth = isMobile ? 64 : 48, markHeigth = isMobile ? 64 : 48, }: MarksContainerProps) { + const [hoveredMark, setHoveredMark] = useState(""); return (