1.1.0 • Published 5 years ago

react-image-enlarger v1.1.0

Weekly downloads
91
License
MIT
Repository
-
Last release
5 years ago

react-image-enlarger

npm package Follow on Twitter

A medium.com style image zoom component with gesture dismissal similar to that found in the iOS Photos app. Originally built for use in Sancho-UI. Try the demo here.

Features

  • Drag to dismiss
  • Optionally use a differernt enlarged image source
  • Optional loading indicator when loading the enlarged image
  • Spring based animations

Install

Install react-image-enlarger and react-gesture-responder using yarn or npm.

yarn add react-image-enlarger react-gesture-responder

Usage

import Image from "react-image-enlarger";

function SingleSource() {
  const [zoomed, setZoomed] = React.useState(false);

  return (
    <Image
      style={{ width: "200px", height: "auto" }}
      zoomed={zoomed}
      src="my-image.jpg"
      alt="The best dog ever"
      onClick={() => setZoomed(true)}
      onRequestClose={() => setZoomed(false)}
    />
  );
}

API

Any additional props beyond the ones listed below are passed to the thumbnail image.

NameTypeDefault ValueDescription
zoomed*booleanWhether the enlarged image is shown
onRequestClose*() => void;A callback for closing the zoomed image
renderLoadingReact.ReactNodeRender a loading indicator
src*StringThe thumbnail image source (and enlarged, if not provided)
enlargedSrcStringAn optional larger image source
overlayColorStringCustomize the background color of the overlay

License

MIT