react-zoom-pan-pinch 2.6.1 → 3.0.1

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.
Files changed (130) hide show
  1. package/.eslintignore +6 -0
  2. package/.github/CODEOWNERS +36 -0
  3. package/.github/FUNDING.yml +13 -0
  4. package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  5. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. package/.github/workflows/docs.yml +34 -0
  7. package/.github/workflows/release.yml +46 -0
  8. package/.github/workflows/tests.yml +42 -0
  9. package/.prettierrc +10 -0
  10. package/.releaserc.json +63 -0
  11. package/CHANGELOG.md +12 -0
  12. package/Code_of_Conduct.md +61 -0
  13. package/Contributing.md +236 -0
  14. package/README.md +119 -88
  15. package/commitlint.config.js +1 -0
  16. package/dist/index.cjs.js +207 -36
  17. package/dist/index.cjs.js.map +1 -1
  18. package/dist/index.d.ts +100 -77
  19. package/dist/index.esm.js +204 -38
  20. package/dist/index.esm.js.map +1 -1
  21. package/dist/src/components/index.d.ts +4 -0
  22. package/dist/src/components/mini-map/mini-map.d.ts +7 -0
  23. package/dist/{components → src/components/transform-component}/transform-component.d.ts +1 -1
  24. package/dist/{components → src/components/transform-wrapper}/transform-wrapper.d.ts +3 -4
  25. package/dist/{core → src/core}/instance.core.d.ts +5 -0
  26. package/dist/src/hooks/index.d.ts +4 -0
  27. package/dist/src/hooks/use-controls.d.ts +2 -0
  28. package/dist/src/hooks/use-transform-context.d.ts +1 -0
  29. package/dist/src/hooks/use-transform-effect.d.ts +2 -0
  30. package/dist/src/hooks/use-transform-init.d.ts +2 -0
  31. package/dist/src/index.d.ts +5 -0
  32. package/dist/{models → src/models}/context.model.d.ts +6 -2
  33. package/dist/src/utils/context.utils.d.ts +4 -0
  34. package/package.json +35 -15
  35. package/rollup.config.js +51 -0
  36. package/src/components/index.ts +4 -0
  37. package/src/components/{keep-scale.tsx → keep-scale/keep-scale.tsx} +2 -2
  38. package/src/components/mini-map/mini-map.tsx +155 -0
  39. package/src/components/{transform-component.tsx → transform-component/transform-component.tsx} +1 -3
  40. package/src/components/transform-wrapper/transform-wrapper.tsx +39 -0
  41. package/src/core/instance.core.ts +19 -3
  42. package/src/hooks/index.ts +4 -0
  43. package/src/hooks/use-controls.tsx +9 -0
  44. package/src/hooks/use-transform-context.tsx +4 -15
  45. package/src/hooks/use-transform-effect.tsx +22 -0
  46. package/src/hooks/use-transform-init.tsx +29 -0
  47. package/src/index.ts +2 -4
  48. package/src/models/context.model.ts +11 -2
  49. package/src/utils/context.utils.ts +24 -3
  50. package/tsconfig.json +32 -0
  51. package/dist/hooks/use-transform-context.d.ts +0 -3
  52. package/dist/stories/docs/handlers.d.ts +0 -12
  53. package/dist/stories/docs/props.d.ts +0 -14
  54. package/dist/stories/examples/content-rerendering/example.d.ts +0 -2
  55. package/dist/stories/examples/keep-scale/example.d.ts +0 -2
  56. package/dist/stories/examples/stress/example.d.ts +0 -2
  57. package/dist/stories/examples/svg-zoom-to-element/example.d.ts +0 -2
  58. package/dist/stories/examples/zoom-to-element/example.d.ts +0 -2
  59. package/dist/stories/types/args.types.d.ts +0 -268
  60. package/dist/stories/utils/args.utils.d.ts +0 -3
  61. package/dist/stories/utils/code.utils.d.ts +0 -6
  62. package/dist/stories/utils/controls.utils.d.ts +0 -3
  63. package/dist/stories/utils/index.d.ts +0 -3
  64. package/dist/utils/context.utils.d.ts +0 -2
  65. package/src/components/transform-wrapper.tsx +0 -56
  66. package/src/stories/assets/big-image.jpeg +0 -0
  67. package/src/stories/assets/map.jpg +0 -0
  68. package/src/stories/assets/medium-image.jpg +0 -0
  69. package/src/stories/assets/pin.svg +0 -1
  70. package/src/stories/assets/small-image.jpg +0 -0
  71. package/src/stories/assets/svg-example.svg +0 -14
  72. package/src/stories/docs/Introduction.stories.mdx +0 -97
  73. package/src/stories/docs/handlers.stories.mdx +0 -48
  74. package/src/stories/docs/handlers.tsx +0 -107
  75. package/src/stories/docs/props.stories.mdx +0 -92
  76. package/src/stories/docs/props.tsx +0 -496
  77. package/src/stories/examples/content/content.stories.mdx +0 -122
  78. package/src/stories/examples/content-rerendering/content-updating.stories.mdx +0 -45
  79. package/src/stories/examples/content-rerendering/example.tsx +0 -74
  80. package/src/stories/examples/controls/controls.stories.mdx +0 -72
  81. package/src/stories/examples/image-big/image-big.stories.mdx +0 -44
  82. package/src/stories/examples/image-medium/image-medium.stories.mdx +0 -42
  83. package/src/stories/examples/image-small/image-small.stories.mdx +0 -42
  84. package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +0 -47
  85. package/src/stories/examples/keep-scale/example.tsx +0 -94
  86. package/src/stories/examples/keep-scale/keep-scale.stories.mdx +0 -45
  87. package/src/stories/examples/stress/example.tsx +0 -24
  88. package/src/stories/examples/stress/stress-test.stories.mdx +0 -28
  89. package/src/stories/examples/svg-zoom-to-element/creativity.svg +0 -143
  90. package/src/stories/examples/svg-zoom-to-element/example.tsx +0 -57
  91. package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +0 -28
  92. package/src/stories/examples/zoom-to-element/example.tsx +0 -95
  93. package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +0 -28
  94. package/src/stories/types/args.types.ts +0 -201
  95. package/src/stories/utils/args.utils.ts +0 -34
  96. package/src/stories/utils/code.utils.tsx +0 -22
  97. package/src/stories/utils/controls.utils.tsx +0 -43
  98. package/src/stories/utils/index.ts +0 -3
  99. package/src/stories/utils/styles.module.css +0 -34
  100. /package/dist/{components → src/components/keep-scale}/keep-scale.d.ts +0 -0
  101. /package/dist/{constants → src/constants}/state.constants.d.ts +0 -0
  102. /package/dist/{core → src/core}/animations/animations.constants.d.ts +0 -0
  103. /package/dist/{core → src/core}/animations/animations.utils.d.ts +0 -0
  104. /package/dist/{core → src/core}/bounds/bounds.types.d.ts +0 -0
  105. /package/dist/{core → src/core}/bounds/bounds.utils.d.ts +0 -0
  106. /package/dist/{core → src/core}/double-click/double-click.logic.d.ts +0 -0
  107. /package/dist/{core → src/core}/handlers/handlers.logic.d.ts +0 -0
  108. /package/dist/{core → src/core}/handlers/handlers.utils.d.ts +0 -0
  109. /package/dist/{core → src/core}/pan/panning.logic.d.ts +0 -0
  110. /package/dist/{core → src/core}/pan/panning.utils.d.ts +0 -0
  111. /package/dist/{core → src/core}/pan/velocity.logic.d.ts +0 -0
  112. /package/dist/{core → src/core}/pan/velocity.utils.d.ts +0 -0
  113. /package/dist/{core → src/core}/pinch/pinch.logic.d.ts +0 -0
  114. /package/dist/{core → src/core}/pinch/pinch.utils.d.ts +0 -0
  115. /package/dist/{core → src/core}/wheel/wheel.logic.d.ts +0 -0
  116. /package/dist/{core → src/core}/wheel/wheel.utils.d.ts +0 -0
  117. /package/dist/{core → src/core}/zoom/zoom.logic.d.ts +0 -0
  118. /package/dist/{core → src/core}/zoom/zoom.utils.d.ts +0 -0
  119. /package/dist/{models → src/models}/calculations.model.d.ts +0 -0
  120. /package/dist/{models → src/models}/helpers.model.d.ts +0 -0
  121. /package/dist/{models → src/models}/index.d.ts +0 -0
  122. /package/dist/{utils → src/utils}/calculations.utils.d.ts +0 -0
  123. /package/dist/{utils → src/utils}/callback.utils.d.ts +0 -0
  124. /package/dist/{utils → src/utils}/event.utils.d.ts +0 -0
  125. /package/dist/{utils → src/utils}/helpers.utils.d.ts +0 -0
  126. /package/dist/{utils → src/utils}/index.d.ts +0 -0
  127. /package/dist/{utils → src/utils}/ref.utils.d.ts +0 -0
  128. /package/dist/{utils → src/utils}/state.utils.d.ts +0 -0
  129. /package/dist/{utils → src/utils}/styles.utils.d.ts +0 -0
  130. /package/src/components/{transform-component.module.css → transform-component/transform-component.module.css} +0 -0
