Skip to content
πŸŒ„ A mobile-friendly, highly customizable, carousel component for displaying media in ReactJS
JavaScript
Branch: master
Clone or download

Latest commit

zackdotcomputer Add support for a per-view custom alt tag (#370)
* Add support for a per-view custom alt tag

* Add documentation for advanced source props

* Update README to document ReactNode captions

* Check for non-string alt tags and error

* Add a warning for images with a complex caption but no alt tag
Latest commit 9b34b3e May 14, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github πŸ’š Move to yarn in CI May 2, 2020
docs fix: a syntax error in the styles docs Apr 22, 2020
src Add support for a per-view custom alt tag (#370) May 14, 2020
.babelrc V1 build system & style framework (#211) Feb 13, 2018
.editorconfig V1 build system & style framework (#211) Feb 13, 2018
.env git commit -m ".gitignore is now working" Feb 14, 2018
.eslintignore V1 build system & style framework (#211) Feb 13, 2018
.eslintrc πŸ”§ Update ESLint config May 2, 2020
.flowconfig v1 initial commit; Jan 27, 2018
.gitignore merge v1, fix conflicts Jun 5, 2019
.prettierrc unsplash images from API + flow fixes Feb 14, 2018
LICENSE re-add LICENSE Feb 14, 2018
README.md Add support for a per-view custom alt tag (#370) May 14, 2020
index.d.ts Add support for a per-view custom alt tag (#370) May 14, 2020
package-scripts.js rename examples --> docs Feb 18, 2018
package.json v1.1.7 May 2, 2020
rollup.config.js ⬆️ Update dependencies May 2, 2020
webpack.config.js rename examples --> docs Feb 18, 2018
yarn.lock ⬆️ Update dependencies May 2, 2020

README.md

React Images

A mobile-friendly, highly customizable, carousel component for displaying media in ReactJS.

Browser support

Should work in every major browser... maybe even IE10 and IE11?

Getting Started

Start by installing react-images

npm install react-images

or

yarn add react-images

If you were using 0.x versions: library was significantly rewritten for 1.x version and contains several breaking changes. The best way to upgrade is to read the docs and follow the examples.

Please note that the default footer parses HTML automatically (such as <b>I'm bold!</b>) but it does not implement any form of XSS or sanitisation. You should do that yourself before passing it into the caption field of react-images.

Using the Carousel

Import the carousel from react-images at the top of a component and then use it in the render function.

import React from 'react';
import Carousel from 'react-images';

const images = [{ source: 'path/to/image-1.jpg' }, { source: 'path/to/image-2.jpg' }];

class Component extends React.Component {
  render() {
    return <Carousel views={images} />;
  }
}

Using the Modal

Import the modal and optionally the modal gateway from react-images at the top of a component and then use it in the render function.

The ModalGateway will insert the modal just before the end of your <body /> tag.

import React from 'react';
import Carousel, { Modal, ModalGateway } from 'react-images';

const images = [{ source: 'path/to/image-1.jpg' }, { source: 'path/to/image-2.jpg' }];

class Component extends React.Component {
  state = { modalIsOpen: false };
  toggleModal = () => {
    this.setState(state => ({ modalIsOpen: !state.modalIsOpen }));
  };
  render() {
    const { modalIsOpen } = this.state;

    return (
      <ModalGateway>
        {modalIsOpen ? (
          <Modal onClose={this.toggleModal}>
            <Carousel views={images} />
          </Modal>
        ) : null}
      </ModalGateway>
    );
  }
}

Advanced Image Lists

The simplest way to define a list of images for the carousel looks like:

const images = [{ source: 'path/to/image-1.jpg' }, { source: 'path/to/image-2.jpg' }];

However, react-images supports several other properties on each image object than just source. For example:

const image = {
  caption: "An image caption as a string, React Node, or a rendered HTML string",
  alt: "A plain string to serve as the image's alt tag",
  source: {
    download: "A URL to serve a perfect quality image download from",
    fullscreen: "A URL to load a very high quality image from",
    regular: "A URL to load a high quality image from",
    thumbnail: "A URL to load a low quality image from"
  };
}

All these fields are optional except source. Additionally, if using an object of URLs (rather than a plain string URL) as your source, you must specify the regular quality URL.

You can’t perform that action at this time.