@@ -2,7 +2,7 @@ import { Meta } from "@storybook/blocks";
22
33<Meta title = " Docs/Introduction" />
44
5- # 🖼 React Zoom Pan Pinch
5+ # React Zoom Pan Pinch
66
77<p >
88 <a href = " https://bettertyped.com/" >
@@ -17,9 +17,6 @@ import { Meta } from "@storybook/blocks";
1717 <a href = " https://github.com/prc5/react-zoom-pan-pinch/blob/main/License.md" >
1818 <img src = " https://custom-icon-badges.demolab.com/github/license/prc5/react-zoom-pan-pinch?logo=law&color=yellow" />
1919 </a >
20- <a href = " https://github.com/semantic-release/semantic-release" >
21- <img src = " https://custom-icon-badges.demolab.com/badge/semver-commitzen-e10079?logo=semantic-release&color=e76f51" />
22- </a >
2320 <a href = " https://www.npmjs.com/package/react-zoom-pan-pinch" >
2421 <img src = " https://custom-icon-badges.demolab.com/npm/dm/react-zoom-pan-pinch?logoColor=fff&logo=trending-up" />
2522 </a >
@@ -29,140 +26,104 @@ import { Meta } from "@storybook/blocks";
2926 <a href = " https://github.com/prc5/react-zoom-pan-pinch" >
3027 <img src = " https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
3128 </a >
32- <a href = " https://hits.sh/github.com/prc5/react-zoom-pan-pinch/" >
33- <img src = " https://hits.sh/github.com/prc5/react-zoom-pan-pinch.svg?color=64BC4B&logo=bookmeter" />
34- </a >
35- <a href = " https://twitter.com/maciej_pyrc" >
36- <img
37- alt = " Twitter Follow"
38- src = " https://img.shields.io/twitter/follow/maciej_pyrc?label=Follow%20&style=social"
39- />
40- </a >
4129</p >
4230
43- > Super fast and light react npm package for zooming, panning and pinching html
44- > elements in easy way
45-
46- - [ Demo] ( https://prc5.github.io/react-zoom-pan-pinch/?path=/story/examples-big-image--big-image )
47- - [ Docs] ( https://prc5.github.io/react-zoom-pan-pinch/?path=/story/docs-props--page )
31+ > Super fast and light React library for zooming, panning, and pinching HTML
32+ > elements with ease.
4833
4934## Key Features
5035
51- - 🚀 Fast and easy to use
52- - 🏭 Light, without external dependencies
53- - 💎 Mobile gestures, touchpad gestures and desktop mouse events support
54- - 🎁 Powerful context usage, which gives you a lot of freedom
55- - 🔧 Highly customizable
56- - 👑 Animations and Utils to create own tools
57- - 🔮 Advanced hooks and components
58-
59- ## Help me keep working on this project ❤️
60-
61- - [ Become a Sponsor on GitHub] ( https://github.com/sponsors/prc5 )
62-
63- ---
36+ - ** Fast and lightweight** — no external dependencies
37+ - ** Touch, trackpad, and mouse** — full gesture support across devices
38+ - ** Render props and hooks** — flexible API for any component architecture
39+ - ** Highly customizable** — animations, bounds, velocity, padding, and more
40+ - ** Advanced components** — ` KeepScale ` , ` MiniMap ` , and programmatic controls
6441
6542## Installation
6643
6744``` bash
68- npm install --save react-zoom-pan-pinch
45+ npm install react-zoom-pan-pinch
46+ ```
47+
6948or
49+
50+ ``` bash
7051yarn add react-zoom-pan-pinch
7152```
7253
73- ## Examples
54+ ## Quick Start
7455
75- ``` jsx
76- import React , { Component } from " react " ;
56+ The simplest setup — wrap any content with ` TransformWrapper ` and
57+ ` TransformComponent ` :
7758
59+ ``` tsx
7860import { TransformWrapper , TransformComponent } from " react-zoom-pan-pinch" ;
7961
80- const Example = () => {
81- return (
82- < TransformWrapper>
83- < TransformComponent>
84- < img src= " image.jpg" alt= " test" / >
85- < / TransformComponent>
86- < / TransformWrapper>
87- );
88- };
62+ const App = () => (
63+ <TransformWrapper >
64+ <TransformComponent >
65+ <img src = " image.jpg" alt = " Zoomable" />
66+ </TransformComponent >
67+ </TransformWrapper >
68+ );
8969```
9070
91- or
71+ ## With Controls (Render Props)
9272
93- ``` jsx
94- import React , { Component } from " react" ;
73+ Access zoom/pan handlers through render props:
9574
75+ ``` tsx
9676import { TransformWrapper , TransformComponent } from " react-zoom-pan-pinch" ;
9777
98- const Example = () => {
99- return (
100- < TransformWrapper
101- initialScale= {1 }
102- initialPositionX= {200 }
103- initialPositionY= {100 }
104- >
105- {({ zoomIn, zoomOut, resetTransform, ... rest }) => (
106- < React .Fragment >
107- < div className= " tools" >
108- < button onClick= {() => zoomIn ()}> + < / button>
109- < button onClick= {() => zoomOut ()}> - < / button>
110- < button onClick= {() => resetTransform ()}> x< / button>
111- < / div>
112- < TransformComponent>
113- < img src= " image.jpg" alt= " test" / >
114- < div> Example text< / div>
115- < / TransformComponent>
116- < / React .Fragment >
117- )}
118- < / TransformWrapper>
119- );
120- };
78+ const App = () => (
79+ <TransformWrapper initialScale = { 1 } initialPositionX = { 200 } initialPositionY = { 100 } >
80+ { ({ zoomIn , zoomOut , resetTransform }) => (
81+ <>
82+ <div className = " tools" >
83+ <button onClick = { () => zoomIn ()} >+</button >
84+ <button onClick = { () => zoomOut ()} >-</button >
85+ <button onClick = { () => resetTransform ()} >x</button >
86+ </div >
87+ <TransformComponent >
88+ <img src = " image.jpg" alt = " Zoomable" />
89+ </TransformComponent >
90+ </>
91+ )}
92+ </TransformWrapper >
93+ );
12194```
12295
123- or
96+ ## With Ref and zoomToElement
97+
98+ Use a ref for imperative access outside of render props:
12499
125100``` tsx
126- import React , { useRef } from " react" ;
101+ import { useRef } from " react" ;
127102import {
128103 TransformWrapper ,
129104 TransformComponent ,
130105 ReactZoomPanPinchRef ,
131106} from " react-zoom-pan-pinch" ;
132107
133- const Controls = ({ zoomIn , zoomOut , resetTransform }) => (
134- <>
135- <button onClick = { () => zoomIn ()} >+</button >
136- <button onClick = { () => zoomOut ()} >-</button >
137- <button onClick = { () => resetTransform ()} >x</button >
138- </>
139- );
140-
141- const Component = () => {
142- const transformComponentRef = useRef <ReactZoomPanPinchRef | null >(null );
108+ const App = () => {
109+ const ref = useRef <ReactZoomPanPinchRef | null >(null );
143110
144- const zoomToImage = () => {
145- if (transformComponentRef .current ) {
146- const { zoomToElement } = transformComponentRef .current ;
147- zoomToElement (" imgExample" );
148- }
111+ const focusImage = () => {
112+ ref .current ?.zoomToElement (" imgExample" );
149113 };
150114
151115 return (
152- <TransformWrapper
153- initialScale = { 1 }
154- initialPositionX = { 200 }
155- initialPositionY = { 100 }
156- ref = { transformComponentRef }
157- >
158- { (utils ) => (
159- <React.Fragment >
160- <Controls { ... utils } />
116+ <TransformWrapper ref = { ref } >
117+ { ({ zoomIn , zoomOut , resetTransform }) => (
118+ <>
119+ <button onClick = { () => zoomIn ()} >+</button >
120+ <button onClick = { () => zoomOut ()} >-</button >
121+ <button onClick = { () => resetTransform ()} >x</button >
161122 <TransformComponent >
162- <img src = " image.jpg" alt = " test " id = " imgExample" />
163- <div onClick = { zoomToImage } >Example text </div >
123+ <img src = " image.jpg" alt = " Zoomable " id = " imgExample" />
124+ <div onClick = { focusImage } >Focus image </div >
164125 </TransformComponent >
165- </React.Fragment >
126+ </>
166127 )}
167128 </TransformWrapper >
168129 );
0 commit comments