diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-12-13 22:04:03 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-12-13 22:04:26 +0100 |
| commit | aec575c3b5797069e4964cfafa26e3de3b92f99e (patch) | |
| tree | ca58b4e85b4f0d3eb78b57cfa58aa9bad9fd4c2f /src/components/MainNav/MainNav.tsx | |
| parent | 5bc55ac0a801cbe82c41a10f7e680612be4deaf8 (diff) | |
chore: add main-nav component
I choose to implement main-nav paths manually instead of fetching
them from GraphQL to ensure functional navigation without JS.
Diffstat (limited to 'src/components/MainNav/MainNav.tsx')
| -rw-r--r-- | src/components/MainNav/MainNav.tsx | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/components/MainNav/MainNav.tsx b/src/components/MainNav/MainNav.tsx new file mode 100644 index 0000000..3140e64 --- /dev/null +++ b/src/components/MainNav/MainNav.tsx @@ -0,0 +1,71 @@ +import { useState } from 'react'; +import Link from 'next/link'; +import { t } from '@lingui/macro'; +import { HamburgerIcon } from '@components/Icons'; +import { mainNav } from '@config/nav'; +import ArticlesIcon from '@assets/images/icon-articles.svg'; +import ContactIcon from '@assets/images/icon-contact.svg'; +import CVIcon from '@assets/images/icon-cv.svg'; +import HomeIcon from '@assets/images/icon-home.svg'; +import styles from './MainNav.module.scss'; + +const MainNav = () => { + const [isChecked, setIsChecked] = useState<boolean>(false); + + const getIcon = (id: string) => { + switch (id) { + case 'home': + return <HomeIcon />; + case 'blog': + return <ArticlesIcon />; + case 'contact': + return <ContactIcon />; + case 'cv': + return <CVIcon />; + default: + break; + } + }; + + const navItems = mainNav.map((item) => { + return ( + <li key={item.id} className={styles.item}> + <Link href={item.slug}> + <a className={styles.link}> + <span className={styles.icon}>{getIcon(item.id)}</span> + <span>{item.name}</span> + </a> + </Link> + </li> + ); + }); + + return ( + <div className={styles.wrapper}> + <input + type="checkbox" + name="main-nav__checkbox" + id="main-nav__checkbox" + aria-labelledby="main-nav-toggle" + className={styles.checkbox} + checked={isChecked} + onChange={() => setIsChecked(!isChecked)} + /> + <label + htmlFor="main-nav__checkbox" + id="main-nav-toggle" + className={styles.label} + > + <HamburgerIcon isActive={isChecked} /> + <span className="screen-reader-text"> + {isChecked ? t`Close menu` : t`Open menu`} + </span> + </label> + <nav className={styles.nav}> + <ul className={styles.list}>{navItems}</ul> + </nav> + </div> + ); +}; + +export default MainNav; |
