diff --git a/components/ScrollButton/ScrollButton.js b/components/ScrollButton/ScrollButton.js new file mode 100644 index 00000000..80f5158f --- /dev/null +++ b/components/ScrollButton/ScrollButton.js @@ -0,0 +1,45 @@ +import React, { useEffect, useState } from 'react'; +import Image from 'next/image'; + +function ScrollButton() { + const [backToTopButton, setBackToTopButton] = useState(false); + + useEffect(() => { + const handleScroll = () => { + if (window.scrollY > 150) { + setBackToTopButton(true); + } else { + setBackToTopButton(false); + } + }; + + window.addEventListener('scroll', handleScroll); + + // Clean up the event listener on component unmount + return () => { + window.removeEventListener('scroll', handleScroll); + }; + }, []); + + const scrollUp = () => { + window.scrollTo({ + top: 0, + behavior: 'smooth', + }); + }; + + return ( +
+ {backToTopButton && ( + + )} +
+ ); +} + +export default ScrollButton; diff --git a/pages/editions/index.js b/pages/editions/index.js index 4a09b2ba..1e10d6cd 100644 --- a/pages/editions/index.js +++ b/pages/editions/index.js @@ -1,6 +1,7 @@ import React from 'react' import PastEditonCard from '../../components/PastEditionCard' import pastEditionsArchiveLinks from '../../config/editions.json' +import ScrollButton from '../../components/ScrollButton/ScrollButton'; const PastEditions = () => { return (
@@ -19,6 +20,7 @@ const PastEditions = () => { }) }
+ ) } diff --git a/pages/index.js b/pages/index.js index 78c8de64..72756f7a 100644 --- a/pages/index.js +++ b/pages/index.js @@ -16,6 +16,7 @@ import speakers from '../config/speakers.json'; import Link from 'next/link'; import Button from '../components/Buttons/button'; import Dropdown from '../components/Dropdown/dropdown'; +import ScrollButton from '../components/ScrollButton/ScrollButton'; export default function Home() { const isTablet = useMediaQuery({ maxWidth: '1118px' }); @@ -192,6 +193,7 @@ export default function Home() {
+ ); } diff --git a/pages/venue/[id].js b/pages/venue/[id].js index a20dcdc5..0a29893b 100644 --- a/pages/venue/[id].js +++ b/pages/venue/[id].js @@ -10,6 +10,7 @@ import { isEventEnded } from '../../components/Venue/venue'; import Agenda from '../../components/Agenda/agenda'; import Guidelines from '../../components/Speaker/guideline'; import CFPdata from "../../config/cfp-data.json" +import ScrollButton from '../../components/ScrollButton/ScrollButton'; export async function getStaticProps({ params }) { let res = {}; const data = cities.filter((p) => p.name === params.id); @@ -95,6 +96,7 @@ function Venue({ city }) { > + ); } diff --git a/public/img/scroll.webp b/public/img/scroll.webp new file mode 100644 index 00000000..1a3d0fb6 Binary files /dev/null and b/public/img/scroll.webp differ