Getting Started
1. Install using npm:
npm install react-images-texts-videos --save
2. Example with images:
<Lightbox
items={{
type:'images',
content: [
{ src: '../images/photo-1.jpg' },
{ src: '../images/photo-2.jpg' }
]}}
isOpen={this.state.lightboxIsOpen}
onClickPrev={this.gotoPrevLightboxImage}
onClickNext={this.gotoNextLightboxImage}
onClose={this.closeLightbox}
/>
3. Example with texts:
<Lightbox
items={{
type:'texts',
content: [
'Text1...',
'Text2...'
]}}
isOpen={this.state.lightboxIsOpen}
onClickPrev={this.gotoPrevLightboxText}
onClickNext={this.gotoNextLightboxText}
onClose={this.closeLightbox}
/>
3. Example with videos:
<Lightbox
items={{type:'videos', items: ['videoId1', 'videoId2']}}
isOpen={this.state.lightboxIsOpen}
onClickPrev={this.gotoPrevLightboxText}
onClickNext={this.gotoNextLightboxText}
onClose={this.closeLightbox}
/>
Options
| Property |
Type |
Default |
Description |
| backdropClosesModal |
bool |
false |
Allow users to exit the lightbox by clicking the backdrop |
| currentImage |
number |
0 |
The index of the image to display initially |
| customControls |
array |
undefined |
An array of elements to display as custom controls on the top of lightbox |
| enableKeyboardInput |
bool |
true |
Supports keyboard input - esc, arrow left, and arrow right |
| items |
object |
undefined |
A object containing two values, the type of element (images, texts or videos), and an array with the items |
| imageCountSeparator |
string |
' of ' |
Custom separator for the image count |
| isOpen |
bool |
false |
Whether or not the lightbox is displayed |
| onClickPrev |
func |
undefined |
Fired on request of the previous image |
| onClickNext |
func |
undefined |
Fired on request of the next image |
| onClickImage |
func |
undefined |
Handle click event on the current image |
| onClickThumbnail |
func |
undefined |
Handle click on thumbnail |
| onClose |
func |
undefined |
Required. Handle closing of the lightbox |
| preloadNextImage |
bool |
true |
Based on the direction the user is navigating, preload the next available image. |
| showCloseButton |
bool |
true |
Optionally display a close "X" button in top right corner |
| showImageCount |
bool |
true |
Optionally display image index, e.g., "3 of 20" |
| showThumbnails |
bool |
false |
Optionally display thumbnails beneath the Lightbox |
| theme |
object |
undefined |
Pass through styles to theme each component; arrow, container, etc. |
| width |
number |
1024 |
Maximum width of the carousel; defaults to 1024px |
Items
| Property |
Type |
Default |
Description |
| type |
string |
undefined |
Required. It can be one of three options: images, texts or videos |
| content |
array |
undefined |
List of the items |
Images items format
| Property |
Type |
Default |
Description |
| src |
string |
undefined |
Required. The primary image path |
| srcset |
array |
undefined |
List of alternative image sizes |
| caption |
string |
undefined |
Displayed benath the current image. Great for description or attribution |
| thumbnail |
string |
undefined |
Thumbnail to display if showThumbnails is set to true |
Text items format
Videos items format
Array of strings that fit any youtube video id
License
React Images is free to use for personal and commercial projects under the MIT license.
Attribution is not required, but greatly appreciated. It does not have to be user-facing and can remain within the code.