@@ -1,3 +0,0 @@
1
- import { ReactZoomPanPinchRef } from "../models";
2
- declare const useTransformContext: () => ReactZoomPanPinchRef;
3
- export default useTransformContext;
@@ -1,12 +0,0 @@
1
- import React from "react";
2
- import { ReactZoomPanPinchHandlers } from "../../models/context.model";
3
- export type ControlsFnOptionsType = {
4
- name: React.ReactNode;
5
- type: string[];
6
- parameters: string[];
7
- description: string;
8
- isObjectRow?: boolean;
9
- };
10
- export type ComponentProps = Record<keyof ReactZoomPanPinchHandlers, Omit<ControlsFnOptionsType, "name" | "isObjectRow"> | Record<string, Omit<ControlsFnOptionsType, "name" | "isObjectRow">>>;
11
- export declare const handlersTable: ComponentProps;
12
- export declare const getHandlersTable: () => ControlsFnOptionsType[];
@@ -1,14 +0,0 @@
1
- import React from "react";
2
- import { ReactZoomPanPinchProps } from "models";
3
- export type ControlsOptionsType = {
4
- name: React.ReactNode;
5
- type: string[];
6
- defaultValue: string;
7
- description: string;
8
- isObjectRow?: boolean;
9
- };
10
- export type ComponentProps = Record<keyof Omit<ReactZoomPanPinchProps, "children">, Omit<ControlsOptionsType, "name" | "isObjectRow"> | Record<string, Omit<ControlsOptionsType, "name" | "isObjectRow">>>;
11
- export declare const componentPropsTable: Record<string, Omit<ControlsOptionsType, "name">>;
12
- export declare const wrapperPropsTable: ComponentProps;
13
- export declare const componentProps: ControlsOptionsType[];
14
- export declare const wrapperProps: ControlsOptionsType[];
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export declare const Example: React.FC<any>;
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export declare const Example: React.FC<any>;
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export declare const Example: React.FC<any>;
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export declare const Example: React.FC<any>;
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export declare const Example: React.FC<any>;
@@ -1,268 +0,0 @@
1
- export declare const argsTypes: {
2
- wheel: {
3
- table: {
4
- disable: boolean;
5
- };
6
- };
7
- "wheel.step": {
8
- defaultValue: number;
9
- control: {
10
- type: string;
11
- min: number;
12
- };
13
- table: {
14
- defaultValue: {
15
- summary: string;
16
- };
17
- };
18
- };
19
- "wheel.disabled": {
20
- defaultValue: NonNullable<boolean | undefined>;
21
- control: {
22
- type: string;
23
- };
24
- table: {
25
- defaultValue: {
26
- summary: string;
27
- };
28
- type: {
29
- summary: string;
30
- };
31
- };
32
- };
33
- "wheel.wheelDisabled": {
34
- defaultValue: NonNullable<boolean | undefined>;
35
- control: {
36
- type: string;
37
- };
38
- table: {
39
- defaultValue: {
40
- summary: string;
41
- };
42
- type: {
43
- summary: string;
44
- };
45
- };
46
- };
47
- "wheel.touchPadDisabled": {
48
- defaultValue: NonNullable<boolean | undefined>;
49
- control: {
50
- type: string;
51
- };
52
- table: {
53
- defaultValue: {
54
- summary: string;
55
- };
56
- type: {
57
- summary: string;
58
- };
59
- };
60
- };
61
- "wheel.activationKeys": {
62
- defaultValue: import("../../models").DeepNonNullableArray<string>;
63
- control: {
64
- type: string;
65
- };
66
- table: {
67
- defaultValue: {
68
- summary: string;
69
- };
70
- type: {
71
- summary: string;
72
- };
73
- };
74
- };
75
- "wheel.excluded": {
76
- defaultValue: import("../../models").DeepNonNullableArray<string>;
77
- control: {
78
- type: string;
79
- };
80
- table: {
81
- defaultValue: {
82
- summary: string;
83
- };
84
- type: {
85
- summary: string;
86
- };
87
- };
88
- };
89
- panning: {
90
- table: {
91
- disable: boolean;
92
- };
93
- };
94
- "panning.disabled": {
95
- defaultValue: NonNullable<boolean | undefined>;
96
- control: {
97
- type: string;
98
- };
99
- table: {
100
- defaultValue: {
101
- summary: string;
102
- };
103
- type: {
104
- summary: string;
105
- };
106
- };
107
- };
108
- "panning.velocityDisabled": {
109
- defaultValue: NonNullable<boolean | undefined>;
110
- control: {
111
- type: string;
112
- };
113
- table: {
114
- defaultValue: {
115
- summary: string;
116
- };
117
- type: {
118
- summary: string;
119
- };
120
- };
121
- };
122
- "panning.lockAxisX": {
123
- defaultValue: NonNullable<boolean | undefined>;
124
- control: {
125
- type: string;
126
- };
127
- table: {
128
- defaultValue: {
129
- summary: string;
130
- };
131
- type: {
132
- summary: string;
133
- };
134
- };
135
- };
136
- "panning.lockAxisY": {
137
- defaultValue: NonNullable<boolean | undefined>;
138
- control: {
139
- type: string;
140
- };
141
- table: {
142
- defaultValue: {
143
- summary: string;
144
- };
145
- type: {
146
- summary: string;
147
- };
148
- };
149
- };
150
- "panning.activationKeys": {
151
- defaultValue: import("../../models").DeepNonNullableArray<string>;
152
- control: {
153
- type: string;
154
- };
155
- table: {
156
- defaultValue: {
157
- summary: string;
158
- };
159
- type: {
160
- summary: string;
161
- };
162
- };
163
- };
164
- "panning.excluded": {
165
- defaultValue: import("../../models").DeepNonNullableArray<string>;
166
- control: {
167
- type: string;
168
- };
169
- table: {
170
- defaultValue: {
171
- summary: string;
172
- };
173
- type: {
174
- summary: string;
175
- };
176
- };
177
- };
178
- pinch: {
179
- table: {
180
- disable: boolean;
181
- };
182
- };
183
- "pinch.step": {
184
- defaultValue: number;
185
- control: {
186
- type: string;
187
- min: number;
188
- };
189
- table: {
190
- defaultValue: {
191
- summary: string;
192
- };
193
- };
194
- };
195
- "pinch.disabled": {
196
- defaultValue: NonNullable<boolean | undefined>;
197
- control: {
198
- type: string;
199
- };
200
- table: {
201
- defaultValue: {
202
- summary: string;
203
- };
204
- type: {
205
- summary: string;
206
- };
207
- };
208
- };
209
- "pinch.excluded": {
210
- defaultValue: import("../../models").DeepNonNullableArray<string>;
211
- control: {
212
- type: string;
213
- };
214
- table: {
215
- defaultValue: {
216
- summary: string;
217
- };
218
- type: {
219
- summary: string;
220
- };
221
- };
222
- };
223
- doubleClick: {
224
- table: {
225
- disable: boolean;
226
- };
227
- };
228
- "doubleClick.step": {
229
- defaultValue: number;
230
- control: {
231
- type: string;
232
- min: number;
233
- };
234
- table: {
235
- defaultValue: {
236
- summary: string;
237
- };
238
- };
239
- };
240
- "doubleClick.disabled": {
241
- defaultValue: NonNullable<boolean | undefined>;
242
- control: {
243
- type: string;
244
- };
245
- table: {
246
- defaultValue: {
247
- summary: string;
248
- };
249
- type: {
250
- summary: string;
251
- };
252
- };
253
- };
254
- "doubleClick.excluded": {
255
- defaultValue: import("../../models").DeepNonNullableArray<string>;
256
- control: {
257
- type: string;
258
- };
259
- table: {
260
- defaultValue: {
261
- summary: string;
262
- };
263
- type: {
264
- summary: string;
265
- };
266
- };
267
- };
268
- };
@@ -1,3 +0,0 @@
1
- export declare const normalizeArgs: (args: {
2
- [key: string]: any;
3
- }) => any;
@@ -1,6 +0,0 @@
1
- import React from "react";
2
- type Props = {
3
- code: string;
4
- };
5
- export declare const Code: React.FC<Props>;
6
- export {};
@@ -1,3 +0,0 @@
1
- import React from "react";
2
- import { ReactZoomPanPinchRef } from "../../models/context.model";
3
- export declare const Controls: React.FC<ReactZoomPanPinchRef>;
@@ -1,3 +0,0 @@
1
- export * from "./args.utils";
2
- export * from "./code.utils";
3
- export * from "./controls.utils";
@@ -1,2 +0,0 @@
1
- import { ReactZoomPanPinchContext, ReactZoomPanPinchRef } from "../models/context.model";
2
- export declare const getContext: (contextInstance: ReactZoomPanPinchContext) => ReactZoomPanPinchRef;
@@ -1,56 +0,0 @@
1
- import React, {
2
- useCallback,
3
- useEffect,
4
- useImperativeHandle,
5
- useRef,
6
- useState,
7
- } from "react";
8
-
9
- import { ZoomPanPinch } from "../core/instance.core";
10
- import { ReactZoomPanPinchProps, ReactZoomPanPinchRef } from "../models";
11
- import { getContext } from "../utils";
12
-
13
- export const Context = React.createContext<ZoomPanPinch>(null as any);
14
-
15
- const getContent = (
16
- children: ReactZoomPanPinchProps["children"],
17
- ctx: ReactZoomPanPinchRef,
18
- ) => {
19
- if (typeof children === "function") {
20
- return children(ctx);
21
- }
22
- return children;
23
- };
24
-
25
- export const TransformWrapper = React.forwardRef(
26
- (
27
- props: Omit<ReactZoomPanPinchProps, "ref">,
28
- ref: React.Ref<ReactZoomPanPinchRef>,
29
- ) => {
30
- const [, forceUpdate] = useState(0);
31
- const { children } = props;
32
- const instance = useRef(new ZoomPanPinch(props)).current;
33
-
34
- const content = getContent(props.children, getContext(instance));
35
-
36
- const handleOnChange = useCallback(() => {
37
- if (typeof children === "function") {
38
- forceUpdate((prev) => prev + 1);
39
- }
40
- }, [children]);
41
-
42
- useImperativeHandle(ref, () => getContext(instance), [instance]);
43
-
44
- useEffect(() => {
45
- instance.update(props);
46
- }, [instance, props]);
47
-
48
- useEffect(() => {
49
- return instance.onChange(handleOnChange);
50
- }, [instance, props, handleOnChange]);
51
-
52
- return <Context.Provider value={instance}>{content}</Context.Provider>;
53
- },
54
- );
55
-
56
- export default TransformWrapper;
Binary file
Binary file
Binary file
@@ -1 +0,0 @@
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>
Binary file
@@ -1,14 +0,0 @@
1
- <svg version="1.1"
2
- baseProfile="full"
3
- width="300" height="200"
4
- xmlns="http://www.w3.org/2000/svg"
5
- id="example-svg"
6
- >
7
-
8
- <rect width="100%" height="100%" fill="red" />
9
-
10
- <circle cx="150" cy="100" r="80" fill="green" />
11
-
12
- <text x="150" y="125" font-size="30" text-anchor="middle" fill="white" id="text-svg">Example</text>
13
-
14
- </svg>
@@ -1,97 +0,0 @@
1
- import { Meta } from "@storybook/addon-docs/blocks";
2
-
3
- <Meta title="Docs/Introduction" />
4
-
5
- # React-zoom-pan-pinch
6
-
7
- [![NPM](https://img.shields.io/npm/v/react-zoom-pan-pinch.svg)](https://www.npmjs.com/package/react-zoom-pan-pinch)
8
- ![npm bundle size](https://img.shields.io/bundlephobia/minzip/react-zoom-pan-pinch)
9
- [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
10
- ![NPM](https://img.shields.io/npm/l/react-zoom-pan-pinch)
11
- ![npm](https://img.shields.io/npm/dm/react-zoom-pan-pinch)
12
- ![GitHub stars](https://img.shields.io/github/stars/prc5/react-zoom-pan-pinch?style=social)
13
-
14
- > Super fast and light react npm package for zooming, panning and pinching html
15
- > elements in easy way
16
-
17
- <br />
18
- <br />
19
-
20
- ## Features
21
-
22
- - 🚀 Fast and easy to use
23
- - 🏭 Light, without external dependencies
24
- - 💎 Mobile gestures, touchpad gestures and desktop mouse events support
25
- - 🎁 Powerful context usage, which gives you a lot of freedom
26
- - 🔧 Highly customizable
27
- - 👑 Animations and many options
28
-
29
- ## Install
30
-
31
- ```bash
32
- npm install --save react-zoom-pan-pinch
33
- ```
34
-
35
- or
36
-
37
- ```bash
38
- yarn add react-zoom-pan-pinch
39
- ```
40
-
41
- ## Usage
42
-
43
- ```jsx
44
- import React, { Component } from "react";
45
-
46
- import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
47
-
48
- class Example extends Component {
49
- render() {
50
- return (
51
- <TransformWrapper>
52
- <TransformComponent>
53
- <img src="image.jpg" alt="test" />
54
- </TransformComponent>
55
- </TransformWrapper>
56
- );
57
- }
58
- }
59
- ```
60
-
61
- or
62
-
63
- ```jsx
64
- import React, { Component } from "react";
65
-
66
- import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
67
-
68
- class Example extends Component {
69
- render() {
70
- return (
71
- <TransformWrapper
72
- initialScale={1}
73
- initialPositionX={200}
74
- initialPositionY={100}
75
- >
76
- {({ zoomIn, zoomOut, resetTransform, ...rest }) => (
77
- <React.Fragment>
78
- <div className="tools">
79
- <button onClick={() => zoomIn()}>+</button>
80
- <button onClick={() => zoomOut()}>-</button>
81
- <button onClick={() => resetTransform()}>x</button>
82
- </div>
83
- <TransformComponent>
84
- <img src="image.jpg" alt="test" />
85
- <div>Example text</div>
86
- </TransformComponent>
87
- </React.Fragment>
88
- )}
89
- </TransformWrapper>
90
- );
91
- }
92
- }
93
- ```
94
-
95
- ## License
96
-
97
- MIT © [prc5](https://github.com/prc5)
@@ -1,48 +0,0 @@
1
- import { Meta } from "@storybook/addon-docs/blocks";
2
-
3
- import { getHandlersTable } from "./handlers.tsx";
4
- import { Code } from "../utils";
5
-
6
- <Meta title="Docs/Handlers" />
7
-
8
- # Handlers
9
-
10
- List of additionaly added handlers - you can acces them via ref or render props
11
-
12
- <table className="handlers-table">
13
- <thead>
14
- <tr>
15
- <th>
16
- Name
17
- </th>
18
- <th>
19
- Type
20
- </th>
21
- <th>
22
- Default
23
- </th>
24
- <th>
25
- Description
26
- </th>
27
- </tr>
28
- </thead>
29
- <tbody>
30
- {getHandlersTable().map(row => (
31
- <tr className={row.isObjectRow ? "is-object-row" : ""}>
32
- <td>
33
- {row.name}
34
- </td>
35
- <td>
36
- {row.type.map(type => (<Code code={type} />))}
37
- </td>
38
- <td>
39
- {row.parameters.map(param => (<Code code={param} />))}
40
- </td>
41
- <td>
42
- {row.description}
43
- </td>
44
- </tr>
45
- ))}
46
- </tbody>
47
-
48
- </table>
@@ -1,107 +0,0 @@
1
- import React from "react";
2
-
3
- import { ReactZoomPanPinchHandlers } from "../../models/context.model";
4
-
5
- export type ControlsFnOptionsType = {
6
- name: React.ReactNode;
7
- type: string[];
8
- parameters: string[];
9
- description: string;
10
- isObjectRow?: boolean;
11
- };
12
-
13
- export type ComponentProps = Record<
14
- keyof ReactZoomPanPinchHandlers,
15
- | Omit<ControlsFnOptionsType, "name" | "isObjectRow">
16
- | Record<string, Omit<ControlsFnOptionsType, "name" | "isObjectRow">>
17
- >;
18
-
19
- export const handlersTable: ComponentProps = {
20
- zoomIn: {
21
- type: ["function(step, animationTime, animationName)"],
22
- parameters: [
23
- "step: number = 0.5",
24
- "animationTime: number = 300",
25
- "animationName: string = easeOut",
26
- ],
27
- description: "Function used for zoom in button",
28
- },
29
- zoomOut: {
30
- type: ["function(step, animationTime, animationName)"],
31
- parameters: [
32
- "step: number = 0.5",
33
- "animationTime: number = 300",
34
- "animationName: string = easeOut",
35
- ],
36
- description: "Function used for zoom out button",
37
- },
38
- setTransform: {
39
- type: ["function(x, y, scale, animationTime, animationName)"],
40
- parameters: [
41
- "x: number",
42
- "y: number",
43
- "scale: number",
44
- "animationTime: number = 300",
45
- "animationName: string = easeOut",
46
- ],
47
- description: "Function used for custom transformation animation",
48
- },
49
- resetTransform: {
50
- type: ["function(animationTime, animationName)"],
51
- parameters: [
52
- "animationTime: number = 300",
53
- "animationName: string = easeOut",
54
- ],
55
- description: "Function used for reset button",
56
- },
57
- centerView: {
58
- type: ["function(scale, animationTime, animationName)"],
59
- parameters: [
60
- "scale: number = undefined",
61
- "animationTime: number = 300",
62
- "animationName: string = easeOut",
63
- ],
64
- description: "Function used for centering the content component",
65
- },
66
- zoomToElement: {
67
- type: ["function(node, customZoom, animationTime, animationName)"],
68
- parameters: [
69
- "node: HTMLElement | string",
70
- "customScale: number = undefined",
71
- "animationTime: number = 300",
72
- "animationName: string = easeOut",
73
- ],
74
- description:
75
- "This function make a transition for certain node provided to the function(as node element or it's id string). It allows only to zoom elements with offsetWidth and offsetHeight properties - since SVG's doesn't have those, it is impossible to perform it on such elements.",
76
- },
77
- };
78
-
79
- export const getHandlersTable = (): ControlsFnOptionsType[] => {
80
- return Object.keys(handlersTable).reduce<ControlsFnOptionsType[]>(
81
- (acc, key) => {
82
- if (Array.isArray(handlersTable[key]?.type)) {
83
- acc.push({
84
- ...handlersTable[key],
85
- name: key,
86
- });
87
- } else {
88
- Object.keys(handlersTable[key]).forEach((prop) => {
89
- acc.push({
90
- ...handlersTable[key][prop],
91
- isObjectRow: key === prop,
92
- name:
93
- key === prop ? (
94
- <b>{prop}</b>
95
- ) : (
96
- <>
97
- {key}.<b>{prop}</b>
98
- </>
99
- ),
100
- });
101
- });
102
- }
103
- return acc;
104
- },
105
- [],
106
- );
107
- };