GithubHelp home page GithubHelp logo

ricoputrap / react-images-viewer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from guonanci/react-images-viewer

0.0 0.0 0.0 1.29 MB

A react library that view photos list easily, and a simple, responsive viewer component for displaying an array of images.

Home Page: https://guonanci.github.io/react-images-viewer/

License: MIT License

Shell 0.46% JavaScript 99.54%

react-images-viewer's Introduction

react-images-viewer

Build Status

jest

A react library that view photos list easily, and a simple, responsive viewer component for displaying an array of images.

中文文档

Quick start

# recommended
yarn add react-images-viewer

or

npm install react-images-viewer --save
import React from "react";
import ImgsViewer from "react-images-viewer";

export default class Demo extends React.Component {
  render() {
    return (
      <ImgsViewer
        imgs={[
          { src: "http://example.com/img1.jpg" },
          { src: "http://example.com/img2.png" },
        ]}
        currImg={this.state.currImg}
        isOpen={this.state.viewerIsOpen}
        onClickPrev={this.gotoPrevious}
        onClickNext={this.gotoNext}
        onClose={this.closeViewer}
      />
    );
  }
}

Demo & Example

Live Demo: guonanci.github.io/react-images-viewer

yarn install
yarn
yarn start

Then open localhost:8000 in a browser.

Using srcSet

Example using srcSet:

<ImgsViewer
  imgs={IMG_SET}
  ...
/>
const IMG_SET = [
  {
    src: "http://example.com/img1.svg",
    caption: "A forest",
    // As an array
    srcSet: [
      "http://example.com/img1_1024.jpg 1024w",
      "http://example.com/img1_800.jpg 800w",
      "http://example.com/img1_500.jpg 500w",
      "http://example.com/img1_320.jpg 320w",
    ],
  },
  {
    src: "http://example.com/img2.svg",
    // As a string
    srcSet:
      "http://example.com/img2_1024.jpg 1024w, http://example.com/img2_800.jpg 800w, http://example.com/img2_500.jpg 500w, http://example.com/img2_320.jpg 320w",
  },
];

Options

Property Type Default Description
backdropCloseable boolean false Allow users to exit the viewer by clicking the backdrop
closeBtnTitle str undefined Customize close esc title
enableKeyboardInput boolean true Supports keyboard input - space, esc, arrow left, arrow up, and arrow right, arrow down
currImg number 0 Required if you want to navigate the imgsViewer, The index of the image to display initially
customControls arr undefined An array of elements to display as custom controls on the top of viewer
imgs arr undefined Required. Array of image objects, See img opts table below
imgCountSeparator str ' / ' Customize separator in the image count
isOpen boolean false Required if you want to navigate the imgsViewer, Whether or not the viewer is displayed
leftArrowTitle str undefined Customize of left arrow title
onClickPrev function undefined Required if you want to navigate the imgsViewer, and fired on request of the previous image
onClickNext function undefined Required if you want to navigate the imgsViewer, and fired on request of the next image
onClose function undefined Required if you want to close the imgsViewer, and handle closing of the viewer
onClickImg function undefined Handle click on current image
onClickThumbnail function undefined Handle click on thumbnail
preloadNextImg boolean true Whether to preload the next available image
rightArrowTitle str undefined Customize right arrow title
showCloseBtn boolean true Optionally display a close 'X' button in top right corner
showImgCount boolean true Optionally display image index, e.g., "2 of 20"
width number 1024 Maximum width of the carousel; defaults to 1024px
spinnerDisabled boolean false Disable Spinner
spinner function DefaultSpinner Spinner component class
spinnerColor str '#fff' Color of spinner
spinnerSize number 50 Size of spinner
preventAutoScroll boolean true Determines whether auto-scrolling is prevented

Images Object

| Property | Type | Default | Description | | :------- | :-------- | :---------- | :---------- | -------- | | src | str | undefined | Required | | srcSet | string[] | string | undefined | Optional | | caption | str | undefined | Optional | | alt | str | undefined | Optional |

react-images-viewer's People

Contributors

guonanci avatar dependabot[bot] avatar hasanyousef avatar joelmaia7 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.