Created
January 19, 2016 06:58
-
-
Save codeaholicguy/3c9507b11a35af4a235a to your computer and use it in GitHub Desktop.
This file contains 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
let _slides = [{ | |
imageUrl: "image.jpg", | |
caption: "This is image" | |
}, { | |
imageUrl: "image.jpg", | |
caption: "This is image" | |
}]; | |
class App extends React.Component { | |
render() { | |
return <SlideShow slides={ _slides } /> | |
} | |
} | |
class SlideShow extends React.Component { | |
constructor() { | |
super() | |
this.state = { activeIndex: 0 }; | |
} | |
jumpToSlide(index) { | |
this.setState({ activeIndex: index }); | |
} | |
render() { | |
return ( | |
<div className="slideshow"> | |
<ul className="slideshow-slides"> | |
{ | |
this.props.slides.map((slide, index) => ( | |
<li className={ classNames({ active: index == this.state.activeIndex }) }> | |
<figure> | |
<img src={ slide.imageUrl } /> | |
{ slide.caption ? <figcaption>{ slide.caption }</figcaption> : null } | |
</figure> | |
</li> | |
)) | |
} | |
</ul> | |
<ul className="slideshow-dots"> | |
{ | |
this.props.slides.map((slide, index) => ( | |
<li className={ (index == this.state.activeIndex) ? 'active': '' }> | |
<a onClick={ (event)=> this.jumpToSlide(index) }>{ index + 1 }</a> | |
</li> | |
)) | |
} | |
</ul> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment