aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Footer/Footer.tsx
blob: 15a4660102873abf4b1cbce4a9efa5e53c369bf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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>
  );
};

export default Footer;