-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarousel.js
More file actions
36 lines (33 loc) · 865 Bytes
/
Carousel.js
File metadata and controls
36 lines (33 loc) · 865 Bytes
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
import React from "react";
class Carousel extends React.Component {
state = {
photos: [],
active: 0
};
static getDerivedStateFromProps({ media }) {
let photos = [];
if (media && media.photos && media.photos.photo) {
photos = media.photos.photo.filter(photo => photo["@size"] === "pn");
}
return { photos };
}
render() {
const { photos, active } = this.state;
return (
<div className="carousel">
<img src={photos[active].value} alt="animal" />
<div className="carousel-smaller">
{photos.map((photo, index) => (
<img
key={photo.value}
src={photo.value}
className={index === active ? "active" : ""}
alt="animal thumbnail"
/>
))}
</div>
</div>
);
}
}
export default Carousel;