-
Notifications
You must be signed in to change notification settings - Fork 311
/
ExampleWithLightbox.js
58 lines (56 loc) · 1.59 KB
/
ExampleWithLightbox.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React from 'react';
import ReactDOM from 'react-dom';
import Gallery from 'react-photo-gallery';
import Lightbox from 'react-images';
class ExampleWithLightbox extends React.Component {
constructor() {
super();
this.state = { currentImage: 0 };
this.closeLightbox = this.closeLightbox.bind(this);
this.openLightbox = this.openLightbox.bind(this);
this.gotoNext = this.gotoNext.bind(this);
this.gotoPrevious = this.gotoPrevious.bind(this);
}
openLightbox(event, obj) {
this.setState({
currentImage: obj.index,
lightboxIsOpen: true,
});
}
closeLightbox() {
this.setState({
currentImage: 0,
lightboxIsOpen: false,
});
}
gotoPrevious() {
this.setState({
currentImage: this.state.currentImage - 1,
});
}
gotoNext() {
this.setState({
currentImage: this.state.currentImage + 1,
});
}
render() {
return (
<div>
<h2>Using a Lightbox:</h2>
<Gallery photos={this.props.photos} columns={this.props.columns} onClick={this.openLightbox}/>
<Lightbox
theme={{ container: { background: 'rgba(0, 0, 0, 0.85)' } }}
images={this.props.photos.map(x => ({ ...x, srcset: x.srcSet, caption: x.title }))}
backdropClosesModal={true}
onClose={this.closeLightbox}
onClickPrev={this.gotoPrevious}
onClickNext={this.gotoNext}
currentImage={this.state.currentImage}
isOpen={this.state.lightboxIsOpen}
width={1600}
/>
</div>
);
}
}
export default ExampleWithLightbox;