Skip to content

Commit

Permalink
style: 💄 Readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
prc5 committed Mar 8, 2024
1 parent 030e724 commit e053ee2
Showing 1 changed file with 18 additions and 55 deletions.
73 changes: 18 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,76 +91,39 @@ or
```jsx
import React, { Component } from "react";

import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";

const Example = () => {
return (
<TransformWrapper
initialScale={1}
initialPositionX={200}
initialPositionY={100}
>
{({ zoomIn, zoomOut, resetTransform, ...rest }) => (
<React.Fragment>
<div className="tools">
<button onClick={() => zoomIn()}>+</button>
<button onClick={() => zoomOut()}>-</button>
<button onClick={() => resetTransform()}>x</button>
</div>
<TransformComponent>
<img src="image.jpg" alt="test" />
<div>Example text</div>
</TransformComponent>
</React.Fragment>
)}
</TransformWrapper>
);
};
```

or

```tsx
import React, { useRef } from "react";
import {
TransformWrapper,
TransformComponent,
ReactZoomPanPinchRef,
useControls,
} from "react-zoom-pan-pinch";

const Controls = ({ zoomIn, zoomOut, resetTransform }) => (
<>
<button onClick={() => zoomIn()}>+</button>
<button onClick={() => zoomOut()}>-</button>
<button onClick={() => resetTransform()}>x</button>
</>
);

const Component = () => {
const transformComponentRef = useRef<ReactZoomPanPinchRef | null>(null);
const Controls = () => {
const { zoomIn, zoomOut, resetTransform } = useControls();

const zoomToImage = () => {
if (transformComponentRef.current) {
const { zoomToElement } = transformComponentRef.current;
zoomToElement("imgExample");
}
};
return (
<div className="tools">
<button onClick={() => zoomIn()}>+</button>
<button onClick={() => zoomOut()}>-</button>
<button onClick={() => resetTransform()}>x</button>
</div>
);
};

const Example = () => {
return (
<TransformWrapper
initialScale={1}
initialPositionX={200}
initialPositionY={100}
ref={transformComponentRef}
>
{(utils) => (
<React.Fragment>
<Controls {...utils} />
{({ zoomIn, zoomOut, resetTransform, ...rest }) => (
<>
<Controls />
<TransformComponent>
<img src="image.jpg" alt="test" id="imgExample" />
<div onClick={zoomToImage}>Example text</div>
<img src="image.jpg" alt="test" />
<div>Example text</div>
</TransformComponent>
</React.Fragment>
</>
)}
</TransformWrapper>
);
Expand Down

0 comments on commit e053ee2

Please sign in to comment.