feat: implement zoom state management in ZoomablePage component to enhance zoom functionality and control panning behavior
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { useState } from "react";
|
||||||
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
|
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
@@ -22,9 +23,14 @@ export const ZoomablePage = ({
|
|||||||
order = "first",
|
order = "first",
|
||||||
onZoomChange,
|
onZoomChange,
|
||||||
}: ZoomablePageProps) => {
|
}: ZoomablePageProps) => {
|
||||||
|
const [isZoomed, setIsZoomed] = useState(false);
|
||||||
|
|
||||||
const handleTransform = (ref: any, state: { scale: number; positionX: number; positionY: number }) => {
|
const handleTransform = (ref: any, state: { scale: number; positionX: number; positionY: number }) => {
|
||||||
onZoomChange?.(state.scale > 1.1);
|
const zoomed = state.scale > 1.1;
|
||||||
|
setIsZoomed(zoomed);
|
||||||
|
onZoomChange?.(zoomed);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
@@ -57,7 +63,10 @@ export const ZoomablePage = ({
|
|||||||
animationTime: 200,
|
animationTime: 200,
|
||||||
animationType: "easeOut"
|
animationType: "easeOut"
|
||||||
}}
|
}}
|
||||||
panning={{ disabled: false }}
|
panning={{
|
||||||
|
disabled: false,
|
||||||
|
lockAxisX: !isZoomed
|
||||||
|
}}
|
||||||
limitToBounds={true}
|
limitToBounds={true}
|
||||||
centerZoomedOut={false}
|
centerZoomedOut={false}
|
||||||
onTransformed={handleTransform}
|
onTransformed={handleTransform}
|
||||||
|
|||||||
Reference in New Issue
Block a user