Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-image-viewer-zoom

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-image-viewer-zoom

A React-based image viewer.

  • 1.0.36
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-image-viewer-zoom

A scalebale image viewer for React.

View the online demo.

Installation

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

Usage

import ImageViewer from 'react-image-viewer-zoom'
import 'react-image-viewer-zoom/dist/style.css' 

class MyComponent extends React.Component<any, any> {
	render() {
		 const images: any = [
            { src: 'https://unsplash.it/800/300?image=1', title: 'title', content: 'content' },
            { src: 'https://unsplash.it/300/800?image=2', title: 'title', content: 'content' },
            { src: 'https://unsplash.it/1800/300?image=3', title: 'title', content: 'content' },
            { src: 'https://unsplash.it/800/1800?image=4', title: 'title', content: 'content' }
        ];
                
        return (
			<ImageViewer
            	showPreview={true}
           		showIndex={true}
               	prefixCls="mycomponent"
             	activeIndex={0}
             	images={images}/>
        )
	}
}

Implement in a modal

class MyModal extends React.Component<any, any> {
    constructor(props: any) {
        this.state = {
            activeIndex: undefined,
            visible: false
        }
    }
    // init active index when open the modal
    open(activeIndex? number) {
        this.setState({
            activeIndex: activeIndex || 0,
            visible: true
        });
    }

    render() {
        const { activeIndex } = this.state;
        
        return this.state.visible ? (
            <div className='my-modal'>
                <ImageViewer
                    showPreview
                    showIndex
                    activeIndex={activeIndex}
                    images={images}/>
            </div>
        ) : null;
    }
}



API

PropTypeRequiredDefaultDetails
imagesarrayyesThe set for the image
showIndexbooleannotrueShow the index of the current image on toolbar
showPreviewbooleannotrueShow bottom Indicators image preview
activeIndexnumberno0Specify the active image when init the image viewer
prefixClsstringnonull
classNamestringnonull

Each image item options props

PropTypeRequiredDetails
srcstringYesThe source of the image
titlestringNoImage title
contentstringNoImage caption

Typescript config

tsconfig.json

{
    "compilerOptions": {
        "allowSyntheticDefaultImports": true
    }
}

Set allowSyntheticDefaultImports to prevent error TS1192: Module 'react' has no default export.

Keywords

FAQs

Package last updated on 06 Mar 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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc