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

react-image-carousel-viewer

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-image-carousel-viewer

Simple library with Image Carousel Viewer component for React

0.0.11
latest
Source
npm
Version published
Weekly downloads
53
-39.77%
Maintainers
1
Weekly downloads
 
Created
Source

Licence npm version Downloads

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

Keywords

react

FAQs

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