Skip to content

Instantly share code, notes, and snippets.

@codeaholicguy
Created January 19, 2016 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeaholicguy/3c9507b11a35af4a235a to your computer and use it in GitHub Desktop.
Save codeaholicguy/3c9507b11a35af4a235a to your computer and use it in GitHub Desktop.
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