You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

zoombox

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zoombox

An interactive image viewer library for react.

1.3.0
latest
Source
npm
Version published
Weekly downloads
26
-58.73%
Maintainers
1
Weekly downloads
 
Created
Source

alt text

An interactive image viewer library for react.

Zoombox is a lightweight library for adding an intreratcive image viewer into your react app.

Demo

Click here to try live demo

demo gif

Features

  • Easy to integrate, now even more easier with scan mode.
  • Caption in images.
  • Area specific zoom based on cursor position.
  • Image preview for next and previuos image.
  • Image drag to view the different parts of it while image zoomed in.
  • Control over the behaviour.
  • Mobile Responsive

Get Started

yarn add zoombox

or

npm i zoombox

Example

import React, { useState } from "react";
import Zoombox from "zoombox";

const App = () => {
  const [active, setActive] = useState(false);
  const images = [
    {
      src: "https://picsum.photos/id/222/1200/800",
      caption: "This is caption one",
    },
    {
      src: "https://picsum.photos/id/230/1200/800",
      caption: "This is caption two",
    },
    {
      src: "https://picsum.photos/id/120/1200/800",
      caption: "This is caption three",
    },
  ];
  return (
    <>
      <button onClick={() => setActive(true)}>
        Click to Open Zoombox, or click on above images
      </button>
      <Zoombox
        {...{
          images,
          active,
          setActive,
        }}
      />
    </>
  );
};
export default App;

Example for Scan Mode

In scan mode zoombox will automatically scan for the images inside given containerRef and generates the images automatically so in that case you don't need to pass images prop, Zoombox will scan <img/> tag which will have data-zoombox attribute, this will also add click event to images on clicking which zoombox will get opened with that particular image.

import React, { useRef, useState } from 'react';
import Zoombox from 'zoombox';

const App = () => {
  const [active, setActive] = useState(false);

  const images = [
    {
      src: 'https://picsum.photos/id/222/1200/800',
      caption: 'This is caption one'
    },
    {
      src: 'https://picsum.photos/id/230/1200/800',
      caption: 'This is caption two'
    },
    {
      src: 'https://picsum.photos/id/120/1200/800',
      caption: 'This is caption three'
    }
  ];
  const containerRef = useRef(null);
  return (
    <div ref={containerRef}>
      <div>
        {images.map((image) => (
          <img data-zoombox data-caption={image.caption} key={image.src} src={image.src} alt={image.caption} height={200} style={{ margin: '10px' }} />
        ))}
      </div>
      <Zoombox
        {...{
          containerRef,
          active,
          setActive,
          maskClosable: true
        }}
      />
    </div>
  );
};
export default App;

API

PropTypeDefault valueDescription
images[{ src: "https://picsum.photos/200", caption?: "This is caption", }][]Array of images with url of image in 'src' with optional 'caption'
containerRef for scan mode !Ref of HTMLElement[]This will enable the scan mode, in which zoombox will automatically scan for the images inside given containerRef and generates the images automatically so in that case you don't need to pass images prop, Zoombox will scan <img/> tag which will have data-zoombox attribute and image src will be taken from src attribute and caption will be taken from data-caption attribute. So your img tag should look like this <img src="https://picsum.photos/200", data-zoombox data-caption="Caption goes here"/> this will also add click event to images on clicking which zoombox will get opened with that particular image.
active*booleanfalseTo tell Zoombox weather to stay visible or not
setActive*React.Dispatch <React.SetStateAction >To update the external active state
zIndexnumber10000Sets the z-index css of ZoomBox's parent container
enableKeyboard MouseControlsbooleantrueEnable / Disable the mouse nad keyboard controls (right arrow -> next slide, left arrow -> prev slide, up arrow -> zoom in, down arrow -> zoom out )
maskClosablebooleanfalseIf sets to true, closes the zoombox when clicked on background mask.
enableZoom0 or 1 or 220 to disable zoom feature, 1 to enable center zoom, 2 for to enable area specific zoom based on cursor position.
closablebooleantrueenable/disable close icon
dbClickToZoombooleantrueenable/disable the ability to zoom at 200% when user double clicks the image.
hideImagePreviewbooleanfalsehides the bottom images preview in zoombox
lockBodyScrollbooleanfalselocks body from scrolling while zoombox is open
maskOpacitynumber0.8sets the opacity of background mask
selectedImagenumber0load the image at given index when zoombox gets opened
showCreditsbooleanfalseshows "Image preview powered by Zoombox" in the corner, just in case if you wish to attribute zoombox.
enableImageDragBetabooleanfalseIt is in Beta mode so might not be perfect to use, When zoom is more than 150% then this will allow user to drag the active image in zoombox and see the different parts of it while zoomed in.

License

Zoombox is licensed under the MIT License.

Support

Zoombox is free to use and always will be, however if you wish to support you can always buy me a coffee !

Buy me a coffee

Or

Keywords

image

FAQs

Package last updated on 18 Sep 2022

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