Skip to content

Commit

Permalink
5
Browse files Browse the repository at this point in the history
  • Loading branch information
btholt committed Sep 9, 2018
1 parent ec3482d commit 89678fe
Show file tree
Hide file tree
Showing 6 changed files with 383 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"presets": [
"react",
[
"env",
{
"targets": {
"browsers": ["last 2 versions"]
}
}
]
],
"plugins": ["transform-class-properties"]
}
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"react/prop-types": 0
},
"plugins": ["react", "import", "jsx-a11y"],
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
Expand Down
259 changes: 259 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
},
"homepage": "https://github.com/btholt/complete-intro-to-react-v4#readme",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.6",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"eslint": "^5.3.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-import": "^2.13.0",
Expand Down
50 changes: 50 additions & 0 deletions src/Carousel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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 };
}
handleIndexClick = event => {
this.setState({
active: +event.target.dataset.index
});
};
render() {
const { photos, active } = this.state;

let hero = "http://placecorgi.com/300/300";
if (photos[active] && photos[active].value) {
hero = photos[active].value;
}

return (
<div className="carousel">
<img src={hero} alt="animal" />
<div className="carousel-smaller">
{photos.map((photo, index) => (
/* eslint-disable-next-line */
<img
onClick={this.handleIndexClick}
data-index={index}
key={photo.value}
src={photo.value}
className={index === active ? "active" : ""}
alt="animal thumnbail"
/>
))}
</div>
</div>
);
}
}

export default Carousel;
Loading

0 comments on commit 89678fe

Please # to comment.