summaryrefslogtreecommitdiffstats
path: root/src/components/Footer/Footer.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-01-04 12:50:31 +0100
committerArmand Philippot <git@armandphilippot.com>2022-01-04 12:52:57 +0100
commit223e164ce8639ac2079d39bb04d7d03f9634ffed (patch)
treeca78c53b17beaf5cad9e7b727b20c3e03c2391f5 /src/components/Footer/Footer.tsx
parente145ef983e64ba1ab0ffacf0e3e9eae94db1d8e4 (diff)
chore: add a back to top link
Diffstat (limited to 'src/components/Footer/Footer.tsx')
-rw-r--r--src/components/Footer/Footer.tsx33
1 files changed, 33 insertions, 0 deletions
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>
);
};