Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-zoom-pan-pinch

prc51.1mMIT3.6.1TypeScript support: included

Zoom and pan html elements in easy way

react, zoom, pan, pinch, animation, velocity, css, fast, transformations, scale, drag, viewer, reacts, touch, css3, svg, bounds, context

readme

🖼 React Zoom Pan Pinch

Super fast and light react npm package for zooming, panning and pinching html elements in easy way

Twitter Follow

Sources

<picture> Premium sponsor banner </picture>

<picture> Premium sponsor banner </picture>

Key Features

  • 🚀 Fast and easy to use
  • 🏭 Light, without external dependencies
  • 💎 Mobile gestures, touchpad gestures and desktop mouse events support
  • 🎁 Powerful context usage, which gives you a lot of freedom
  • 🔧 Highly customizable
  • 👑 Animations and Utils to create own tools
  • 🔮 Advanced hooks and components

Try other BetterTyped projects

Do you like this library? Try out other projects

Hyper Fetch

⚡Hyper Fetch - Fetching and realtime data exchange framework.


Installation

npm install --save react-zoom-pan-pinch
or
yarn add react-zoom-pan-pinch

<picture> Premium sponsor banner </picture>

<picture> Premium sponsor banner </picture>

Examples

import React, { Component } from "react";

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

const Example = () => {
  return (
    <TransformWrapper>
      <TransformComponent>
        <img src="image.jpg" alt="test" />
      </TransformComponent>
    </TransformWrapper>
  );
};

or

import React, { Component } from "react";

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

const Controls = () => {
  const { zoomIn, zoomOut, resetTransform } = useControls();

  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}
    >
      {({ zoomIn, zoomOut, resetTransform, ...rest }) => (
        <>
          <Controls />
          <TransformComponent>
            <img src="image.jpg" alt="test" />
            <div>Example text</div>
          </TransformComponent>
        </>
      )}
    </TransformWrapper>
  );
};

<picture> Premium sponsor banner </picture>

<picture> Premium sponsor banner </picture>

License

MIT © prc5

Help me keep working on this project ❤️

💖 Our sponsors

My Sponsors

changelog

CHANGELOG

Version: 3.0.0

  • Removed render props performance issues. I've removed state from render props, now if we want to listen to it's changes we need to use useTransformEffect hook
  • Created helper hooks for handling controls, transform state and context without performance issues with rerendering
  • Added KeepScale, MiniMap components
  • Added documentation about new hooks
  • New readme
  • Semantic release

Version: 2.1.3

Published: 24.07.2021
  1. Alignment animation size changes:

  2. "padding" size is not longer calculated based on the wrapper size - it's now represented by pixels

  3. you can set separate "padding" values for X and Y

  4. Storybook docs fix - prevented to log every action callback since it was killing performance