diff --git a/README.md b/README.md index 0c373814..8fa7c45d 100644 --- a/README.md +++ b/README.md @@ -458,6 +458,10 @@ const FlowWithControls = () => ( - `showZoom`: boolean - default: true - `showFitView`: boolean - default: true - `showInteractive`: boolean - default: true +- `onZoomIn`: function that gets triggered when the zoom in button is pressed +- `onZoomOut`: function that gets triggered when the zoom out button is pressed +- `onFitView`: function that gets triggered when the fit-to-view button is pressed +- `onInteractiveChange`: function that gets triggered when the lock button is pressed - passes the new value - `style`: css properties - `className`: additional class name diff --git a/src/additional-components/Controls/index.tsx b/src/additional-components/Controls/index.tsx index 0f6caa07..c107f94e 100644 --- a/src/additional-components/Controls/index.tsx +++ b/src/additional-components/Controls/index.tsx @@ -15,9 +15,23 @@ interface ControlProps extends React.HTMLAttributes { showZoom?: boolean; showFitView?: boolean; showInteractive?: boolean; + onZoomIn?: () => void; + onZoomOut?: () => void; + onFitView?: () => void; + onInteractiveChange?: (interactiveStatus: boolean) => void; } -const Controls = ({ style, showZoom = true, showFitView = true, showInteractive = true, className }: ControlProps) => { +const Controls = ({ + style, + showZoom = true, + showFitView = true, + showInteractive = true, + onZoomIn, + onZoomOut, + onFitView, + onInteractiveChange, + className, +}: ControlProps) => { const setInteractive = useStoreActions((actions) => actions.setInteractive); const fitView = useStoreActions((actions) => actions.fitView); const zoomIn = useStoreActions((actions) => actions.zoomIn); @@ -30,10 +44,20 @@ const Controls = ({ style, showZoom = true, showFitView = true, showInteractive
{showZoom && ( <> -
zoomIn()}> +
{ + zoomIn(); + if (onZoomIn) { + onZoomIn(); + } + }}>
-
zoomOut()}> +
{ + zoomOut(); + if (onZoomOut) { + onZoomOut(); + } + }}>
@@ -41,7 +65,12 @@ const Controls = ({ style, showZoom = true, showFitView = true, showInteractive {showFitView && (
fitView({ padding: 0.1 })} + onClick={() => { + fitView({ padding: 0.1 }); + if (onFitView) { + onFitView(); + } + }} >
@@ -49,7 +78,12 @@ const Controls = ({ style, showZoom = true, showFitView = true, showInteractive {showInteractive && (
setInteractive(!isInteractive)} + onClick={() => { + setInteractive(!isInteractive); + if (onInteractiveChange) { + onInteractiveChange(!isInteractive); + } + }} > {isInteractive ? : }