Advertisement
dfghgfhplkjbv

src/components/SingleJob/VacancyGallery.js

Mar 4th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import Swiper from 'react-id-swiper'
  3. import styles from './VacancyGallery.module.scss'
  4. import Img from 'gatsby-image'
  5.  
  6. class VacancyGallery extends Component {
  7. state = { activeImageUrl: null }
  8.  
  9. componentDidMount = () => {
  10. const { photo } = this.props
  11. if (photo.length > 0) {
  12. this.setState({
  13. activeImageUrl: photo[0].url,
  14. })
  15. }
  16. }
  17.  
  18. chooseActiveImage = (url) => {
  19. this.setState({ activeImageUrl: url })
  20. }
  21.  
  22. openActiveImage = (url) => {
  23. if (typeof window !== 'undefined') window.open(url, '_blank')
  24. }
  25.  
  26. render() {
  27. const sliderParams = {
  28. slidesPerView: 3,
  29. spaceBetween: 30,
  30. loop: false,
  31. autoplay: true,
  32. rebuildOnUpdate: false,
  33. preventClicks: false,
  34. preventClicksPropagation: false,
  35. breakpoints: {
  36. 1200: {
  37. slidesPerView: 3,
  38. },
  39. 860: {
  40. slidesPerView: 2,
  41. slidesPerGroup: 2,
  42. },
  43. },
  44. }
  45.  
  46. const { photo } = this.props
  47. return (
  48. <>
  49. {photo.length > 0 && (
  50. <div className={styles.root}>
  51. <div className={styles.activeImageWrapper} onClick={() => this.openActiveImage(this.state.activeImageUrl)}>
  52. <Img className={styles.activeImage} fluid={this.props.photo[0].fluid} alt="" />
  53. </div>
  54.  
  55. <Swiper {...sliderParams}>
  56. {photo.map((item, index) => (
  57. <div onClick={() => this.chooseActiveImage(item.url)} className={styles.slide} key={index}>
  58. <img className={styles.img} src={item.url} alt="" />
  59. </div>
  60. ))}
  61. </Swiper>
  62. </div>
  63. )}
  64. </>
  65. )
  66. }
  67. }
  68.  
  69. export default VacancyGallery
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement