2018-06-11 23:54:16 +02:00
|
|
|
import React, { Component } from 'react'
|
2018-04-16 22:32:30 +02:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import Link from 'gatsby-link'
|
2018-05-04 01:58:43 +02:00
|
|
|
import Img from 'gatsby-image'
|
2018-06-11 19:48:38 +02:00
|
|
|
import FullWidth from '../atoms/FullWidth'
|
|
|
|
import styles from './ProjectNav.module.scss'
|
2018-04-16 22:32:30 +02:00
|
|
|
|
2018-06-11 23:54:16 +02:00
|
|
|
const ProjectItem = ({ title, slug, img, current }) => (
|
|
|
|
<div className={styles.item} id={current ? 'current' : null}>
|
|
|
|
<Link className={styles.link} to={slug}>
|
|
|
|
<Img
|
|
|
|
className={styles.image}
|
|
|
|
sizes={img.childImageSharp.sizes}
|
|
|
|
alt={title}
|
|
|
|
/>
|
|
|
|
<h1 className={styles.title}>{title}</h1>
|
|
|
|
</Link>
|
|
|
|
</div>
|
2018-04-16 22:32:30 +02:00
|
|
|
)
|
|
|
|
|
2018-06-11 23:54:16 +02:00
|
|
|
class ProjectNav extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
this.scrollToCurrent()
|
|
|
|
}
|
|
|
|
|
|
|
|
scrollToCurrent = () => {
|
|
|
|
const container = window.document.getElementById('scrollContainer')
|
|
|
|
const current = window.document.getElementById('current')
|
|
|
|
const currentLeft = current.getBoundingClientRect().left
|
|
|
|
const currentWidth = current.clientWidth
|
|
|
|
const finalPosition = currentLeft - window.innerWidth / 2 + currentWidth / 2
|
|
|
|
|
|
|
|
container.scrollLeft = finalPosition
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { projects, project } = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FullWidth>
|
|
|
|
<nav className={styles.projectNav} id="scrollContainer">
|
|
|
|
{projects.map(({ node }) => {
|
|
|
|
const current = node.slug === project.slug
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ProjectItem
|
|
|
|
key={node.slug}
|
|
|
|
title={node.title}
|
|
|
|
current={current}
|
|
|
|
slug={node.slug}
|
|
|
|
img={node.img}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</nav>
|
|
|
|
</FullWidth>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-11 21:11:18 +02:00
|
|
|
ProjectItem.propTypes = {
|
2018-06-11 23:54:16 +02:00
|
|
|
current: PropTypes.bool,
|
2018-06-11 21:11:18 +02:00
|
|
|
title: PropTypes.string,
|
|
|
|
slug: PropTypes.string,
|
|
|
|
img: PropTypes.object
|
2018-05-23 00:03:46 +02:00
|
|
|
}
|
|
|
|
|
2018-04-16 22:32:30 +02:00
|
|
|
ProjectNav.propTypes = {
|
2018-06-11 23:54:16 +02:00
|
|
|
projects: PropTypes.array,
|
|
|
|
project: PropTypes.object
|
2018-04-16 22:32:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ProjectNav
|