-
Notifications
You must be signed in to change notification settings - Fork 311
/
ExampleWithLightbox.js
61 lines (59 loc) · 1.55 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
59
60
61
import React from "react";
import ReactDOM from "react-dom";
import Gallery from "react-photo-gallery";
import Carousel, { Modal, ModalGateway } 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 with a Lightbox component</h2>
<Gallery photos={this.props.photos} onClick={this.openLightbox} />
<ModalGateway>
{this.state.lightboxIsOpen ? (
<Modal onClose={this.closeLightbox}>
<Carousel
currentIndex={this.state.currentImage}
views={this.props.photos.map(x => ({
...x,
srcset: x.srcSet,
caption: x.title
}))}
/>
</Modal>
) : null}
</ModalGateway>
</div>
);
}
}
export default ExampleWithLightbox;