From 223e164ce8639ac2079d39bb04d7d03f9634ffed Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Tue, 4 Jan 2022 12:50:31 +0100
Subject: chore: add a back to top link

---
 src/components/Footer/Footer.tsx | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

(limited to 'src/components/Footer/Footer.tsx')

diff --git a/src/components/Footer/Footer.tsx b/src/components/Footer/Footer.tsx
index 12d86ce..15a4660 100644
--- a/src/components/Footer/Footer.tsx
+++ b/src/components/Footer/Footer.tsx
@@ -1,12 +1,45 @@
+import { ButtonLink } from '@components/Buttons';
 import Copyright from '@components/Copyright/Copyright';
 import FooterNav from '@components/FooterNav/FooterNav';
+import { ArrowIcon } from '@components/Icons';
+import { t } from '@lingui/macro';
+import { useEffect, useState } from 'react';
 import styles from './Footer.module.scss';
 
 const Footer = () => {
+  const [backToTopClasses, setBackToTopClasses] = useState(
+    `${styles['back-to-top']} ${styles['back-to-top--hidden']}`
+  );
+
+  const handleScroll = () => {
+    const currentScrollY = window.scrollY;
+
+    if (currentScrollY > 300) {
+      setBackToTopClasses(
+        `${styles['back-to-top']} ${styles['back-to-top--visible']}`
+      );
+    } else {
+      setBackToTopClasses(
+        `${styles['back-to-top']} ${styles['back-to-top--hidden']}`
+      );
+    }
+  };
+
+  useEffect(() => {
+    window.addEventListener('scroll', handleScroll);
+    return () => window.removeEventListener('scroll', handleScroll);
+  }, []);
+
   return (
     <footer className={styles.wrapper}>
       <Copyright />
       <FooterNav />
+      <div className={backToTopClasses}>
+        <ButtonLink target="#top" position="center">
+          <span className="screen-reader-text">{t`Back to top`}</span>
+          <ArrowIcon direction="top" />
+        </ButtonLink>
+      </div>
     </footer>
   );
 };
-- 
cgit v1.2.3

