1.16.0 • Published 23 days ago

@sasza/react-panzoom v1.16.0

Weekly downloads
17
License
MIT
Repository
github
Last release
23 days ago

@sasza/react-panzoom

React component for pan and zoom with possibility to moving, resizing and selecting elements inside based on panzoom-core.

"Preview"

Demo

https://codesandbox.io/s/goofy-rgb-48tbu https://codesandbox.io/s/bold-pond-v0kvx7 (map with background image) https://codesandbox.io/s/loving-lederberg-r75ufe (example from above) Library react-drawing

Installation

npm install @sasza/react-panzoom

Properties

NameDefaultDescription
boundary{ top, right, bottom left, parent } \| boolfalsetop, right, bottom, left - numbers in px.can be used as expression like: { top: 'childHeight - containerHeight - 100px' }
children *node
disabledUserSelectboolfalseprevent css select as text etc
disabledboolfalsedisabling pan and zoom
disabledElementsboolfalsedisabling moving elements
disabledMoveboolfalsedisabling move
disabledZoomboolfalsedisabling zoom
heightstring/number100%height of child container
onContainerChangefuncnullevent on move/zoom
onContainerClickfuncnullevent on mousedown/touchdown
onContainerPositionChangefuncnullevent on position change
onContainerZoomChangefuncnullevent on zoom change
onElementsChangefuncnullcallback invoked when elements change position
selectingboolfalseswitches to selecting mode, see selecting
widthstring/number100%width of child container
zoomInitialnumber1initial zoom value
zoomMaxnumber5maximum zoom
zoomMinnumber0.3minimum zoom
zoomSpeednumber1zoom speed on wheel event

* - is required

API

const panZoomRef = useRef<PanZoomAPI>();
// ...
return (
  <PanZoom ref={panZoomRef}>
    ...
  </PanZoom>
)

panZoomRef.current contains methods like:

FunctionDescription
move(x:number, y:number)Add x and y in px to current offset. Returns current position {x, y}
getElements()Returns map of elements
getPosition()Returns current position {x, y}
setPosition(x:number, y:number)Set offset position of pan
getZoom():numberReturns current zoom
setZoom(zoom:number)Sets zoom
zoomIn(zoom:number)Add to current zoom, could be also negative number (it will work like zoomOut)
zoomOut(zoom:number)Sub from current zoom
childNodeReturns node element
reset()Reset to (0, 0, 0)

Elements

"Preview"

import PanZoom, { Element } from '@sasza/react-panzoom'

// ...

<div style={{ width: 300, height: 300 }}>
  <PanZoom>
    <Element id="orange" x={50} y={60}>
      <Circle />
    </Element>
    <Element id="red" x={120} y={150}>
      <Square />
    </Element>
  </PanZoom>
</div>

Element properties

NameDefaultDescription
id *string/idundefinedUnique ID of element
children *node
classNamestringundefinedClass name for element
disabledboolfalseDisabling element
draggableSelectorstringundefinedSelector for dragging element
familystringundefinedName of element's family, all of elements are connected during moving
followersArray\<string/id>[]Similar to family, but for specified ids of elements
onAfterResizefuncnullEvent after resizing element
onClickfuncnullEvent on clicking at element
onMouseUpfuncnullEvent on mouse up after clicking at element
resizableboolfalseIs element resizable
resizedMaxWidthnumberundefinedMaximum width of resized element
resizedMinWidthnumber15Minimum width of resized element
resizerWidthnumber15Width of resizer element
xnumber0x position of element
ynumber0y position of element

Selecting

import PanZoom, { Element } from '@sasza/react-panzoom'

// ...

<div style={{ width: 300, height: 300 }}>
  <PanZoom selecting>
    <Element id="orange" x={50} y={60}>
      <Circle />
    </Element>
    <Element id="red" x={120} y={150}>
      <Square />
    </Element>
    <Element id="green" x={200} y={50}>
      <SquareRounded />
    </Element>
  </PanZoom>
</div>

"Preview"

Testing

npm run test

Examples

npm run storybook

Usage

import PanZoom from "@sasza/react-panzoom";

const App = () => (
  <PanZoom>
    Lorem ipsum dolor
  </PanZoom>
)
import { PanZoomWithCover } from "@sasza/react-panzoom";

const App = () => (
  <PanZoomWithCover cover="url_to_image">
    Lorem ipsum dolor
  </PanZoomWithCover>
)
1.16.0

23 days ago

1.15.0

1 month ago

1.14.0

1 month ago

1.13.0

3 months ago

1.12.0

4 months ago

1.11.4

4 months ago

1.11.3

4 months ago

1.11.2

4 months ago

1.10.4

7 months ago

1.10.3

8 months ago

1.10.2

8 months ago

1.9.3

9 months ago

1.9.2

9 months ago

1.11.0

6 months ago

1.11.1

6 months ago

1.9.1

9 months ago

1.9.0

10 months ago

1.10.1

8 months ago

1.10.0

8 months ago

1.8.9

10 months ago

1.8.2

12 months ago

1.8.1

12 months ago

1.8.0

12 months ago

1.8.8

10 months ago

1.8.7

10 months ago

1.8.6

10 months ago

1.8.5

11 months ago

1.8.4

12 months ago

1.8.3

12 months ago

1.6.4

1 year ago

1.7.1

1 year ago

1.7.0

1 year ago

1.6.6

1 year ago

1.6.5

1 year ago

1.6.3

1 year ago

1.6.2

1 year ago

1.6.1

1 year ago

1.5.2

2 years ago

1.6.0

1 year ago

1.5.1

2 years ago

1.5.0

2 years ago

1.3.2

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago