Skip to content

Commit 290079d

Browse files
authored
Merge pull request #281 from Super3laa/AlaaEssam
2 parents 75147e2 + 664d7bb commit 290079d

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

src/App.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import './App.css';
33
import LinkButton from './components/LinkButton/LinkButton';
44
import Navbar from './components/Navbar/Navbar';
55
import CardsContainer from './components/ProjectList/CardsContainer';
6+
import ScrollUpButton from './components/ScrollUpButton/ScrollUpButton';
67
import SocialShare from './components/SocialShare/SocialShare';
78

89
const App = () => {
@@ -12,6 +13,7 @@ const App = () => {
1213
<div className="App-header">
1314
<h1>Make your first open source contribution in 5 minutes</h1>
1415
</div>
16+
<ScrollUpButton />
1517
<LinkButton />
1618
<CardsContainer />
1719
<SocialShare/>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
.Scroll-Up {
3+
cursor: pointer;
4+
position: relative;
5+
animation: swing alternate 0.5s infinite;
6+
}
7+
8+
.Scroll-Up:active {
9+
opacity: 0.75;
10+
}
11+
12+
.Scroll-Up-Wrapper {
13+
padding: 1vw;
14+
padding-bottom: 1.75vw;
15+
z-index: 3;
16+
position: fixed;
17+
bottom: 0;
18+
right: 0;
19+
}
20+
21+
@keyframes swing {
22+
from {
23+
top: -0.5rem;
24+
}
25+
26+
to {
27+
top: 1rem;
28+
}
29+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React,{useEffect, useState} from 'react'
2+
import './ScrollUpButton.css'
3+
import scrollUp from "./scroll-up.svg";
4+
5+
export default function ScrollUpButton() {
6+
const [currentYPos,setCurrentYPos] = useState(window.pageYOffset);
7+
const offsetHeight = window.innerHeight - 80
8+
useEffect(()=>{
9+
function updatePosition(){
10+
setCurrentYPos(window.pageYOffset);
11+
}
12+
window.addEventListener('scroll', updatePosition);
13+
updatePosition();
14+
return () => window.removeEventListener('scroll', updatePosition);
15+
},[])
16+
17+
const scrollUpFn = ()=> window.scrollTo({ top: 0, left: 0, behavior: "smooth" });
18+
return (
19+
currentYPos >= offsetHeight ? <div className="Scroll-Up-Wrapper">
20+
<img className="Scroll-Up"
21+
onClick={scrollUpFn}
22+
src={scrollUp} alt="Scroll Up!" width="64" height="64" />
23+
</div>:<></>
24+
)
25+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import renderer from 'react-test-renderer';
3+
import ScrollUpButton from './ScrollUpButton';
4+
5+
6+
it('renders a project card', () => {
7+
const tree = renderer.create(
8+
<ScrollUpButton />
9+
).toJSON();
10+
expect(tree).toMatchSnapshot();
11+
});
12+
Lines changed: 8 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)