Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-lightbox-with-youtube

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-lightbox-with-youtube

A simple, responsive lightbox component for displaying an array of images with React.js

  • 0.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

React Images

Join the chat at https://gitter.im/react-images/Lobby

A simple, responsive lightbox component for displaying an array of images.

Quick start

npm install --save react-images
import React from 'react';
import Lightbox from 'react-images';

export default class Sample extends React.Component {
  ...
  render() {
    return (
      <Lightbox
        images={[{ src: 'http://example.com/img1.jpg' }, { src: 'http://example.com/img2.jpg' }]}
        isOpen={this.state.lightboxIsOpen}
        onClickPrev={this.gotoPrevious}
        onClickNext={this.gotoNext}
        onClose={this.closeLightbox}
      />
    );
  }
}

Demo & Examples

Live demo: jossmac.github.io/react-images

To build the examples locally, run:

npm install
npm start

Then open localhost:8000 in a browser.

Using srcset

Example using srcset:

<Lightbox
  images={LIGHTBOX_IMAGE_SET}
  ...
/>

const LIGHTBOX_IMAGE_SET = [
  {
    src: 'http://example.com/example/img1.jpg',
    srcset: [
      'http://example.com/example/img1_1024.jpg 1024w',
      'http://example.com/example/img1_800.jpg 800w',
      'http://example.com/example/img1_500.jpg 500w',
      'http://example.com/example/img1_320.jpg 320w',
    ],
  },
  {
    src: 'http://example.com/example/img2.jpg',
    srcset: [
      'http://example.com/example/img2_1024.jpg 1024w',
      'http://example.com/example/img2_800.jpg 800w',
      'http://example.com/example/img2_500.jpg 500w',
      'http://example.com/example/img2_320.jpg 320w',
    ],
  }
];

Notes on srcset support:

The srcset attribute is supported by some modern browsers. Results of browser implementation and behaviour may vary. The sizes attribute uses the default maxWidth CSS property set to the image. By default this is 80% so 80vw.

Another thing to note is that 'h' or height in the srcset attribute does not yet exist. Because of the nature of the fixed height of a Lightbox this is problematic for portrait sized images. You will need to calculate what the best 'w' size for a portrait size ought to be given the height of the fixed viewport otherwise unnecessarily large images will be fetched. See issue: https://github.com/ResponsiveImagesCG/picture-element/issues/86

Read more about the srcset and sizes attributes here: https://ericportis.com/posts/2014/srcset-sizes/.

Adding Captions

Example using caption for the first image:

<Lightbox
  images={LIGHTBOX_IMAGE_SET}
  ...
/>

const LIGHTBOX_IMAGE_SET = [
  {
    src: 'http://example.com/example/img1.jpg',
    caption: 'Sydney, Australia - Photo by Jill Smith',
  },
  {
    src: 'http://example.com/example/img2.jpg',
  }
];

Note that the caption is an entirely optional property, as can be seen in the first gallery on the example page. The first image has a single line caption, the second demonstrates multiline, and the remaining images are without captions, entirely.

Options

PropertyTypeDefaultDescription
backdropClosesModalboolfalseAllow users to exit the lightbox by clicking the backdrop
closeButtonTitlestring' Close (Esc) 'Customize close esc title
enableKeyboardInputbooltrueSupports keyboard input - esc, arrow left, and arrow right
currentImagenumber0The index of the image to display initially
customControlsarrayundefinedAn array of elements to display as custom controls on the top of lightbox
imagesarrayundefinedRequired. An array of objects containing valid src and srcset values of img element
imageCountSeparatorString' of 'Customize separator in the image count
isOpenboolfalseWhether or not the lightbox is displayed
leftArrowTitlestring' Previous (Left arrow key) 'Customize of left arrow title
onClickPrevfuncundefinedFired on request of the previous image
onClickNextfuncundefinedFired on request of the next image
onClosefuncundefinedRequired. Handle closing of the lightbox
onClickImagefuncundefinedHandle click on image
onClickThumbnailfuncundefinedHandle click on thumbnail
preloadNextImagebooltrueBased on the direction the user is navigating, preload the next available image
rightArrowTitlestring' Next (Right arrow key) 'Customize right arrow title
showCloseButtonbooltrueOptionally display a close "X" button in top right corner
showImageCountbooltrueOptionally display image index, e.g., "3 of 20"
widthnumber1024Maximum width of the carousel; defaults to 1024px

Keywords

FAQs

Package last updated on 29 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc