Giter Club home page Giter Club logo

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 apepper avatar archr avatar colin-suckow avatar davwheat avatar deadiine avatar gregorypotdevin avatar harshzalavadiya avatar hsource avatar indreklasn avatar jedwatson avatar jlaramie avatar jorrit avatar josh-a-e avatar jossmac avatar ko avatar kripod avatar lkazberova avatar mkalygin avatar moonsupport avatar neptunian avatar newsiberian avatar nickhsu avatar pradel avatar robintail avatar rogach avatar shmuga avatar thepatrik avatar zackdotcomputer avatar zuccs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-images's Issues

Just updated fro 0.3.2 to 0.4.5 - transitivie peer dependency on react 15.0.2

I am now getting the following npm warning.

npm ERR! peer dep missing: react@^15.0.2, required by [email protected]

The react-addons-transition-group module had peer dependency on "react": "^15.0.2"

You module indicates peer dependencies of react ^0.14 or 15.0^ yet it pulls in that module.

Is this going to cause a problem for me at run time in 0.14.8, as I can't update it yet ?
Is there maybe someway I can address the complaint it so i don't get the warning ?

It basically appears to work ok at moment.

Thanks for the useful module.
Robin

add thumbnail preview

Are there any plans to add a bottom bar with thumbnail preview/selection (like react-image-gallery) ?

image

It could be nice to be able to plug an external component at the bottom of the Lightbox to add a custom one if needed.

Add a property callback function for photo currentImage state change

Like onClose property, would there be an interest in an optional onChangeImage property or something like that?

Here is the scenario that I've run into:
My responsive Gallery component must re render itself when the browser window width changes. This turns out to be an issue when using a phone and changing orientation. The Lightbox gets rendered again and the image gets reset to the 'initialImage' index which is whatever it opened the Lightbox with initially. If i had this callback I could keep track of Lightbox's current image state and keep my 'initialImage' up to date.

How Can I Customize The Style of My Lightbox?

I'm trying to put a white background behind my images because I can still see the spinner behind my png images. Also png files don't have a background and I'd like them to have one in general.

The default style that comes in the library, default.js, is applied to the Lightbox component right before it's exported in the last line of src/Lightbox.js:

export default useSheet(Lightbox, defaultStyles);

I've tried calling the react-jss method useSheet() on Lightbox after importing it to the file I'm using it in with my own jss stylesheet, but it doesn't seem to change anything.

I've also tried adding inline style to the Lightbox component.

Code from first approach:

import Lightbox from "react-images";
import reactJss from "react-jss";
import camelCase from "jss-camel-case";
import px from "jss-px";
import nested from "jss-nested";
import vendorPrefixer from "jss-vendor-prefixer";

const jss = create();
const useSheet = reactJss(jss);
jss.use(camelCase());
jss.use(nested());
jss.use(px());
jss.use(vendorPrefixer());

import myStyles from "./default.js";

const StylizedLightbox = useSheet(Lightbox, myStyles);

