fix(availability): prevent hover animation jump when switching days (#22209)

* fix(availability): prevent hover animation jump when switching days

* Update CellHighlightContainer.tsx

---------

Co-authored-by: Anik Dhabal Babu <[email protected]>
This commit is contained in:
ozerandAnik Dhabal Babu authored and GitHub committed 2025-09-02 13:25:31 +00:00
1 parent 6cd4f1fcaa
commit 87331f0a3a
1 file changed
+19 -5
@@ -13,20 +13,31 @@ export function CellHighlightContainer({ children }: { children: React.ReactNode
const [isAnimating, setIsAnimating] = useState(false); const [isAnimating, setIsAnimating] = useState(false);
const componentContainerRef = useRef<HTMLDivElement>(null); const componentContainerRef = useRef<HTMLDivElement>(null);
const { x, y, height, isHover, updateDimensions, setContainerRef } = useStore(store, (state) => state); const { x, y, height, isHover, updateDimensions, setContainerRef, browsingDate, emitCellPosition } =
useStore(store, (state) => state);
const prevBrowsingDateRef = useRef(browsingDate);
useEffect(() => { useEffect(() => {
let timeout: NodeJS.Timeout | null = null; let timeout: NodeJS.Timeout | null = null;
if (isHover) { if (isHover) {
setIsAnimating(true); setIsAnimating(true);
} else { } else {
timeout = setTimeout(() => setIsAnimating(false), 1000); timeout = setTimeout(() => setIsAnimating(false), 300);
} }
return () => { return () => {
timeout && clearTimeout(timeout); timeout && clearTimeout(timeout);
}; };
}, [isHover]); }, [isHover]);
useEffect(() => {
if (prevBrowsingDateRef.current?.getTime() !== browsingDate.getTime()) {
setIsAnimating(false);
// Clear hover state and position when date changes
emitCellPosition(-1);
prevBrowsingDateRef.current = browsingDate;
}
}, [browsingDate, emitCellPosition]);
useLayoutEffect(() => { useLayoutEffect(() => {
const handleUpdate = () => { const handleUpdate = () => {
updateDimensions(); updateDimensions();
@@ -50,13 +61,16 @@ export function CellHighlightContainer({ children }: { children: React.ReactNode
return ( return (
<LazyMotion features={domAnimation}> <LazyMotion features={domAnimation}>
<div <div
className="relative -mx-2 w-[calc(100%+16px)] overflow-x-scroll px-2 lg:-mx-6 lg:w-[calc(100%+48px)] lg:px-6" className="relative -mx-2 w-[calc(100%+16px)] overflow-hidden overflow-x-scroll px-2 lg:-mx-6 lg:w-[calc(100%+48px)] lg:px-6"
ref={componentContainerRef}> ref={componentContainerRef}>
{children} {children}
<m.div <m.div
className="border-subtle opcaity-0 pointer-events-none absolute left-0 top-0 h-full rounded-lg border-2" className="border-subtle pointer-events-none absolute left-0 top-0 h-full rounded-lg border-2 opacity-0"
animate={{ x: [null, x], opacity: isAnimating || isHover ? 1 : 0.1 }} animate={{
x: [null, x],
opacity: isAnimating || isHover ? 1 : 0,
}}
style={{ y, height, width: DAY_CELL_WIDTH }} style={{ y, height, width: DAY_CELL_WIDTH }}
transition={{ type: "spring", stiffness: 300, damping: 30 }} transition={{ type: "spring", stiffness: 300, damping: 30 }}
/> />