react-zoom-pan-pinch 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,6 +56,7 @@ export type ReactZoomPanPinchProps = {
56
56
  centerZoomedOut?: boolean;
57
57
  centerOnInit?: boolean;
58
58
  disablePadding?: boolean;
59
+ customTransform?: (x: number, y: number, scale: number) => string;
59
60
  wheel?: {
60
61
  step?: number;
61
62
  disabled?: boolean;
@@ -179,5 +180,6 @@ export type LibrarySetup = Pick<
179
180
  | "onZoomStop"
180
181
  | "onTransformed"
181
182
  | "onInit"
183
+ | "customTransform"
182
184
  >
183
185
  >;
Binary file
@@ -0,0 +1 @@
1
+ <svg enable-background="new 0 0 24 24" height="512" viewBox="0 0 24 24" width="512" xmlns="http://www.w3.org/2000/svg"><path d="m12 0c-4.962 0-9 4.066-9 9.065 0 7.103 8.154 14.437 8.501 14.745.143.127.321.19.499.19s.356-.063.499-.189c.347-.309 8.501-7.643 8.501-14.746 0-4.999-4.038-9.065-9-9.065zm0 14c-2.757 0-5-2.243-5-5s2.243-5 5-5 5 2.243 5 5-2.243 5-5 5z"/></svg>
@@ -159,6 +159,12 @@ export const wrapperPropsTable: ComponentProps = {
159
159
  description:
160
160
  "Used to disable panning, zooming boundary padding effect. By enabling this option, you will not be able to zoom outside the image area.",
161
161
  },
162
+ customTransform: {
163
+ type: ["function"],
164
+ defaultValue: "undefined",
165
+ description:
166
+ "We can provide custom transform function to provide different way of handling our transform logic. If we need performance we can import getMatrixTransformStyles functions and replace default one. WARNING: default transform prevents svg blur on the safari.",
167
+ },
162
168
  wheel: {
163
169
  wheel: {
164
170
  type: [""],
@@ -0,0 +1,94 @@
1
+ import React from "react";
2
+
3
+ import { TransformWrapper } from "../../../components/transform-wrapper";
4
+ import { TransformComponent } from "../../../components/transform-component";
5
+ import { normalizeArgs } from "../../utils";
6
+ import { KeepScale } from "components/keep-scale";
7
+ import exampleImg from "../../assets/map.jpg";
8
+ import { ReactComponent as Pin } from "../../assets/pin.svg";
9
+
10
+ export const Example: React.FC<any> = (args: any) => {
11
+ return (
12
+ <TransformWrapper {...normalizeArgs(args)} maxScale={100}>
13
+ <TransformComponent
14
+ wrapperStyle={{
15
+ width: "700px",
16
+ height: "500px",
17
+ maxWidth: "100%",
18
+ maxHeight: "calc(100vh - 50px)",
19
+ }}
20
+ >
21
+ <div
22
+ style={{
23
+ position: "relative",
24
+ background: "#999",
25
+ }}
26
+ >
27
+ <h2>Pins will keep the initial scale with KeepScale component</h2>
28
+
29
+ <img
30
+ style={{ width: "600px", height: "300px" }}
31
+ src={exampleImg}
32
+ alt=""
33
+ />
34
+ <div
35
+ style={{
36
+ position: "absolute",
37
+ top: "50%",
38
+ left: "50%",
39
+ transform: "translate(-50%, -50%)",
40
+ zIndex: 2,
41
+ marginLeft: "-200px",
42
+ }}
43
+ >
44
+ <KeepScale>
45
+ <Pin fill="red" style={{ width: "20px", height: "20px" }} />
46
+ </KeepScale>
47
+ </div>
48
+ <div
49
+ style={{
50
+ position: "absolute",
51
+ top: "50%",
52
+ left: "50%",
53
+ transform: "translate(-50%, -50%)",
54
+ zIndex: 2,
55
+ marginLeft: "200px",
56
+ }}
57
+ >
58
+ <KeepScale>
59
+ <Pin fill="red" style={{ width: "20px", height: "20px" }} />
60
+ </KeepScale>
61
+ </div>
62
+ <div
63
+ style={{
64
+ position: "absolute",
65
+ top: "50%",
66
+ left: "50%",
67
+ transform: "translate(-50%, -50%)",
68
+ zIndex: 2,
69
+ marginBottom: "150px",
70
+ }}
71
+ >
72
+ <KeepScale>
73
+ <Pin fill="red" style={{ width: "20px", height: "20px" }} />
74
+ </KeepScale>
75
+ </div>
76
+ <div
77
+ style={{
78
+ position: "absolute",
79
+ top: "50%",
80
+ left: "50%",
81
+ transform: "translate(-50%, -50%)",
82
+ zIndex: 2,
83
+ marginTop: "100px",
84
+ }}
85
+ >
86
+ <KeepScale>
87
+ <Pin fill="red" style={{ width: "20px", height: "20px" }} />
88
+ </KeepScale>
89
+ </div>
90
+ </div>
91
+ </TransformComponent>
92
+ </TransformWrapper>
93
+ );
94
+ };
@@ -0,0 +1,45 @@
1
+ import { Meta, Story, ArgsTable, Canvas } from "@storybook/addon-docs/blocks";
2
+ import { action } from "@storybook/addon-actions";
3
+
4
+ import { TransformWrapper } from "../../../components/transform-wrapper";
5
+ import { argsTypes } from "../../types/args.types";
6
+ import { Example } from "./example";
7
+
8
+ export const Template = (args) => <Example {...args} />;
9
+
10
+ <Meta
11
+ title="Examples/Keep scale"
12
+ component={TransformWrapper}
13
+ argTypes={{
14
+ ...argsTypes,
15
+ "wheel.excluded": {
16
+ ...argsTypes["wheel.excluded"],
17
+ defaultValue: ["wheelDisabled"],
18
+ },
19
+ "panning.excluded": {
20
+ ...argsTypes["panning.excluded"],
21
+ defaultValue: ["panningDisabled"],
22
+ },
23
+ "pinch.excluded": {
24
+ ...argsTypes["pinch.excluded"],
25
+ defaultValue: ["pinchDisabled"],
26
+ },
27
+ centerOnInit: {
28
+ defaultValue: true,
29
+ },
30
+ }}
31
+ />
32
+
33
+ # Keep scale
34
+
35
+ <br />
36
+
37
+ ### Preview:
38
+
39
+ <Canvas>
40
+ <Story name="Keep scale">{(args) => <Template {...args} />}</Story>
41
+ </Canvas>
42
+
43
+ ## Component API
44
+
45
+ <ArgsTable story="Keep scale" />
@@ -13,7 +13,7 @@ export const Template = (args) => <Example {...args} />;
13
13
  argTypes={argsTypes}
14
14
  />
15
15
 
16
- # Zoom To Element
16
+ # SVG Zoom To Element
17
17
 
18
18
  <br />
19
19
 
@@ -5,3 +5,4 @@ export * from "./event.utils";
5
5
  export * from "./helpers.utils";
6
6
  export * from "./state.utils";
7
7
  export * from "./styles.utils";
8
+ export * from "./ref.utils";
@@ -0,0 +1,16 @@
1
+ /* eslint-disable no-param-reassign */
2
+ import type * as React from "react";
3
+
4
+ export function mergeRefs<T = any>(
5
+ refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>,
6
+ ): React.RefCallback<T> {
7
+ return (value) => {
8
+ refs.forEach((ref) => {
9
+ if (typeof ref === "function") {
10
+ ref(value);
11
+ } else if (ref != null) {
12
+ (ref as React.MutableRefObject<T | null>).current = value;
13
+ }
14
+ });
15
+ };
16
+ }
@@ -4,6 +4,15 @@ export const getTransformStyles = (
4
4
  x: number,
5
5
  y: number,
6
6
  scale: number,
7
+ ): string => {
8
+ // Standard translate prevents blurry svg on the safari
9
+ return `translate3d(${x}px, ${y}px, 0) scale(${scale})`;
10
+ };
11
+
12
+ export const getMatrixTransformStyles = (
13
+ x: number,
14
+ y: number,
15
+ scale: number,
7
16
  ): string => {
8
17
  // The shorthand for matrix does not work for Safari hence the need to explicitly use matrix3d
9
18
  // Refer to https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix