Created
March 6, 2018 22:53
-
-
Save yordanzhelevdev/0df90d127a8a8e87e41a085e126e1e80 to your computer and use it in GitHub Desktop.
Carousel Backup
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
import React, { Component } from "react"; | |
import { CSSTransitionGroup } from 'react-transition-group'; | |
import './carousel.css'; | |
export const images = [ | |
'images/grill.jpg', | |
'images/grill2.jpg', | |
'images/grill3.jpg' | |
]; | |
class SlideHeader extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
slideshow: props.slide, | |
slideIndex: 0 | |
}; | |
this.currentIndex = 0; | |
} | |
componentDidMount() { | |
this.goTo(); | |
} | |
componentDidUpdate() { | |
this.timeout = setTimeout(() => { | |
this.goTo(); | |
}, 4000); | |
} | |
componentWillUnmount() { | |
clearInterval(this.timeout); | |
} | |
goTo() { | |
let index = 0; | |
index = this.currentIndex + 1; | |
this.currentIndex = index >= images.length ? 0 : index; | |
this.setState({ | |
slideIndex: this.currentIndex, | |
slideshow: images[this.currentIndex] | |
}); | |
} | |
render() { | |
return (<SlideItems src={this.state.slideshow} index={this.state.slideIndex}/>) ; | |
} | |
} | |
function SlideItems(props) { | |
return ( | |
<div className="slide-header"> | |
<div className="overlay-header"> | |
<h1>Grillber lorem ipsum</h1> | |
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span> | |
<button>Order Now</button> | |
</div> | |
<CSSTransitionGroup | |
transitionName="swap" | |
transitionEnterTimeout={4000} | |
transitionLeave={false}> | |
<img src={props.src} alt="grill" key={'img_ ' + props.index} /> | |
</CSSTransitionGroup> | |
</div> | |
); | |
} | |
SlideHeader.defaultProps = { | |
images: images | |
}; | |
export default SlideHeader; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment