Skip to content

Commit 4219373

Browse files
Add smooth and smooth step options to wheel (#386)
1 parent 4638e84 commit 4219373

5 files changed

Lines changed: 37 additions & 2 deletions

File tree

src/constants/state.constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export const initialSetup: LibrarySetup = {
2121
disablePadding: false,
2222
wheel: {
2323
step: 0.2,
24+
smooth: false,
25+
smoothStep: 0.001,
2426
disabled: false,
2527
wheelDisabled: false,
2628
touchPadDisabled: false,

src/core/wheel/wheel.logic.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const handleWheelZoom = (
4646
disablePadding,
4747
} = setup;
4848
const { size, disabled } = zoomAnimation;
49-
const { step } = wheel;
49+
const { step, smooth, smoothStep } = wheel;
5050

5151
if (!contentComponent) {
5252
throw new Error("Component not mounted");
@@ -56,10 +56,11 @@ export const handleWheelZoom = (
5656
event.stopPropagation();
5757

5858
const delta = getDelta(event, null);
59+
const zoomStep = smooth ? smoothStep * Math.abs(event.deltaY) : step;
5960
const newScale = handleCalculateWheelZoom(
6061
contextInstance,
6162
delta,
62-
step,
63+
zoomStep,
6364
!event.ctrlKey,
6465
);
6566

src/models/context.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ export type ReactZoomPanPinchProps = {
6868
customTransform?: (x: number, y: number, scale: number) => string;
6969
wheel?: {
7070
step?: number;
71+
smoothStep?: number;
72+
smooth?: boolean;
7173
disabled?: boolean;
7274
wheelDisabled?: boolean;
7375
touchPadDisabled?: boolean;

src/stories/docs/props.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ export const wrapperPropsTable: ComponentProps = {
176176
defaultValue: String(initialSetup.wheel.step),
177177
description: "The sensitivity of zooming with the wheel/touchpad.",
178178
},
179+
smoothStep: {
180+
type: ["number"],
181+
defaultValue: String(initialSetup.wheel.smoothStep),
182+
description:
183+
"The sensitivity multiplier of zooming with the wheel/touchpad used, instead of the step value, when smooth scrolling is enabled.",
184+
},
185+
smooth: {
186+
type: ["boolean"],
187+
defaultValue: String(initialSetup.wheel.smooth),
188+
description:
189+
"Enable smooth scrolling by multiplying the scroll delta with the smooth step factor.",
190+
},
179191
disabled: {
180192
type: ["boolean"],
181193
defaultValue: String(initialSetup.wheel.disabled),

src/stories/types/args.types.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ export const argsTypes = {
1616
defaultValue: { summary: "0" },
1717
},
1818
},
19+
"wheel.smoothStep": {
20+
defaultValue: initialSetup.wheel.smoothStep,
21+
control: {
22+
type: "number",
23+
min: 0,
24+
},
25+
table: {
26+
defaultValue: { summary: "0" },
27+
},
28+
},
29+
"wheel.smooth": {
30+
defaultValue: initialSetup.wheel.smooth,
31+
control: { type: "boolean" },
32+
table: {
33+
defaultValue: { summary: "false" },
34+
type: { summary: "boolean" },
35+
},
36+
},
1937
"wheel.disabled": {
2038
defaultValue: initialSetup.wheel.disabled,
2139
control: { type: "boolean" },

0 commit comments

Comments
 (0)