react-zoom-pan-pinch 2.1.2 → 2.2.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.
- package/CHANGELOG.md +14 -0
- package/README.md +43 -0
- package/dist/index.cjs.js +87 -60
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +11 -2
- package/dist/index.esm.js +87 -60
- package/dist/index.esm.js.map +1 -1
- package/package.json +13 -12
- package/src/.eslintrc.js +36 -0
- package/src/components/transform-component.module.css +30 -0
- package/src/components/transform-component.tsx +52 -0
- package/src/components/transform-context.tsx +493 -0
- package/src/components/transform-wrapper.tsx +18 -0
- package/src/constants/state.constants.ts +88 -0
- package/src/core/animations/animations.constants.ts +76 -0
- package/src/core/animations/animations.utils.ts +109 -0
- package/src/core/bounds/bounds.types.ts +8 -0
- package/src/core/bounds/bounds.utils.ts +157 -0
- package/src/core/double-click/double-click.logic.ts +75 -0
- package/src/core/handlers/handlers.logic.ts +112 -0
- package/src/core/handlers/handlers.utils.ts +202 -0
- package/src/core/pan/panning.logic.ts +99 -0
- package/src/core/pan/panning.utils.ts +199 -0
- package/src/core/pan/velocity.logic.ts +148 -0
- package/src/core/pan/velocity.utils.ts +79 -0
- package/src/core/pinch/pinch.logic.ts +83 -0
- package/src/core/pinch/pinch.utils.ts +88 -0
- package/src/core/wheel/wheel.logic.ts +118 -0
- package/src/core/wheel/wheel.utils.ts +121 -0
- package/src/core/zoom/zoom.logic.ts +69 -0
- package/src/core/zoom/zoom.utils.ts +58 -0
- package/src/hooks/use-transform-context.tsx +16 -0
- package/src/index.ts +6 -0
- package/src/models/calculations.model.ts +26 -0
- package/src/models/context.model.ts +179 -0
- package/src/models/helpers.model.ts +15 -0
- package/src/models/index.ts +3 -0
- package/src/react-app-env.d.ts +1 -0
- package/src/stories/assets/big-image.jpeg +0 -0
- package/src/stories/assets/medium-image.jpg +0 -0
- package/src/stories/assets/small-image.jpg +0 -0
- package/src/stories/assets/svg-example.svg +14 -0
- package/src/stories/docs/Introduction.stories.mdx +97 -0
- package/src/stories/docs/handlers.stories.mdx +48 -0
- package/src/stories/docs/handlers.tsx +107 -0
- package/src/stories/docs/props.stories.mdx +92 -0
- package/src/stories/docs/props.tsx +490 -0
- package/src/stories/examples/content/content.stories.mdx +122 -0
- package/src/stories/examples/content-rerendering/content-updating.stories.mdx +42 -0
- package/src/stories/examples/content-rerendering/example.tsx +74 -0
- package/src/stories/examples/controls/controls.stories.mdx +71 -0
- package/src/stories/examples/image-big/image-big.stories.mdx +44 -0
- package/src/stories/examples/image-medium/image-medium.stories.mdx +42 -0
- package/src/stories/examples/image-small/image-small.stories.mdx +42 -0
- package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +47 -0
- package/src/stories/examples/zoom-to-element/example.tsx +91 -0
- package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +28 -0
- package/src/stories/types/args.types.ts +201 -0
- package/src/stories/utils/args.utils.ts +34 -0
- package/src/stories/utils/code.utils.tsx +21 -0
- package/src/stories/utils/controls.utils.tsx +26 -0
- package/src/stories/utils/index.ts +3 -0
- package/src/stories/utils/styles.module.css +29 -0
- package/src/styles.css +8 -0
- package/src/typings.d.ts +10 -0
- package/src/utils/calculations.utils.ts +16 -0
- package/src/utils/callback.utils.ts +11 -0
- package/src/utils/context.utils.ts +27 -0
- package/src/utils/event.utils.ts +22 -0
- package/src/utils/helpers.utils.ts +27 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/state.utils.ts +40 -0
- package/src/utils/styles.utils.ts +27 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { TransformWrapper } from "../../../components/transform-wrapper";
|
|
4
|
+
import { TransformComponent } from "../../../components/transform-component";
|
|
5
|
+
import { normalizeArgs } from "../../utils";
|
|
6
|
+
|
|
7
|
+
export const Example: React.FC<any> = (args: any) => {
|
|
8
|
+
const [firstBlock, setFirstBlock] = useState(false);
|
|
9
|
+
const [secondBlock, setSecondBlock] = useState(false);
|
|
10
|
+
const [thirdBlock, setThirdBlock] = useState(false);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const a = setInterval(() => {
|
|
14
|
+
setFirstBlock((prev) => !prev);
|
|
15
|
+
}, 1000);
|
|
16
|
+
const b = setInterval(() => {
|
|
17
|
+
setSecondBlock((prev) => !prev);
|
|
18
|
+
}, 3000);
|
|
19
|
+
const c = setInterval(() => {
|
|
20
|
+
setThirdBlock((prev) => !prev);
|
|
21
|
+
}, 12000);
|
|
22
|
+
() => {
|
|
23
|
+
clearInterval(a);
|
|
24
|
+
clearInterval(b);
|
|
25
|
+
clearInterval(c);
|
|
26
|
+
};
|
|
27
|
+
}, []);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<TransformWrapper {...normalizeArgs(args)}>
|
|
31
|
+
<TransformComponent
|
|
32
|
+
wrapperStyle={{
|
|
33
|
+
width: "500px",
|
|
34
|
+
height: "500px",
|
|
35
|
+
maxWidth: "100%",
|
|
36
|
+
maxHeight: "calc(100vh - 50px)",
|
|
37
|
+
}}
|
|
38
|
+
>
|
|
39
|
+
<div
|
|
40
|
+
style={{
|
|
41
|
+
background: "#444",
|
|
42
|
+
color: "white",
|
|
43
|
+
padding: "50px",
|
|
44
|
+
minHeight: "300px",
|
|
45
|
+
width: "100%",
|
|
46
|
+
}}
|
|
47
|
+
>
|
|
48
|
+
<h2>Constantly rerendering content</h2>
|
|
49
|
+
|
|
50
|
+
{firstBlock ? <p>Content #1</p> : <p>Changed Content #1</p>}
|
|
51
|
+
|
|
52
|
+
{secondBlock ? <p>Content #2</p> : <p>Changed Content #2</p>}
|
|
53
|
+
|
|
54
|
+
{thirdBlock ? (
|
|
55
|
+
<p>Content #3</p>
|
|
56
|
+
) : (
|
|
57
|
+
<p>
|
|
58
|
+
Changed Content #3
|
|
59
|
+
<br />
|
|
60
|
+
<br />
|
|
61
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
|
|
62
|
+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
|
63
|
+
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
64
|
+
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
|
|
65
|
+
reprehenderit in voluptate velit esse cillum dolore eu fugiat
|
|
66
|
+
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
|
|
67
|
+
sunt in culpa qui officia deserunt mollit anim id est laborum
|
|
68
|
+
</p>
|
|
69
|
+
)}
|
|
70
|
+
</div>
|
|
71
|
+
</TransformComponent>
|
|
72
|
+
</TransformWrapper>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
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 { TransformComponent } from "../../../components/transform-component";
|
|
6
|
+
import { argsTypes } from "../../types/args.types.ts";
|
|
7
|
+
import { normalizeArgs, Controls } from "../../utils";
|
|
8
|
+
|
|
9
|
+
import exampleImg from "../../assets/small-image.jpg";
|
|
10
|
+
|
|
11
|
+
export const Template = (args) => (
|
|
12
|
+
<TransformWrapper {...normalizeArgs(args)}>
|
|
13
|
+
{(utils) => (
|
|
14
|
+
<div>
|
|
15
|
+
<Controls {...utils} />
|
|
16
|
+
<TransformComponent
|
|
17
|
+
wrapperStyle={{ maxWidth: "100%", maxHeight: "calc(100vh - 50px)" }}
|
|
18
|
+
>
|
|
19
|
+
<div style={{ background: "#444", color: "white", padding: "50px" }}>
|
|
20
|
+
<h1>No scrollbars needed</h1>
|
|
21
|
+
<h2>Use mouse or gestures to move around</h2>
|
|
22
|
+
<button
|
|
23
|
+
onClick={() => alert("You can still interact with click events!")}
|
|
24
|
+
>
|
|
25
|
+
Click me!
|
|
26
|
+
</button>
|
|
27
|
+
<p>
|
|
28
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
|
|
29
|
+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
|
30
|
+
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
31
|
+
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
|
|
32
|
+
reprehenderit in voluptate velit esse cillum dolore eu fugiat
|
|
33
|
+
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
|
|
34
|
+
sunt in culpa qui officia deserunt mollit anim id est laborum
|
|
35
|
+
</p>
|
|
36
|
+
<img src={exampleImg} alt="" />
|
|
37
|
+
<p>
|
|
38
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
|
|
39
|
+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
|
40
|
+
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
41
|
+
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
|
|
42
|
+
reprehenderit in voluptate velit esse cillum dolore eu fugiat
|
|
43
|
+
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
|
|
44
|
+
sunt in culpa qui officia deserunt mollit anim id est laborum
|
|
45
|
+
</p>
|
|
46
|
+
</div>
|
|
47
|
+
</TransformComponent>
|
|
48
|
+
</div>
|
|
49
|
+
)}
|
|
50
|
+
</TransformWrapper>
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
<Meta
|
|
54
|
+
title="Examples/Controls"
|
|
55
|
+
component={TransformWrapper}
|
|
56
|
+
argTypes={argsTypes}
|
|
57
|
+
/>
|
|
58
|
+
|
|
59
|
+
# Controls
|
|
60
|
+
|
|
61
|
+
<br />
|
|
62
|
+
|
|
63
|
+
### Preview:
|
|
64
|
+
|
|
65
|
+
<Canvas>
|
|
66
|
+
<Story name="Controls">{(args) => <Template {...args} />}</Story>
|
|
67
|
+
</Canvas>
|
|
68
|
+
|
|
69
|
+
## Component API
|
|
70
|
+
|
|
71
|
+
<ArgsTable story="Controls" />
|
|
@@ -0,0 +1,44 @@
|
|
|
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 { TransformComponent } from "../../../components/transform-component";
|
|
6
|
+
import { argsTypes } from "../../types/args.types.ts";
|
|
7
|
+
import { normalizeArgs, Controls } from "../../utils";
|
|
8
|
+
|
|
9
|
+
import exampleImg from "../../assets/big-image.jpeg";
|
|
10
|
+
|
|
11
|
+
export const Template = (args) => (
|
|
12
|
+
<TransformWrapper {...normalizeArgs(args)}>
|
|
13
|
+
{(utils) => (
|
|
14
|
+
<div>
|
|
15
|
+
<Controls {...utils} />
|
|
16
|
+
<TransformComponent
|
|
17
|
+
wrapperStyle={{ maxWidth: "100%", maxHeight: "calc(100vh - 50px)" }}
|
|
18
|
+
>
|
|
19
|
+
<img src={exampleImg} alt="" />
|
|
20
|
+
</TransformComponent>
|
|
21
|
+
</div>
|
|
22
|
+
)}
|
|
23
|
+
</TransformWrapper>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
<Meta
|
|
27
|
+
title="Examples/Big Image"
|
|
28
|
+
component={TransformWrapper}
|
|
29
|
+
argTypes={argsTypes}
|
|
30
|
+
/>
|
|
31
|
+
|
|
32
|
+
# Big Image
|
|
33
|
+
|
|
34
|
+
<br />
|
|
35
|
+
|
|
36
|
+
### Preview:
|
|
37
|
+
|
|
38
|
+
<Canvas>
|
|
39
|
+
<Story name="Big Image">{(args) => <Template {...args} />}</Story>
|
|
40
|
+
</Canvas>
|
|
41
|
+
|
|
42
|
+
## Component API
|
|
43
|
+
|
|
44
|
+
<ArgsTable story="Big Image" />
|
|
@@ -0,0 +1,42 @@
|
|
|
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 { TransformComponent } from "../../../components/transform-component";
|
|
6
|
+
import { argsTypes } from "../../types/args.types.ts";
|
|
7
|
+
import { normalizeArgs, Controls } from "../../utils";
|
|
8
|
+
|
|
9
|
+
import exampleImg from "../../assets/medium-image.jpg";
|
|
10
|
+
|
|
11
|
+
export const Template = (args) => (
|
|
12
|
+
<TransformWrapper {...normalizeArgs(args)}>
|
|
13
|
+
{(utils) => (
|
|
14
|
+
<div>
|
|
15
|
+
<Controls {...utils} />
|
|
16
|
+
<TransformComponent>
|
|
17
|
+
<img src={exampleImg} alt="" />
|
|
18
|
+
</TransformComponent>
|
|
19
|
+
</div>
|
|
20
|
+
)}
|
|
21
|
+
</TransformWrapper>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
<Meta
|
|
25
|
+
title="Examples/Medium Image"
|
|
26
|
+
component={TransformWrapper}
|
|
27
|
+
argTypes={argsTypes}
|
|
28
|
+
/>
|
|
29
|
+
|
|
30
|
+
# Medium Image
|
|
31
|
+
|
|
32
|
+
<br />
|
|
33
|
+
|
|
34
|
+
### Preview:
|
|
35
|
+
|
|
36
|
+
<Canvas>
|
|
37
|
+
<Story name="Medium Image">{(args) => <Template {...args} />}</Story>
|
|
38
|
+
</Canvas>
|
|
39
|
+
|
|
40
|
+
## Component API
|
|
41
|
+
|
|
42
|
+
<ArgsTable story="Medium Image" />
|
|
@@ -0,0 +1,42 @@
|
|
|
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 { TransformComponent } from "../../../components/transform-component";
|
|
6
|
+
import { argsTypes } from "../../types/args.types.ts";
|
|
7
|
+
import { normalizeArgs, Controls } from "../../utils";
|
|
8
|
+
|
|
9
|
+
import exampleImg from "../../assets/small-image.jpg";
|
|
10
|
+
|
|
11
|
+
export const Template = (args) => (
|
|
12
|
+
<TransformWrapper {...normalizeArgs(args)}>
|
|
13
|
+
{(utils) => (
|
|
14
|
+
<div>
|
|
15
|
+
<Controls {...utils} />
|
|
16
|
+
<TransformComponent>
|
|
17
|
+
<img src={exampleImg} alt="" />
|
|
18
|
+
</TransformComponent>
|
|
19
|
+
</div>
|
|
20
|
+
)}
|
|
21
|
+
</TransformWrapper>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
<Meta
|
|
25
|
+
title="Examples/Small Image"
|
|
26
|
+
component={TransformWrapper}
|
|
27
|
+
argTypes={argsTypes}
|
|
28
|
+
/>
|
|
29
|
+
|
|
30
|
+
# Small Image
|
|
31
|
+
|
|
32
|
+
<br />
|
|
33
|
+
|
|
34
|
+
### Preview:
|
|
35
|
+
|
|
36
|
+
<Canvas>
|
|
37
|
+
<Story name="Small Image">{(args) => <Template {...args} />}</Story>
|
|
38
|
+
</Canvas>
|
|
39
|
+
|
|
40
|
+
## Component API
|
|
41
|
+
|
|
42
|
+
<ArgsTable story="Small Image" />
|
|
@@ -0,0 +1,47 @@
|
|
|
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 { TransformComponent } from "../../../components/transform-component";
|
|
6
|
+
import { argsTypes } from "../../types/args.types.ts";
|
|
7
|
+
import { normalizeArgs, Controls } from "../../utils";
|
|
8
|
+
|
|
9
|
+
import exampleImg from "../../assets/medium-image.jpg";
|
|
10
|
+
|
|
11
|
+
export const Template = (args) => (
|
|
12
|
+
<TransformWrapper
|
|
13
|
+
{...normalizeArgs(args)}
|
|
14
|
+
initialScale={0.4}
|
|
15
|
+
minScale={0.2}
|
|
16
|
+
centerOnInit={true}
|
|
17
|
+
>
|
|
18
|
+
{(utils) => (
|
|
19
|
+
<div>
|
|
20
|
+
<Controls {...utils} />
|
|
21
|
+
<TransformComponent>
|
|
22
|
+
<img src={exampleImg} alt="" />
|
|
23
|
+
</TransformComponent>
|
|
24
|
+
</div>
|
|
25
|
+
)}
|
|
26
|
+
</TransformWrapper>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
<Meta
|
|
30
|
+
title="Examples/Zoomed Out"
|
|
31
|
+
component={TransformWrapper}
|
|
32
|
+
argTypes={argsTypes}
|
|
33
|
+
/>
|
|
34
|
+
|
|
35
|
+
# Zoomed Out
|
|
36
|
+
|
|
37
|
+
<br />
|
|
38
|
+
|
|
39
|
+
### Preview:
|
|
40
|
+
|
|
41
|
+
<Canvas>
|
|
42
|
+
<Story name="Zoomed Out">{(args) => <Template {...args} />}</Story>
|
|
43
|
+
</Canvas>
|
|
44
|
+
|
|
45
|
+
## Component API
|
|
46
|
+
|
|
47
|
+
<ArgsTable story="Zoomed Out" />
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
|
|
7
|
+
import styles from "../../utils/styles.module.css";
|
|
8
|
+
|
|
9
|
+
export const Example: React.FC<any> = (args: any) => {
|
|
10
|
+
return (
|
|
11
|
+
<TransformWrapper {...normalizeArgs(args)}>
|
|
12
|
+
{({ zoomToElement, resetTransform }) => (
|
|
13
|
+
<>
|
|
14
|
+
<div>
|
|
15
|
+
<button
|
|
16
|
+
className={styles.controlBtn}
|
|
17
|
+
onClick={() => zoomToElement("element1")}
|
|
18
|
+
>
|
|
19
|
+
Zoom to element 1
|
|
20
|
+
</button>
|
|
21
|
+
<button
|
|
22
|
+
className={styles.controlBtn}
|
|
23
|
+
onClick={() => zoomToElement("element2")}
|
|
24
|
+
>
|
|
25
|
+
Zoom to element 2
|
|
26
|
+
</button>
|
|
27
|
+
<button
|
|
28
|
+
className={styles.controlBtn}
|
|
29
|
+
onClick={() => zoomToElement("element3")}
|
|
30
|
+
>
|
|
31
|
+
Zoom to element 3
|
|
32
|
+
</button>
|
|
33
|
+
<button
|
|
34
|
+
className={styles.controlBtn}
|
|
35
|
+
onClick={() => resetTransform()}
|
|
36
|
+
>
|
|
37
|
+
Reset
|
|
38
|
+
</button>
|
|
39
|
+
</div>
|
|
40
|
+
<TransformComponent
|
|
41
|
+
wrapperStyle={{
|
|
42
|
+
maxWidth: "100%",
|
|
43
|
+
maxHeight: "calc(100vh - 50px)",
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
<div
|
|
47
|
+
style={{
|
|
48
|
+
background: "#444",
|
|
49
|
+
color: "white",
|
|
50
|
+
padding: "50px",
|
|
51
|
+
minHeight: "300px",
|
|
52
|
+
width: "100%",
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
<div
|
|
56
|
+
id="element1"
|
|
57
|
+
style={{ background: "red", width: "200px", height: "400px" }}
|
|
58
|
+
>
|
|
59
|
+
Zoom element 1
|
|
60
|
+
</div>
|
|
61
|
+
<div
|
|
62
|
+
id="element2"
|
|
63
|
+
style={{
|
|
64
|
+
background: "blue",
|
|
65
|
+
width: "250px",
|
|
66
|
+
height: "150px",
|
|
67
|
+
marginTop: "200px",
|
|
68
|
+
marginLeft: "200px",
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
Zoom element 2
|
|
72
|
+
</div>
|
|
73
|
+
<div
|
|
74
|
+
id="element3"
|
|
75
|
+
style={{
|
|
76
|
+
background: "green",
|
|
77
|
+
width: "150px",
|
|
78
|
+
height: "150px",
|
|
79
|
+
marginTop: "200px",
|
|
80
|
+
marginLeft: "500px",
|
|
81
|
+
}}
|
|
82
|
+
>
|
|
83
|
+
Zoom element 3
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
</TransformComponent>
|
|
87
|
+
</>
|
|
88
|
+
)}
|
|
89
|
+
</TransformWrapper>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
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/Zoom To Element"
|
|
12
|
+
component={TransformWrapper}
|
|
13
|
+
argTypes={argsTypes}
|
|
14
|
+
/>
|
|
15
|
+
|
|
16
|
+
# Zoom To Element
|
|
17
|
+
|
|
18
|
+
<br />
|
|
19
|
+
|
|
20
|
+
### Preview:
|
|
21
|
+
|
|
22
|
+
<Canvas>
|
|
23
|
+
<Story name="Zoom To Element">{(args) => <Template {...args} />}</Story>
|
|
24
|
+
</Canvas>
|
|
25
|
+
|
|
26
|
+
## Component API
|
|
27
|
+
|
|
28
|
+
<ArgsTable story="Zoom To Element" />
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { initialSetup } from "../../constants/state.constants";
|
|
2
|
+
|
|
3
|
+
export const argsTypes = {
|
|
4
|
+
wheel: {
|
|
5
|
+
table: {
|
|
6
|
+
disable: true,
|
|
7
|
+
},
|
|
8
|
+
},
|
|
9
|
+
"wheel.step": {
|
|
10
|
+
defaultValue: initialSetup.wheel.step,
|
|
11
|
+
control: {
|
|
12
|
+
type: "number",
|
|
13
|
+
min: 0,
|
|
14
|
+
},
|
|
15
|
+
table: {
|
|
16
|
+
defaultValue: { summary: "0" },
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
"wheel.disabled": {
|
|
20
|
+
defaultValue: initialSetup.wheel.disabled,
|
|
21
|
+
control: { type: "boolean" },
|
|
22
|
+
table: {
|
|
23
|
+
defaultValue: { summary: "false" },
|
|
24
|
+
type: { summary: "boolean" },
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
"wheel.wheelDisabled": {
|
|
28
|
+
defaultValue: initialSetup.wheel.wheelDisabled,
|
|
29
|
+
control: { type: "boolean" },
|
|
30
|
+
table: {
|
|
31
|
+
defaultValue: { summary: "false" },
|
|
32
|
+
type: { summary: "boolean" },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
"wheel.touchPadDisabled": {
|
|
36
|
+
defaultValue: initialSetup.wheel.touchPadDisabled,
|
|
37
|
+
control: { type: "boolean" },
|
|
38
|
+
table: {
|
|
39
|
+
defaultValue: { summary: "false" },
|
|
40
|
+
type: { summary: "boolean" },
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
"wheel.activationKeys": {
|
|
44
|
+
defaultValue: initialSetup.wheel.activationKeys,
|
|
45
|
+
control: { type: "text" },
|
|
46
|
+
table: {
|
|
47
|
+
defaultValue: { summary: "" },
|
|
48
|
+
type: { summary: "string" },
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
"wheel.excluded": {
|
|
52
|
+
defaultValue: initialSetup.wheel.excluded,
|
|
53
|
+
control: { type: "array" },
|
|
54
|
+
table: {
|
|
55
|
+
defaultValue: { summary: "" },
|
|
56
|
+
type: { summary: "array" },
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
panning: {
|
|
60
|
+
table: {
|
|
61
|
+
disable: true,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
"panning.disabled": {
|
|
65
|
+
defaultValue: initialSetup.panning.disabled,
|
|
66
|
+
control: { type: "boolean" },
|
|
67
|
+
table: {
|
|
68
|
+
defaultValue: { summary: "false" },
|
|
69
|
+
type: { summary: "boolean" },
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
"panning.velocityDisabled": {
|
|
73
|
+
defaultValue: initialSetup.panning.velocityDisabled,
|
|
74
|
+
control: { type: "boolean" },
|
|
75
|
+
table: {
|
|
76
|
+
defaultValue: { summary: "false" },
|
|
77
|
+
type: { summary: "boolean" },
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
"panning.lockAxisX": {
|
|
81
|
+
defaultValue: initialSetup.panning.lockAxisX,
|
|
82
|
+
control: { type: "boolean" },
|
|
83
|
+
table: {
|
|
84
|
+
defaultValue: { summary: "false" },
|
|
85
|
+
type: { summary: "boolean" },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
"panning.lockAxisY": {
|
|
89
|
+
defaultValue: initialSetup.panning.lockAxisY,
|
|
90
|
+
control: { type: "boolean" },
|
|
91
|
+
table: {
|
|
92
|
+
defaultValue: { summary: "false" },
|
|
93
|
+
type: { summary: "boolean" },
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
"panning.activationKeys": {
|
|
97
|
+
defaultValue: initialSetup.panning.activationKeys,
|
|
98
|
+
control: { type: "text" },
|
|
99
|
+
table: {
|
|
100
|
+
defaultValue: { summary: "" },
|
|
101
|
+
type: { summary: "string" },
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
"panning.excluded": {
|
|
105
|
+
defaultValue: initialSetup.panning.excluded,
|
|
106
|
+
control: { type: "array" },
|
|
107
|
+
table: {
|
|
108
|
+
defaultValue: { summary: "" },
|
|
109
|
+
type: { summary: "array" },
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
pinch: {
|
|
113
|
+
table: {
|
|
114
|
+
disable: true,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
"pinch.step": {
|
|
118
|
+
defaultValue: initialSetup.pinch.step,
|
|
119
|
+
control: {
|
|
120
|
+
type: "number",
|
|
121
|
+
min: 0,
|
|
122
|
+
},
|
|
123
|
+
table: {
|
|
124
|
+
defaultValue: { summary: "0" },
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
"pinch.disabled": {
|
|
128
|
+
defaultValue: initialSetup.pinch.disabled,
|
|
129
|
+
control: { type: "boolean" },
|
|
130
|
+
table: {
|
|
131
|
+
defaultValue: { summary: "false" },
|
|
132
|
+
type: { summary: "boolean" },
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
"pinch.excluded": {
|
|
136
|
+
defaultValue: initialSetup.pinch.excluded,
|
|
137
|
+
control: { type: "array" },
|
|
138
|
+
table: {
|
|
139
|
+
defaultValue: { summary: "" },
|
|
140
|
+
type: { summary: "array" },
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
doubleClick: {
|
|
144
|
+
table: {
|
|
145
|
+
disable: true,
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
"doubleClick.step": {
|
|
149
|
+
defaultValue: initialSetup.doubleClick.step,
|
|
150
|
+
control: {
|
|
151
|
+
type: "number",
|
|
152
|
+
min: 0,
|
|
153
|
+
},
|
|
154
|
+
table: {
|
|
155
|
+
defaultValue: { summary: "0" },
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
"doubleClick.disabled": {
|
|
159
|
+
defaultValue: initialSetup.doubleClick.disabled,
|
|
160
|
+
control: { type: "boolean" },
|
|
161
|
+
table: {
|
|
162
|
+
defaultValue: { summary: "false" },
|
|
163
|
+
type: { summary: "boolean" },
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
"doubleClick.excluded": {
|
|
167
|
+
defaultValue: initialSetup.doubleClick.excluded,
|
|
168
|
+
control: { type: "array" },
|
|
169
|
+
table: {
|
|
170
|
+
defaultValue: { summary: "" },
|
|
171
|
+
type: { summary: "array" },
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
// doubleClick: {
|
|
176
|
+
// disabled: false,
|
|
177
|
+
// step: 20,
|
|
178
|
+
// mode: "zoomIn",
|
|
179
|
+
// animation: true,
|
|
180
|
+
// animationType: "easeOut",
|
|
181
|
+
// animationTime: 200,
|
|
182
|
+
// },
|
|
183
|
+
// zoomAnimation: {
|
|
184
|
+
// disabled: false,
|
|
185
|
+
// size: 0.4,
|
|
186
|
+
// animationTime: 200,
|
|
187
|
+
// animationType: "easeOut",
|
|
188
|
+
// },
|
|
189
|
+
// alignmentAnimation: {
|
|
190
|
+
// disabled: false,
|
|
191
|
+
// size: 30,
|
|
192
|
+
// animationTime: 200,
|
|
193
|
+
// animationType: "easeOut",
|
|
194
|
+
// },
|
|
195
|
+
// velocityAnimation: {
|
|
196
|
+
// disabled: false,
|
|
197
|
+
// sensitivity: 1,
|
|
198
|
+
// animationTime: 600,
|
|
199
|
+
// animationType: "easeOut",
|
|
200
|
+
// equalToMove: true,
|
|
201
|
+
// },
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const normalizeArgs = (args: { [key: string]: any }): any => {
|
|
2
|
+
const newArgs = {};
|
|
3
|
+
|
|
4
|
+
Object.keys(args).forEach((key) => {
|
|
5
|
+
const normalizedKey = key.split(".");
|
|
6
|
+
const isNested = normalizedKey.length === 2;
|
|
7
|
+
|
|
8
|
+
if (isNested) {
|
|
9
|
+
if (!newArgs[normalizedKey[0]]) {
|
|
10
|
+
newArgs[normalizedKey[0]] = {};
|
|
11
|
+
}
|
|
12
|
+
newArgs[normalizedKey[0]][normalizedKey[1]] = args[key];
|
|
13
|
+
} else {
|
|
14
|
+
newArgs[key] = args[key];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
...newArgs,
|
|
20
|
+
onTransformed: undefined,
|
|
21
|
+
onWheelStart: undefined,
|
|
22
|
+
onWheel: undefined,
|
|
23
|
+
onWheelStop: undefined,
|
|
24
|
+
onZoomStart: undefined,
|
|
25
|
+
onZoom: undefined,
|
|
26
|
+
onZoomStop: undefined,
|
|
27
|
+
onPanningStart: undefined,
|
|
28
|
+
onPanning: undefined,
|
|
29
|
+
onPanningStop: undefined,
|
|
30
|
+
onPinchStart: undefined,
|
|
31
|
+
onPinch: undefined,
|
|
32
|
+
onPinchStop: undefined,
|
|
33
|
+
};
|
|
34
|
+
};
|