class MyLightbox extends Component {

[...]

render() {
    return (
        <StylizedLightbox
            [...]
       /> 

Code from second approach:

import Lightbox from "react-images";

class MyLightbox extends Component {

[...]

render() {
    return (
      <Lightbox style = {{ backgroundColor: "white" }}
        currentImage={this.props.currentImage}
      />
    );
  }

Thank you for any help.

Feature: download image (open full size image in new window)

please ensure the change is aligned with the project roadmap by opening an issue first

Hello. I'd like to implement a new feature which will provide an ability to download currently viewed image by opening it in a new browser window. This can be also useful when viewing "thin" images. I plan to add the property .showDownloadButton and display a nice icon in the CloseBar. Here is a screenshot.

Are you interested of this feature implementation?

2016-06-23_03-18-12

backdropClosesModal has no effect

Clicking the backdrop does not close the lightbox, neither if i set backdropClosesModal explicit when initializing it.
I tested it with Chrome and Firefox.

Cannot read property 'windowHeight' of null

Hello again. Currently I'm updating my project to React 14 and had to update this library as well, but I'm getting this:

screen shot 2016-03-11 at 13 59 43

Possible reasons

It looks like we set windowHeight in state but setState is async, so according to the docs it's possible that we will have it undefined when we start to render. At least I believe this is my case. My code looks like this:

    return (
      <Lightbox
        images={images.map((image) => {return {src: image}})}
        isOpen={true}
        onClose={this.onClose.bind(this)}
        onClickPrev={() => {}}
        onClickNext={() => {}}
      />
    );

As a fix I've downgraded to version 0.2.0 and now it works perfect with my older setup, which is this:

return (
      <Lightbox
        images={images.map((image) => {return {src: image}})}
        isOpen={true}
        onClose={this.onClose.bind(this)}
        onClickPrev={() => {}}
        onClickNext={() => {}}
        styles={this.props.styles}
        width={width}
        height={height}
      />
    );

Yes, I want to render only one image :)

Questions

  1. Why don't we read windowHeight from window on each render, what's the reason to keep it in state? If you think it makes sense to change the way we do now I may have time to take a look on weekends :)
  2. Why onClickPrev and onClickNext are required even if you have only one image?

Upgrading to 0.3.3 error

From the console when clicking on the "preview" image to open the lightbox this error appears:

invariant.js:39 Uncaught Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's render method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).

The page seems to hang then I try clicking again and get this error:

ReactTransitionGroup.js:132 Uncaught TypeError: Cannot read property 'componentWillEnter' of undefined

see: neptunian/react-photo-gallery#5

Repo Management

Hello everyone!

I'm afraid that I've become too busy at work to give this package the time it needs. If anyone would like to come on board as a collaborator, either just to help out, or possibly to take the reigns, I'd really appreciate it.

Pinging you guys specifically because of your issue/PR support:
@neptunian, @pradel, @newsiberian, @RobinTail

second one not working

I use react-images in a list,but the first one working well, but the second not work,Anyone encounter it?react0.14.8

Ref owner warning about multiple React modules

Working on a project with react & react 15.0.1 versions. React-images was not working and there is only warning from invariant.js about multiple React modules.

I've deleted react from peer dependency and upgraded versions and now react-images is working.
Also, I've tried as a workaround to delete /node_modules/react-images/node_modules/react and react-dom, which lead to the same result, react-images started to work.

Not sure whether i'm doing something wrong. (npm - 3.8.7, node - 5.9.0)
Nevertheless, thank u for this lightbox, it is awesome.

custom component as child rather than array of images as prop

I'm happy to fork/modify this myself if needed, but I'm wondering if it would be possible to accept custom children components and render those instead of the images. What parts of the Lightbox component would I need to change?

I need to include a few buttons below the image, but I need to pass appropriate callbacks etc.
If there's a way to do that already, please let me know!

Mobile pinch zoom?

This is a great library and it works sufficiently good for mobile.

I was wondering how hard would it be to implement pinch zoom to the images, or what are the steps I might take for the implementation of this.

Thanks!

Code review

Disclaimer: I probably didn't spend enough time, feel free to ignore if something is not true. Also my language below is very strict forward, don't take it as "rude".

General

Related to JSS

  1. As react-images is a lib, you should not use jss singleton instance, create your own: https://github.com/jsstyles/jss#create-an-own-instance-of-jss
    Normally in such cases I create a local jss module where I create the instance, do the setup, export useSheet function and use this module in all other components.
  2. you could use useSheet as a decorator
  3. you can do the same without any helper:
    https://github.com/jossmac/react-images/blob/master/src/Lightbox.js#L109
    <button className={${classes.some} ${classes.some2}}>test</button>
  4. instead of using one big style file and one big Lightbox class, you should split it into different small classes.
  5. vendor prefixes for userSelect are handled by the prefixer plugin you are already using, not sure about touchCallout, try it out. https://github.com/jossmac/react-images/blob/master/src/styles/default.js#L131
  6. I ended up in puting style file at the same directory level as the componet using it. For e.g. Lightbox.js, lightboxStyle.js

Scroll in one line?

Can I scroll small images in one line, as carousel? How can I do it?

I have structure:

<div>
<a>
<a>
...
<a>
</div>

this div generated when rendered Lightbox, and I can't assign some style for it (for example, display: table-cell)... But I want all small images inline with scroll...

I just tried out 0.4.6 and got the follow message in console log.

main.bundle.js:3396 Warning: FirstChild(...): No render method found on the returned component instance: you may have forgotten to define render, returned null/false from a stateless component, or tried to render an element whose type is a function that isn't a React component.

I had a quick look it almost seems to me that FirstChild if its a component is missing render().

Getting `<noscript></noscript>` tag when importing `<Lightbox />`

So I tried putting this bad boy in my code:

import React, { Component } from 'react'
import Lightbox from 'react-images'

// Components
import PageDescription from './../components/page-description'

const LIGHTBOX_IMAGE_SET = [{
    src: require('./../../assets/img/blah/01.png')
}]

export default class PressKit extends Component {
    render() { return (
        <article>
            <section className="bubble">
                <PageDescription
                    title="Press Kit"
                    subtitle="All Our Info Are Belong to You"
                    description="BORING!"
                />
            </section>

            <section className="bubble">
                <Lightbox
                    images={LIGHTBOX_IMAGE_SET}
                    onClickPrev={() => {}}
                    onClickNext={() => {}}
                    onClose={() => {}}
                />
            </section>
        </article>
    )}
}

That image works when it's in an <img /> tag. For some reason, it doesn't show anything but <noscript></noscript> when I use <Lightbox />.

Implement layout using flexbox

Apart from greatly simplify the style API, paving the way for theming (ref #70) and custom components as children (ref #54), this feature will remove the necessity for internal state.

Note: current browser support for flexbox is good, but incomplete.

Image goes up when you close lightbox

Hi Joss,

You're component is wonderful, I've just integrated into one of my React project.
Btw, I got a visual bug when the lightbox is open

When you want to leave the lightbox (using ESC or clicking on the cross) the image goes up.
It seems that appears only if you have scroll in the web page. I think it is caused by the overflow which is applied on . Do you know anything that could fix that bug please ?

There is an example in video :
https://vid.me/xh59

Thanks in advance.

Fix js warnings when using React 15.2

warning.js:25 Warning: Unknown props duration, component on

tag. Remove these props from the element. For details, see https://fb.me/react-unknown-prop
in div (created by Fade)
in Fade (created by ReactTransitionGroup)
in FirstChild (created by ReactTransitionGroup)
in ReactTransitionGroupwarning @ warning.js:25warnUnknownProperties @ ReactDOMUnknownPropertyDevtool.js:64handleElement @ ReactDOMUnknownPropertyDevtool.js:74onBeforeMountComponent @ ReactDOMUnknownPropertyDevtool.js:78(anonymous function) @ ReactDebugTool.js:16emitEvent @ ReactDebugTool.js:13onBeforeMountComponent @ ReactDebugTool.js:242mountComponent @ ReactReconciler.js:15performInitialMount @ ReactCompositeComponent.js:238mountComponent @ ReactCompositeComponent.js:132mountComponent @ ReactReconciler.js:19_updateRenderedComponent @ ReactCompositeComponent.js:485_performComponentUpdate @ ReactCompositeComponent.js:458updateComponent @ ReactCompositeComponent.js:401receiveComponent @ ReactCompositeComponent.js:340receiveComponent @ ReactReconciler.js:64_updateRenderedComponent @ ReactCompositeComponent.js:472_performComponentUpdate @ ReactCompositeComponent.js:458updateComponent @ ReactCompositeComponent.js:401receiveComponent @ ReactCompositeComponent.js:340receiveComponent @ ReactReconciler.js:64_updateRenderedComponent @ ReactCompositeComponent.js:472_performComponentUpdate @ ReactCompositeComponent.js:458updateComponent @ ReactCompositeComponent.js:401receiveComponent @ ReactCompositeComponent.js:340receiveComponent @ ReactReconciler.js:64performUpdateIfNecessary @ ReactCompositeComponent.js:344performUpdateIfNecessary @ ReactReconciler.js:86runBatchedUpdates @ ReactUpdates.js:89perform @ Transaction.js:29perform @ Transaction.js:29perform @ ReactUpdates.js:60flushBatchedUpdates @ ReactUpdates.js:104close @ ReactUpdates.js:27closeAll @ Transaction.js:72perform @ Transaction.js:38perform @ ReactUpdates.js:60flushBatchedUpdates @ ReactUpdates.js:104closeAll @ Transaction.js:72perform @ Transaction.js:38batchedUpdates @ ReactDefaultBatchingStrategy.js:33batchedUpdates @ ReactUpdates.js:66dispatchEvent @ ReactEventListener.js:85
warning.js:25 Warning: Unknown props onSwipedLeft, onSwipedRight, flickThreshold, delta, preventDefaultTouchmoveEvent, nodeName on
tag. Remove these props from the element. For details, see https://fb.me/react-unknown-prop
in div (created by Swipeable)
in Swipeable (created by Lightbox)
in figure (created by Lightbox)
in div (created by Lightbox)
in div (created by Fade)
in Fade (created by ReactTransitionGroup)
in FirstChild (created by ReactTransitionGroup)
in ReactTransitionGroup

More information here:
https://gist.github.com/jimfb/d99e0678e9da715ccf6454961ef04d1b

'X of Y' template in props

Hi Joss,

Just wondering if you can implement a little improvement when you change anything in the library next time. It is about making X of Y something you can pass as a prop. This will be extremely useful in multilingual interfaces.

Here is how a feature can look like:

<Lightbox
    images={[{ src: 'http://example.com/img1.jpg' }, { src: 'http://example.com/img2.jpg' }]}
    imageCountTemplate="{current} ΠΈΠ· {total}" // ← Russian
/>

Certainly, imageCountTemplate can be undefined, which will output {current} of {total} as this is happening now.

Cheers!

Example images are included in npm repo

$ du -hs node_modules/react-images/*
...
6.5M    node_modules/react-images/examples

Probably don't need to download 6 megs of cute animal photos on every deploy. Add a .npmignore file to remove the examples folder. docs.

FirstChild(...): No `render` method found on the returned component instance

FirstChild(...): No render method found on the returned component instance: you may have forgotten to define render, returned null/false from a stateless component, or tried to render an element whose type is a function that isn't a React component.

I gave it a try, Issue is in the \react-images\lib\Fade.js 33 line to return empty.Want to be able to repair

adding captions in the lightbox

Is there any desire to have a caption be visible in the lightbox for an image? I've started implementing it for my own use, but I'm wondering if this is something that you'd be interested in merging in.

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.