2.1.0 • Published 8 months ago

react-pan-and-zoom v2.1.0

Weekly downloads
-
License
-
Repository
github
Last release
8 months ago

React pan and zoom

A React component to pan and zoom using a trackpad, mouse or touchscreen.

Demo

Demo.

Introduction

This package differs from other packages in that it detects the mouse type and using a trackpad you can pan with two fingers and zoom with a pinch.

Installation

npm install --save react-pan-and-zoom

Usage

import { PanZoomProvider, PanZoom, useSafeGestures } from 'react-pan-and-zoom'

function App() {
  // Disable swiping back and forward with two fingers in the browser
  useSafeGestures()

  return (
    <PanZoomProvider>
      <PanZoom>
        Pannable and zoomable content goes here
      </PanZoom>
    </PanZoomProvider>
  )
}

You can also import a hook called usePanZoom to access the pan and zoom state inside PanZoomProvider.

Props

PanZoomProvider

PropTypeDefaultDescription
forceMouseType'touchpad' or 'touchscreen' or 'mouse'automaticForce a mouse type
initialPanXy{ x: 0, y: 0 }The initial pan value
isPanBoundedbooleantrueWhether to bound panning
panBoundPaddingPadding{ top: 0, bottom: 0, left: 0, right: 0 }Padding for panning
panZoomDelaynumber300The delay in ms for the pan to adjust after a zoom
centerOnMountbooleantrueWhether to center on mount if the content is smaller than the container
centerOnMountDelaynumber3 * 1000 / 60How long to way on mount before centering the content
initialZoomnumber1The initial zoom value
isZoomBoundedbooleantrueWhether to bound zooming
minZoomnumber0.5The minimum zoom value
maxZoomnumber2The maximum zoom value
zoomStrengthnumber0.05The strength factor of the zoom
onChange(pan: Xy, zoom: number) => voidundefinedThe callback when the pan or zoom changes

PanZoom

PropTypeDefaultDescription
containerClassNamestringempty stringThe class name of the container
containerStyleCSSPropertiesempty objectThe style of the container
contentClassNamestringempty stringThe class name of the content
contentStyleCSSPropertiesempty objectThe style of the content

License

MIT License

Contributing

Yes please!

2.1.0

8 months ago

2.0.0

12 months ago

1.3.2

12 months ago

1.3.1

12 months ago

1.3.0

12 months ago

1.2.0

12 months ago

1.1.1

12 months ago

1.1.0

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.0

1 year ago