1.3.0 • Published 2 years ago

zoombox v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

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

1.3.0

2 years ago

1.2.0

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago