Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.26 KB | None | 0 0
  1. import React, {Component} from "react";
  2. import styles from '../styles/AnimatedWrapper.css';
  3.  
  4. const AnimatedWrapper = WrappedComponent =>
  5. class AnimatedWrapper extends Component {
  6. componentWillAppear(cb) {
  7. console.log('componentWillAppear');
  8. cb();
  9. }
  10. componentWillEnter(cb) {
  11. console.log('componentWillEnter');
  12. cb();
  13. }
  14. componentWillLeave(cb) {
  15. console.log('componentWillLeave');
  16. cb();
  17. }
  18. render() {
  19. return (
  20. <div id="animated-wrapper" className={styles.animatedPageWrapper}>
  21. <WrappedComponent {...this.props}/>
  22. </div>
  23. );}
  24. };
  25.  
  26. export default AnimatedWrapper;
  27.  
  28. import React, { Component } from 'react';
  29. import { Route, Switch } from 'react-router-dom';
  30. import TransitionGroup from "react-transition-group/TransitionGroup";
  31.  
  32. import Navbar from "./components/Navbar";
  33. import Footer from "./components/Footer";
  34. import Slider from "./components/Slider";
  35. import ComingSoon from "./components/ComingSoon";
  36.  
  37. const firstChild = props => {
  38. const childrenArray = React.Children.toArray(props.children);
  39. return childrenArray[0] || null;
  40. }
  41.  
  42. class App extends Component {
  43. render() {
  44. return (
  45. <div className="App">
  46. <Navbar />
  47. <Switch>
  48. <Route
  49. path="/coming-soon"
  50. children={({ match, ...rest }) => (
  51. <TransitionGroup component={firstChild}>
  52. {match && <ComingSoon {...rest} />}
  53. </TransitionGroup>
  54. )}/>
  55. <Route
  56. path="/"
  57. children={({ match, ...rest }) => (
  58. <TransitionGroup component={firstChild}>
  59. {match && <Slider {...rest} />}
  60. </TransitionGroup>
  61. )}/>
  62. </Switch>
  63. <Footer />
  64. </div>
  65. );
  66. }
  67. }
  68.  
  69. export default App;
  70.  
  71. import React from 'react';
  72. import ReactDOM from 'react-dom';
  73. import { BrowserRouter } from 'react-router-dom';
  74. import App from './App';
  75. import './index.css';
  76.  
  77. ReactDOM.render(
  78. <BrowserRouter>
  79. <App />
  80. </BrowserRouter>,
  81. document.getElementById('root')
  82. );
  83.  
  84. import React, { Component } from 'react';
  85. import _ from 'lodash';
  86.  
  87. // components
  88. import AnimatedWrapper from './AnimatedWrapper';
  89. import Separator from './Separator';
  90.  
  91. // styles
  92. import styles from '../styles/Slider.css';
  93.  
  94. // images
  95. import Apartment from "../../public/images/apartment.jpg";
  96. import Floor from "../../public/images/floor.jpg";
  97. import Furniture from "../../public/images/furniture.jpg";
  98. import Kitchen1 from "../../public/images/kitchen.jpg";
  99. import Kitchen2 from "../../public/images/kitchen-2.jpg";
  100.  
  101. class SliderComponent extends Component {
  102. constructor(props) {
  103. super(props);
  104.  
  105. this.state = {
  106. currentSlide: 0,
  107. slides: [Apartment, Floor, Furniture, Kitchen1, Kitchen2]
  108. };
  109. }
  110.  
  111. componentDidMount() {
  112. this.zoomAnimation();
  113. this.slideContentAnimation();
  114.  
  115. this.sliderInterval = setInterval(() => {
  116. if (this.state.currentSlide === 4) {
  117. if (this.refs.slider) {
  118. this.setState({ currentSlide: 0 });
  119. }
  120. } else {
  121. if (this.refs.slider) {
  122. this.setState({ currentSlide: this.state.currentSlide + 1 });
  123. }
  124. }
  125. }, 6000);
  126. }
  127.  
  128. componentWillUpdate() {
  129. const currentContent = document.getElementById(`content-${this.state.currentSlide}`);
  130. setTimeout(() => {
  131. currentContent.classList.remove(`${styles.currentContent}`);
  132. }, 1500);
  133. }
  134.  
  135. componentDidUpdate() {
  136. this.zoomAnimation();
  137. this.slideContentAnimation();
  138. }
  139.  
  140. setSlide(number) {
  141. this.setState({ currentSlide: number });
  142. }
  143.  
  144. zoomAnimation() {
  145. setTimeout(() => {
  146. const currentSlide = document.getElementById(`slide-${this.state.currentSlide}`);
  147. currentSlide.classList.add(`${styles.slideZoom}`);
  148. }, 500);
  149. }
  150.  
  151. slideContentAnimation() {
  152. setTimeout(() => {
  153. const currentContent = document.getElementById(`content-${this.state.currentSlide}`);
  154. if (currentContent) {
  155. currentContent.classList.add(`${styles.currentContent}`);
  156. }
  157. }, 1500);
  158. }
  159.  
  160. renderSlides() {
  161. return this.state.slides.map((slide, index) => {
  162. const isCurrent = index === this.state.currentSlide;
  163.  
  164. const slideStyle = {
  165. backgroundImage: `url(${this.state.slides[index]})`
  166. }
  167.  
  168. return (
  169. <div
  170. id={`slide-${index}`}
  171. key={`slide-${index}`}
  172. className={`
  173. ${styles.slide}
  174. ${isCurrent ? styles.currentSlide : null}
  175. `}
  176. style={slideStyle}
  177. alt="slide">
  178. <div
  179. id={`content-${index}`}
  180. key={`content-${index}`}
  181. className={`
  182. ${styles.content}
  183. `}>
  184. <h1>{`WE SPECIALIZE IN KITCHENS ${index}`}</h1>
  185. <Separator
  186. containerWidth={720}
  187. circleWidth={5}
  188. circleHeight={5}
  189. backgroundColor="#fff"
  190. lineWidth={350}
  191. lineColor="#fff"
  192. />
  193. <div
  194. className={`${styles['hvr-sweep-to-top']} ${styles.btn}`}>
  195. More Information
  196. </div>
  197. </div>
  198. </div>
  199. );
  200. });
  201. }
  202.  
  203. renderNavBar() {
  204. return (
  205. <div className={styles.sliderNav}>
  206. {_.range(5).map((index) => {
  207. return (
  208. <div
  209. key={index}
  210. onClick={() => this.setSlide(index)}
  211. className={this.state.currentSlide === index ? styles.current : null}>
  212. </div>
  213. )
  214. })}
  215. </div>
  216. )
  217. }
  218.  
  219. render() {
  220. return (
  221. <div className={styles.container} ref="slider">
  222. <div className={styles.slidesContainer}>
  223. {this.renderSlides()}
  224. </div>
  225.  
  226. {this.renderNavBar()}
  227. </div>
  228. );
  229. }
  230. }
  231.  
  232. const Slider = AnimatedWrapper(SliderComponent);
  233. export default Slider;
  234.  
  235. import React from 'react';
  236. import AnimatedWrapper from './AnimatedWrapper';
  237. import styles from '../styles/ComingSoon.css';
  238.  
  239. const ComingSoonComponent = function() {
  240. return (
  241. <div>
  242. <div className={styles.mainContent}>
  243. <div>
  244. <h1 className={styles.mainTitle}>{`Coming Soon`}</h1>
  245. </div>
  246. </div>
  247. </div>
  248. );
  249. };
  250.  
  251. const ComingSoon = AnimatedWrapper(ComingSoonComponent);
  252. export default ComingSoon;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement