0.1.2 • Published 2 years ago

use-drag-and-zoom v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

useDragAndZoom react hook

A simple react hook that allows dragging and zooming on the element. It zooms in inside of the selected element and when zooms out the element comebacks to its original boundaries.

The parent element has to have CSS styles set to overflow: hidden

If you use typescript you will have to define a type of HTMLElement to which the ref is going to be attached to, for example useDragAndZoom<HTMLDivElement>({...}).

installation

Usage

const ref = useDragAndZoom<HTMLDivElement>({
  width: 600,
  height: 600,
  minZoom: 1,
  maxZoom: 2,
});

return (
  // parent div
  <div
    style={{
      overflow: "hidden",
    }}
  >
    <div ref={ref}>content of your element which can be zoomed in</div>
  </div>
);

Interface

interface UseDraggable {
  width: number;
  height: number;
  minZoom: number;
  maxZoom: number;
}

Demo

Codesanbox link

License

MIT