Giter Site home page Giter Site logo

linecode / react-images Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jossmac/react-images

0.0 2.0 0.0 11.94 MB

๐ŸŒ„ A mobile-friendly, highly customizable, carousel component for displaying media in ReactJS

Home Page: http://jossmac.github.io/react-images

License: MIT License

JavaScript 99.85% Shell 0.15%

react-images's Introduction

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.

react-images's People

Contributors

adam187 avatar amirhar avatar apepper avatar archr avatar colin-suckow avatar davwheat avatar deadiine avatar fend25 avatar foglerek avatar gregorypotdevin avatar harshzalavadiya avatar hsource avatar indreklasn avatar jedwatson avatar jorrit avatar jossmac avatar kachkaev avatar ko avatar kripod avatar lkazberova avatar lordoffreaks avatar mkalygin avatar neptunian avatar newsiberian avatar pradel avatar robintail avatar rogach avatar shmuga avatar zackdotcomputer avatar zuccs avatar

Watchers

 avatar  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.