Skip to content

Commit fb8fb5f

Browse files
committed
Fix slide transition
1 parent c33beda commit fb8fb5f

File tree

5 files changed

+79
-23
lines changed

5 files changed

+79
-23
lines changed

src/About.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
23
import { Link } from 'react-router-dom';
34

45
class About extends Component {
6+
static propTypes = {
7+
onClickLink: PropTypes.func.isRequired
8+
};
9+
510
componentDidMount() {
611
document.querySelector('title').textContent = 'Abhishek Chaudhuri - About';
712
document.querySelector('.links-about').classList.add('selected');
@@ -10,6 +15,8 @@ class About extends Component {
1015
}
1116

1217
render() {
18+
const { onClickLink } = this.props;
19+
1320
const bio = 'Abhishek Chaudhuri is a college student from North Brunswick, New Jersey. He studies' +
1421
' at Rutgers University-New Brunswick, majors in Computer Engineering, and minors in Computer' +
1522
' Science. He excels in subjects like math and science and has a strong penchant for' +
@@ -28,7 +35,8 @@ class About extends Component {
2835
<p className="about-bio" tabIndex={0}>{bio}</p>
2936
</div>
3037
</div>
31-
<Link className="arrow-right" to="/projects" aria-label="Go to Projects">
38+
<Link className="arrow-right" to="/projects" aria-label="Go to Projects"
39+
onClick={() => onClickLink('projects')}>
3240
<i className="fas fa-arrow-right"/>
3341
</Link>
3442
</main>

src/App.css

+18-12
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,39 @@ main {
2727
}
2828

2929
/* Transition effects */
30-
.slide-enter {
30+
.left .slide-enter {
3131
transform: translate(110%);
3232
}
3333

34-
.slide-enter.slide-enter-active {
34+
.right .slide-enter {
35+
transform: translate(-110%);
36+
}
37+
38+
.left .slide-enter.slide-enter-active,
39+
.right .slide-enter.slide-enter-active {
3540
transform: translate(0%);
3641
transition: 600ms ease-in-out;
3742
position: fixed;
3843
width: 100%; /* Match contact's width with other components */
3944
}
4045

41-
.slide-exit {
46+
.left .slide-exit,
47+
.right .slide-exit {
4248
transform: translate(0%);
4349
}
4450

45-
.slide-exit.slide-exit-active {
51+
.left .slide-exit.slide-exit-active {
4652
transform: translate(-110%);
4753
transition: 600ms ease-in-out;
4854
position: relative;
4955
}
5056

57+
.right .slide-exit.slide-exit-active {
58+
transform: translate(110%);
59+
transition: 600ms ease-in-out;
60+
position: relative;
61+
}
62+
5163
/* Heading */
5264
.heading {
5365
padding-bottom: 0;
@@ -177,12 +189,6 @@ main {
177189
margin: auto;
178190
}
179191

180-
@media screen and (max-width: 500px) {
181-
.about-bio {
182-
width: 100%;
183-
}
184-
}
185-
186192
/* Projects section */
187193
.projects-list {
188194
padding: 0 5%;
@@ -200,7 +206,7 @@ main {
200206
padding-right: 1%;
201207
}
202208

203-
@media screen and (max-width: 600px) {
209+
@media screen and (max-width: 800px) {
204210
.projects-list li {
205211
width: 100%; /* If viewport is too small, have one card per row */
206212
}
@@ -211,7 +217,7 @@ main {
211217
}
212218

213219
.projects-image {
214-
width: 30%;
220+
width: 70%;
215221
}
216222

217223
.projects-technology {

src/App.js

+33-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class App extends Component {
1818
history: PropTypes.object.isRequired
1919
};
2020

21+
state = {
22+
slideDirection: 'left' // Determines which direction to slide components
23+
};
24+
2125
componentDidMount() {
2226
// Change title of tab every page change
2327
if (window.location.pathname === '/')
@@ -41,7 +45,26 @@ class App extends Component {
4145
navbar.classList.add('sticky') : navbar.classList.remove('sticky');
4246
};
4347

48+
setSlider = dest => {
49+
// Check where to slide the components
50+
if (window.location.pathname === '/contact') {
51+
// At Contact, always slide right
52+
this.setState({slideDirection: 'right'});
53+
} else if (window.location.pathname === '/projects') {
54+
// At Projects, check which link was clicked
55+
if (dest === 'about') {
56+
this.setState({slideDirection: 'right'});
57+
} else {
58+
this.setState({slideDirection: 'left'});
59+
}
60+
} else {
61+
// At About, always slide left (default)
62+
this.setState({slideDirection: 'left'});
63+
}
64+
};
65+
4466
render() {
67+
const slideDirection = this.state.slideDirection;
4568
const location = this.props.location;
4669
window.onscroll = this.checkScroll;
4770

@@ -56,12 +79,15 @@ class App extends Component {
5679
</header>
5780
<nav className="links">
5881
{/* Redirect routes without reloading the browser */}
59-
<Link className="links-about" to="/about">About</Link>
60-
<Link className="links-projects" to="/projects">Projects</Link>
61-
<Link className="links-contact" to="/contact">Contact</Link>
82+
<Link className="links-about" to="/about"
83+
onClick={() => this.setSlider('about')}>About</Link>
84+
<Link className="links-projects" to="/projects"
85+
onClick={() => this.setSlider('projects')}>Projects</Link>
86+
<Link className="links-contact" to="/contact"
87+
onClick={() => this.setSlider('contact')}>Contact</Link>
6288
</nav>
6389
<hr/>
64-
<TransitionGroup className="transition-group">
90+
<TransitionGroup className={'transition-group ' + slideDirection}>
6591
<CSSTransition key={location.key} timeout={{ enter: 600, exit: 600 }}
6692
classNames={'slide'}>
6793
<Switch location={location}>
@@ -76,13 +102,13 @@ class App extends Component {
76102
</main>
77103
)}/>
78104
<Route path={process.env.PUBLIC_URL + '/about'} render={() => (
79-
<About/>
105+
<About onClickLink={this.setSlider}/>
80106
)}/>
81107
<Route path={process.env.PUBLIC_URL + '/projects'} render={() => (
82-
<Projects/>
108+
<Projects onClickLink={this.setSlider}/>
83109
)}/>
84110
<Route path={process.env.PUBLIC_URL + '/contact'} render={() => (
85-
<Contact/>
111+
<Contact onClickLink={this.setSlider}/>
86112
)}/>
87113
</Switch>
88114
</CSSTransition>

src/Contact.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
23
import { Link } from 'react-router-dom';
34

45
class Contact extends Component {
6+
static propTypes = {
7+
onClickLink: PropTypes.func.isRequired
8+
};
9+
510
componentDidMount() {
611
document.querySelector('title').textContent = 'Abhishek Chaudhuri - Contact';
712
document.querySelector('.links-about').classList.remove('selected');
@@ -10,9 +15,12 @@ class Contact extends Component {
1015
}
1116

1217
render() {
18+
const { onClickLink } = this.props;
19+
1320
return (
1421
<main className="contact">
15-
<Link className="arrow-left" to="/projects" aria-label="Go to Projects">
22+
<Link className="arrow-left" to="/projects" aria-label="Go to Projects"
23+
onClick={() => onClickLink('projects')}>
1624
<i className="fas fa-arrow-left"/>
1725
</Link>
1826
<div className="contact-wrapper">

src/Projects.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
23
import { Link } from 'react-router-dom';
34
import projectData from './projects.json';
45

56
class Projects extends Component {
7+
static propTypes = {
8+
onClickLink: PropTypes.func.isRequired
9+
};
10+
611
componentDidMount() {
712
document.querySelector('title').textContent = 'Abhishek Chaudhuri - Projects';
813
document.querySelector('.links-about').classList.remove('selected');
@@ -11,12 +16,14 @@ class Projects extends Component {
1116
}
1217

1318
render() {
19+
const { onClickLink } = this.props;
1420
// Extract JSON data as an array
1521
const projects = JSON.parse(JSON.stringify(projectData));
1622

1723
return (
1824
<main className="projects">
19-
<Link className="arrow-left" to="/about" aria-label="Go to About">
25+
<Link className="arrow-left" to="/about" aria-label="Go to About"
26+
onClick={() => onClickLink('about')}>
2027
<i className="fas fa-arrow-left"/>
2128
</Link>
2229
<div className="projects-wrapper">
@@ -46,7 +53,8 @@ class Projects extends Component {
4653
</ul>
4754
<p className="projects-addendum" tabIndex={0}>...And much more on GitHub!</p>
4855
</div>
49-
<Link className="arrow-right" to="/contact" aria-label="Go to Contact">
56+
<Link className="arrow-right" to="/contact" aria-label="Go to Contact"
57+
onClick={() => onClickLink('contact')}>
5058
<i className="fas fa-arrow-right"/>
5159
</Link>
5260
</main>

0 commit comments

Comments
 (0)