1.0.1 • Published 7 years ago

react-blackbox v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

React Images Viewer

A simple react component for displaying an array of images.

Quick start

npm install --save react-blackbox
import React from 'react';
import Blackbox from 'react-image-viewer';

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

To build the examples locally, run:

npm install
npm start

Then open localhost:8000 in a browser.

Example using caption for the first image:

<Blackbox
  images={Blackbox_IMAGE_SET}
  ...
/>

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

Options

PropertyTypeDefaultDescription
backdropClosesModalboolfalseAllow users to exit the blackbox 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 blackbox
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 blackbox 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 blackbox
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
hideArrowboolfalseShow image arrow to change images