Socket
Socket
Sign inDemoInstall

react-magnifier

Package Overview
Dependencies
15
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-magnifier

React image zoom component


Version published
Weekly downloads
4.9K
increased by0.64%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

react-magnifier

React image zoom component

  • Simple and customizable
  • Supports touch screens
  • Allows different files for large image and magnifying glass (e.g. thumbnail and high-resolution image)

→ Demo

Demo

Usage

Install the package using NPM:

npm install react-magnifier

Add the component to your React application:

import Magnifier from "react-magnifier";
import yourImage from "./path/to/image";

export default function ExampleComponent() {
  return <Magnifier src={yourImage} width={500} />;
}

Configuration

PropTypeDefaultDescription
src (required)String–URL/path of the large image
heightNumber/String'auto'Image height (absolute or relative values possible)
widthNumber/String'100%'Image width (absolute or relative values possible)
classNameString''Class which will be applied to the image wrapper
zoomImgSrcString–URL/path of the image inside the magnifying glass (if not specified, the large image will be used)
zoomFactorNumber1.5Factor by which the zoom image will be scaled (based on the size of the large image)
mgWidthNumber150Width of the magnifying glass in px
mgHeightNumber150Height of the magnifying glass in px
mgBorderWidthNumber2Border width of the magnifying glass in px
mgShapeString'circle'Shape of the magnifying glass (possible values: 'circle', 'square')
mgShowOverflowBooleantrueSet this to false to cut off the magnifying glass at the image borders. When disabling mgShowOverflow, it's recommended that you also set all offsets to 0
mgMouseOffsetXNumber0Horizontal offset of the magnifying glass in px when hovering with a mouse
mgMouseOffsetYNumber0Vertical offset of the magnifying glass in px when hovering with a mouse
mgTouchOffsetXNumber-50Horizontal offset of the magnifying glass in px when dragging on a touch screen
mgTouchOffsetYNumber-50Vertical offset of the magnifying glass in px when dragging on a touch screen

Any other props will be passed down to the <img> element. This way, you can e.g. add an alt attribute to the image.

Custom styling

.magnifier {
  /* Styles for <div> around image and magnifying glass */
}

.magnifier-image {
  /* Styles for large image */
}

.magnifying-glass {
  /* Styles for magnifying glass */
}

Development

Requirements: Node.js, Yarn

  1. Clone this repository: git clone [repo-url]
  2. Install all dependencies: yarn install
  3. Run yarn start to generate the library bundle using Rollup and see the component in action using Storybook

Suggestions and contributions are always welcome! Please first discuss changes via issue before submitting a pull request.

Keywords

FAQs

Last updated on 30 Sep 2019

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc