Last active
October 4, 2018 11:20
-
-
Save DZuz14/004f0aab105a671ea59b9992d5a8820d to your computer and use it in GitHub Desktop.
Slider Wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import Slide from '../slide' | |
import LeftArrow from '../left-arrow' | |
import RightArrow from '../right-arrow' | |
export default class Slider extends Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
images: [ | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/aurora.jpg", | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/canyon.jpg", | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/city.jpg", | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/desert.jpg", | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/mountains.jpg", | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/redsky.jpg", | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/sandy-shores.jpg", | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/tree-of-life.jpg" | |
], | |
currentIndex: 0, | |
translateValue: 0 | |
} | |
} | |
goToPrevSlide = () => { | |
} | |
goToNextSlide = () => { | |
this.setState(prevState => ({ | |
currentIndex: prevState.currentIndex + 1 | |
})); | |
} | |
render() { | |
return ( | |
<div className="slider"> | |
<div className="slider-wrapper" | |
style={{ | |
transform: `translateX(${this.state.translateValue}px)`, | |
transition: 'transform ease-out 0.45s' | |
}}> | |
{ | |
this.state.images.map((image, i) => ( | |
<Slide key={i} image={image} /> | |
)) | |
} | |
</div> | |
<LeftArrow | |
goToPrevSlide={this.goToPrevSlide} | |
/> | |
<RightArrow | |
goToNextSlide={this.goToNextSlide} | |
/> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment