Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react'
  2. import { Grid, Row, Col } from 'react-bootstrap'
  3. import FontAwesome from 'react-fontawesome'
  4.  
  5. export default class Slider extends React.Component {
  6.   constructor(props) {
  7.     super(props)
  8.  
  9.     this.state = {
  10.       currentElements: this.props.children.slice(
  11.         0,
  12.         this.props.numberOfElements
  13.       ),
  14.       beginningIndex: 0,
  15.       endIndex: this.props.numberOfElements
  16.     }
  17.   }
  18.  
  19.   onLeftArrowClick = () => {
  20.     this.setState((prevState, props) => {
  21.       return {
  22.         begginingIndex: prevState.begginingIndex - 1,
  23.         endIndex: prevState.endIndex - 1
  24.       }
  25.     })
  26.   }
  27.  
  28.   onRightArrowClick = () => {
  29.     this.setState((prevState, props) => {
  30.       return {
  31.         begginingIndex: prevState.begginingIndex + 1,
  32.         endIndex: prevState.endIndex + 1
  33.       }
  34.     })
  35.   }
  36.  
  37.   render = () => {
  38.     return (
  39.       <div className="slider">
  40.         <div onClick={this.onLeftArrowClick}>
  41.           <FontAwesome name="chevron-left" className="bold" size="5x" />
  42.         </div>
  43.         <div className={this.props.className}>
  44.           {this.state.currentElements}
  45.         </div>
  46.         <div onClick={this.onRightArrowClick}>
  47.           <FontAwesome name="chevron-right" className="bold" size="5x" />
  48.         </div>
  49.       </div>
  50.     )
  51.   }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement