mirror of
https://github.com/kremalicious/portfolio.git
synced 2025-01-03 10:25:00 +01:00
project nav fixes
This commit is contained in:
parent
47e00e805c
commit
f2cb601473
@ -24,32 +24,6 @@ const query = graphql`
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
class Project extends PureComponent {
|
|
||||||
static propTypes = {
|
|
||||||
node: PropTypes.object.isRequired,
|
|
||||||
currentSlug: PropTypes.string.isRequired,
|
|
||||||
refCurrentItem: PropTypes.any
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { node, currentSlug, refCurrentItem } = this.props
|
|
||||||
const isCurrent = node.slug === currentSlug
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={styles.item} ref={isCurrent ? refCurrentItem : null}>
|
|
||||||
<Link className={styles.link} to={node.slug}>
|
|
||||||
<Img
|
|
||||||
className={styles.image}
|
|
||||||
fluid={node.img.childImageSharp.fluid}
|
|
||||||
alt={node.title}
|
|
||||||
/>
|
|
||||||
<h1 className={styles.title}>{node.title}</h1>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class ProjectNav extends PureComponent {
|
export default class ProjectNav extends PureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
currentSlug: PropTypes.string.isRequired
|
currentSlug: PropTypes.string.isRequired
|
||||||
@ -82,18 +56,26 @@ export default class ProjectNav extends PureComponent {
|
|||||||
activeRect.width / 2
|
activeRect.width / 2
|
||||||
|
|
||||||
scrollContainer.scrollLeft += this.state.scrollLeftPosition
|
scrollContainer.scrollLeft += this.state.scrollLeftPosition
|
||||||
|
this.setState({ scrollLeftPosition })
|
||||||
|
}
|
||||||
|
|
||||||
this.setState(state => {
|
Project({ node, refCurrentItem }) {
|
||||||
return {
|
return (
|
||||||
...state,
|
<div className={styles.item} ref={refCurrentItem}>
|
||||||
scrollLeftPosition
|
<Link className={styles.link} to={node.slug}>
|
||||||
}
|
<Img
|
||||||
})
|
className={styles.image}
|
||||||
|
fluid={node.img.childImageSharp.fluid}
|
||||||
|
alt={node.title}
|
||||||
|
/>
|
||||||
|
<h1 className={styles.title}>{node.title}</h1>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { currentSlug } = this.props
|
const { currentSlug } = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StaticQuery
|
<StaticQuery
|
||||||
query={query}
|
query={query}
|
||||||
@ -102,14 +84,17 @@ export default class ProjectNav extends PureComponent {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<nav className={styles.projectNav} ref={this.scrollContainer}>
|
<nav className={styles.projectNav} ref={this.scrollContainer}>
|
||||||
{projects.map(({ node }) => (
|
{projects.map(({ node }) => {
|
||||||
<Project
|
const isCurrent = node.slug === currentSlug
|
||||||
key={node.id}
|
|
||||||
node={node}
|
return (
|
||||||
currentSlug={currentSlug}
|
<this.Project
|
||||||
refCurrentItem={this.currentItem}
|
key={node.slug}
|
||||||
/>
|
node={node}
|
||||||
))}
|
refCurrentItem={isCurrent ? this.currentItem : null}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
})}
|
||||||
</nav>
|
</nav>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
|
Loading…
Reference in New Issue
Block a user