1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-06-30 05:31:44 +02:00

refactor projects nav into projects slider

This commit is contained in:
Matthias Kretschmann 2018-06-11 21:11:18 +02:00
parent 6a3b501e18
commit 154adac8ad
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 51 additions and 145 deletions

View File

@ -3,19 +3,12 @@ import PropTypes from 'prop-types'
import Link from 'gatsby-link' import Link from 'gatsby-link'
import Img from 'gatsby-image' import Img from 'gatsby-image'
import FullWidth from '../atoms/FullWidth' import FullWidth from '../atoms/FullWidth'
import { ReactComponent as Index } from '../../images/index.svg'
import icons from '../atoms/Icons.module.scss'
import styles from './ProjectNav.module.scss' import styles from './ProjectNav.module.scss'
const ProjectNavLink = ({ previous, next }) => { const ProjectItem = ({ title, slug, img }) => {
const slug = previous ? previous.slug : next.slug
const title = previous ? previous.title : next.title
const img = previous ? previous.img : next.img
return ( return (
<div className={styles.item}> <div className={styles.item}>
<Link className={styles.link + ' prev'} to={slug}> <Link className={styles.link} to={slug}>
<Img <Img
className={styles.image} className={styles.image}
sizes={img.childImageSharp.sizes} sizes={img.childImageSharp.sizes}
@ -27,35 +20,29 @@ const ProjectNavLink = ({ previous, next }) => {
) )
} }
const ProjectNav = ({ previous, next }) => ( const ProjectNav = ({ projects }) => (
<FullWidth> <FullWidth>
<nav className={styles.projectNav}> <nav className={styles.projectNav}>
{previous && <ProjectNavLink previous={previous} />} {projects.map(({ node }) => (
<Link className={styles.index} title="Back to projects" to={'/'}> <ProjectItem
<Index className={icons.icon} /> key={node.slug}
</Link> title={node.title}
{next ? ( slug={node.slug}
<ProjectNavLink next={next} /> img={node.img}
) : ( />
<div className={`${styles.item} ${styles.itemEnd}`}> ))}
<div className={styles.end}>
<h3>This is the end</h3>
<p>I would rather not show you my websites from 1999.</p>
</div>
</div>
)}
</nav> </nav>
</FullWidth> </FullWidth>
) )
ProjectNavLink.propTypes = { ProjectItem.propTypes = {
previous: PropTypes.object, title: PropTypes.string,
next: PropTypes.object slug: PropTypes.string,
img: PropTypes.object
} }
ProjectNav.propTypes = { ProjectNav.propTypes = {
previous: PropTypes.object, projects: PropTypes.object
next: PropTypes.object
} }
export default ProjectNav export default ProjectNav

View File

@ -3,10 +3,23 @@
$breakpoint-project-nav: 45rem; $breakpoint-project-nav: 45rem;
.projectNav { .projectNav {
display: flex; white-space: nowrap;
flex-wrap: wrap; overflow-x: scroll;
justify-content: space-between; -webkit-overflow-scrolling: touch;
overflow: hidden;
&::-webkit-scrollbar {
display: none;
}
}
.item {
display: inline-block;
width: 45vw;
margin-left: $spacer;
&:last-child {
margin-right: $spacer * 2;
}
} }
.image { .image {
@ -20,48 +33,6 @@ $breakpoint-project-nav: 45rem;
} }
} }
.item {
flex: 1 1 46%;
position: relative;
transition: .2s ease-out;
max-width: 500px;
&:first-child {
margin-right: $spacer / 2;
&:hover,
&:focus {
transform: translate3d(-.5rem, 0, 0);
}
}
/* stylelint-disable no-descending-specificity */
&:last-child {
margin-left: $spacer / 2;
&:hover,
&:focus {
transform: translate3d(.5rem, 0, 0);
}
}
/* stylelint-enable no-descending-specificity */
@media (min-width: $breakpoint-project-nav) {
flex-basis: 33%;
&:first-child,
&:last-child {
margin: 0;
}
}
}
.itemEnd {
pointer-events: none;
display: flex;
align-items: center;
}
.title { .title {
visibility: hidden; visibility: hidden;
font-size: 0; font-size: 0;
@ -70,69 +41,3 @@ $breakpoint-project-nav: 45rem;
.link { .link {
display: block; display: block;
} }
.index {
height: 100%;
display: block;
align-self: center;
margin-top: $spacer * 2;
margin-left: $spacer;
margin-right: $spacer;
transition: .2s ease-out;
order: 3;
width: 100%;
@media (min-width: $breakpoint-project-nav) {
margin-top: 0;
margin-left: $spacer * 4;
margin-right: $spacer * 4;
order: initial;
width: auto;
}
svg {
fill: $brand-grey-light;
width: 1.5rem;
height: 1.5rem;
}
&:hover,
&:focus {
svg {
fill: $brand-cyan;
}
}
&:first-child {
margin-left: 48.5%;
}
&:last-child {
margin-right: auto;
}
}
.end {
padding-right: $spacer;
text-align: left;
h3 {
font-size: $font-size-h4;
margin-bottom: $spacer / 4;
color: $brand-grey-light;
@media (min-width: $breakpoint-project-nav) {
font-size: $font-size-h3;
}
}
p {
margin: 0;
color: $brand-grey-light;
font-size: $font-size-small;
@media (min-width: $breakpoint-project-nav) {
font-size: $font-size-base;
}
}
}

View File

@ -43,11 +43,10 @@ class Project extends Component {
render() { render() {
const meta = this.props.data.dataYaml const meta = this.props.data.dataYaml
const projects = this.props.data.allProjectsYaml.edges
const project = this.props.data.projectsYaml const project = this.props.data.projectsYaml
const projectImages = this.props.data.projectImages.edges const projectImages = this.props.data.projectImages.edges
const pathContext = this.props.pathContext
const { title, links, techstack } = project const { title, links, techstack } = project
const { next, previous } = pathContext
return ( return (
<Fragment> <Fragment>
@ -67,7 +66,7 @@ class Project extends Component {
</Content> </Content>
</article> </article>
<ProjectNav previous={previous} next={next} /> <ProjectNav projects={projects} />
</Fragment> </Fragment>
) )
} }
@ -90,7 +89,7 @@ Project.propTypes = {
export default Project export default Project
export const projectQuery = graphql` export const projectAndProjectsQuery = graphql`
query ProjectBySlug($slug: String!) { query ProjectBySlug($slug: String!) {
projectsYaml(slug: { eq: $slug }) { projectsYaml(slug: { eq: $slug }) {
title title
@ -136,6 +135,7 @@ export const projectQuery = graphql`
} }
} }
} }
projectImages: allImageSharp( projectImages: allImageSharp(
filter: { id: { regex: $slug } } filter: { id: { regex: $slug } }
sort: { fields: [id], order: ASC } sort: { fields: [id], order: ASC }
@ -147,5 +147,19 @@ export const projectQuery = graphql`
} }
} }
} }
allProjectsYaml {
edges {
node {
title
slug
img {
childImageSharp {
...ProjectImageSizes
}
}
}
}
}
} }
` `