• Stars
    star
    2,348
  • Rank 19,596 (Top 0.4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

React Images

⚠️ Warning!

Don't use this in a new project. This package hasn't been properly maintained in a long time and there are much better options available.

Instead, try...


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.

More Repositories

1

react-toast-notifications

🍞 A toast notification system for react
JavaScript
2,172
star
2

react-scrolllock

🔒 Prevent scroll on the <body />
JavaScript
451
star
3

react-focus-marshal

👮🏻 Traps focus within a DOM node
JavaScript
82
star
4

react-blink

👁 React replacement for the <blink> element
JavaScript
70
star
5

react-radios

🔘 Proper handling of HTML radios in react
JavaScript
60
star
6

react-height-transition

📏 Animate height when children mount/unmount
JavaScript
57
star
7

jade-field-mixins

A collection of Jade mixins for defining form fields. The style and structure follow Bootstrap's form definition. Initially crafted for recreating dashboards using KeystoneJS
CSS
38
star
8

react-scroll-captor

📜 Restrict scroll events to the immediate child
JavaScript
27
star
9

interpolate-range

💯 Super simple numeric range interpolation
JavaScript
15
star
10

react-icons

Simple component for icons in your React app
JavaScript
14
star
11

react-deprecate

⚠️ Rename props with deprecation warning
JavaScript
13
star
12

react-select-simple-value

A simple value wrapper for react-select
JavaScript
12
star
13

react-node-resolver

🔍 Resolve the DOM node of any react component
JavaScript
12
star
14

react-prop-toggle

🕹 Influence nodes outside your app's render tree
JavaScript
7
star
15

react-view-transition

🎟 Animate views as they mount/unmout
JavaScript
6
star
16

react-pseudo-state

🎛 Stateful pseudo-classes in React
JavaScript
5
star
17

less-entypo-icons

A single LESS file for including entypo icons
CSS
4
star
18

react-focuslock

Restrict focus scope to a single element, typically a modal dialog
JavaScript
3
star
19

asser-ts

Assertion functions for TS
TypeScript
3
star
20

adjustable

Adjustable helper utilities for CSS-in-JS
JavaScript
2
star
21

simple-grid

A simple, responsive grid
CSS
1
star
22

react-sronly

🗣 Provide accessible text to Screen Readers
JavaScript
1
star
23

swipe

experiment with touch events
JavaScript
1
star