Skip to content

Commit

Permalink
feat: Add Left, Right, and Middle click pan options (#420)
Browse files Browse the repository at this point in the history
Co-authored-by: Elliott Ewing <[email protected]>
  • Loading branch information
EEwing and Elliott Ewing authored Oct 19, 2023
1 parent 1e38727 commit 2777107
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/constants/state.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export const initialSetup: LibrarySetup = {
velocityDisabled: false,
lockAxisX: false,
lockAxisY: false,
allowLeftClickPan: true,
allowMiddleClickPan: true,
allowRightClickPan: true,
activationKeys: [],
excluded: [],
},
Expand Down
4 changes: 4 additions & 0 deletions src/core/instance.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ export class ZoomPanPinch {
const keysPressed = this.isPressingKeys(this.setup.panning.activationKeys);
if (!keysPressed) return;

if(event.button == 0 && !this.setup.panning.allowLeftClickPan) return;
if(event.button == 1 && !this.setup.panning.allowMiddleClickPan) return;
if(event.button == 2 && !this.setup.panning.allowRightClickPan) return;

event.preventDefault();
event.stopPropagation();

Expand Down
3 changes: 3 additions & 0 deletions src/models/context.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export type ReactZoomPanPinchProps = {
velocityDisabled?: boolean;
lockAxisX?: boolean;
lockAxisY?: boolean;
allowLeftClickPan?: boolean;
allowMiddleClickPan?: boolean;
allowRightClickPan?: boolean;
activationKeys?: string[];
excluded?: string[];
};
Expand Down
18 changes: 18 additions & 0 deletions src/stories/docs/props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,24 @@ export const wrapperPropsTable: ComponentProps = {
description:
"Disable the panning feature for the Y axis (prevents vertical panning).",
},
allowLeftClickPan: {
type: ["boolean"],
defaultValue: String(initialSetup.panning.allowLeftClickPan),
description:
"Allow left click to initiate panning",
},
allowMiddleClickPan: {
type: ["boolean"],
defaultValue: String(initialSetup.panning.allowMiddleClickPan),
description:
"Allow middle click to initiate panning",
},
allowRightClickPan: {
type: ["boolean"],
defaultValue: String(initialSetup.panning.allowRightClickPan),
description:
"Allow right click to initiate panning",
},
activationKeys: {
type: ["string[]"],
defaultValue: String(initialSetup.panning.activationKeys),
Expand Down

0 comments on commit 2777107

Please sign in to comment.