0.0.11 • Published 2 years ago

react-image-carousel-viewer v0.0.11

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

Licence npm version Downloads

React Image Carousel Viewer

Simple library with Image Carousel Viewer component for React.

Installation

npm i react-image-carousel-viewer

Live Demo

https://codesandbox.io/s/react-image-carousel-viewer-example-1-461uc1

Example

import { useState } from "react";
import { ReactImageCarouselViewer } from "react-image-carousel-viewer";
import "./styles.css";

function App() {
  const [isOpen, setIsOpen] = useState(false);
  const [index, setIndex] = useState(0);
  const images = [
    {
      src: "http://placeimg.com/1200/800/nature",
      description: "image-1"
    },
    { src: "http://placeimg.com/800/1200/nature", description: "image-2" },
    { src: "http://placeimg.com/1920/1080/nature" },
    { src: "http://placeimg.com/1500/500/nature" }
  ];

  return (
    <>
      <p className="title">react-image-carousel-viewer</p>
      <div className="container">
        {images.map((image, index) => (
          <img
            className="image"
            src={image.src}
            alt=""
            key={index}
            onClick={() => {
              setIndex(index);
              setIsOpen(true);
            }}
          />
        ))}

        <ReactImageCarouselViewer
          open={isOpen}
          onClose={() => setIsOpen(false)}
          images={images}
          startIndex={index}
        />
      </div>
    </>
  );
}

export default App;

API

PropertyTypeDescription
images{src: string; description?: string; id?: string}[]Array that contains image src and optional description.
startIndexnumberFirst image from the array to display in the viewer.
openbooleanTrigger to open/close modal.
onClose() => voidHandle modal closing action.
leftArrowJSX.ElementCustom component for left arrow (optional).
rightArrowJSX.ElementCustom component for right arrow (optional).
loadingElementJSX.ElementCustom component for loading animation (optional).
extraTopElementJSX.ElementCustom component for an element in the modal (optional).
disableScrollbooleanTrigger for scrolling action (optional).

Keyboard Interactions

ESC - Closes modal

Scroll - Changes current image

Left Arrow - Show the previous image

Right Arrow - Shows the next image

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago