New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@jay./react-medium-image-zoom

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jay./react-medium-image-zoom

Medium.com style image zoom for React

latest
Source
npmnpm
Version
3.0.6
Version published
Maintainers
1
Created
Source

react-medium-image-zoom

All Contributors

This library is a different implementation of Medium.com's image zoom that allows for a low-res and high-res images to work together for “zooming” effects and works regardless of parent elements that have overflow: hidden or parents with transform properties. Versions >=3.0.0 are compatible with React.js >=16.x; if you need compatibility with react@^0.14.0 || ^15.0.0, please use version 2.x.

You can view the demo here.

demo

Installation

$ npm install --save react-medium-image-zoom

Usage

import ImageZoom from 'react-medium-image-zoom'

function MyComponent(props) {
  return (
    <div>
      <p>Some text...</p>

      <ImageZoom
        image={{
          src: 'bridge.jpg',
          alt: 'Golden Gate Bridge',
          className: 'img',
          style: { width: '50em' }
        }}
        zoomImage={{
          src: 'bridge-big.jpg',
          alt: 'Golden Gate Bridge'
        }}
      />

      <p>Some text...</p>
    </div>
  )
}
PropTypeRequiredDefaultDetails
imageobjectyesnoneThe original image
zoomImageobjectnoimageThe image to be used for zooming
zoomMarginnumberno40Pixel number to offset zoomed image from the window
isZoomedbooleannofalseFor more direct control over the zoom state
shouldHandleZoomfuncno(event) => truePass this callback to intercept a zoom click event and determine whether or not to zoom. Function must return a truthy or falsy value
shouldReplaceImagebooleannotrueOnce the image has been "zoomed" and downloaded the larger image, this replaces the original image with the zoomImage
shouldRespectMaxDimensionbooleannofalseWhen true, don't make the zoomed image's dimensions larger than the original dimensions. Only supported if no zoomImage is provided. Will also disable the zooming if the image's is already rendered at its maximum width & height
defaultStylesobjectno{}For fine-grained control over all default styles (zoomContainer, overlay, image, zoomImage)
onZoomfuncno() => {}Pass this callback to respond to a zoom interaction.
onUnzoomfuncno() => {}Pass this callback to respond to an unzoom interaction.

Each one of these image props accepts normal image props, for example:

PropTypeRequiredDetails
srcstringyesThe source for the image
altstringnoThe alt text for the image
classNamestringnoClasses to apply to the image
styleobjectnoAdditional styles to apply to the image
......no...

Controlled vs Uncontrolled Modes

Similar to how an <input /> works in React, if the consumer initially chooses to control the isZoomed value, then this means the consumer is now responsible for telling the component the value of isZoomed. If the consumer instantiates the component with a non-null isZoomed value and subsequently does not pass a value for it on updates, then an error will be thrown notifying the consumer that this is a controlled component.

The reverse is true, as well. If the component is instantiated without an isZoomed value, then the component will handle its own isZoomed state. If a non-null isZoomed prop is passed after instantiation, then an error will be thrown notifying the consumer that this component controls its own state.

Browser Support

Currently, this has only been tested on the latest modern browsers. Pull requests are welcome.

Development

The source code is located within the src directory. Use $ npm run build to build the main file as well as the example during development, and use $ npm run dev dev to have it watch for changes to src/ and example/src.

You can view the built example as a file via $ open example/build/index.html, or you can use $ npm run dev to start a local dev server and navigate to http://localhost:3000.

Storybook

This project's different options and use cases are documented in storybook. You can use this in dev like so:

  • $ yarn run storybook (or $ npm run storybook)
  • navigate to http://localhost:6006

The page should look like this:

image

Contributing

  • Check out the issues
  • Fork this repository
  • Clone your fork
  • Check out a feature branch ($ git checkout -b my-feature)
  • Make your changes
  • Run $ make to compile your changes and build the example
  • Test your example (see the "Development" section above)
  • Push your branch to your GitHub repo
  • Create a pull request from your branch to this repo's master branch
  • When all is merged, pull down the upstream changes to your master
  • Delete your feature branch

Contributors

Thanks goes to these wonderful people (emoji key):


Cameron Bothner

💻 📖 🐛 💡 🤔 👀 ⚠️

Jeremy Bini

💻 🐛

ismay

🐛 🤔

Rajit Singh

🐛

Roberto Saccon

🐛

wtfdaemon

🐛

Robert Pearce

💻 💬 ⚠️ 🐛 💡 🎨 👀 🤔 📖

Josh Sloat

🐛 💻 💡

This project follows the all-contributors specification. Contributions of any kind welcome!

FAQs

Package last updated on 15 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts