-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
edc6831
commit 82f2ed0
Showing
7 changed files
with
255 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { stylesConfig } from "@/utils/functions"; | ||
import styles from "./styles.module.scss"; | ||
import navLinks from "@/constants/navigation"; | ||
import Link from "next/link"; | ||
|
||
interface NavigationProps extends React.HTMLAttributes<HTMLElement> { | ||
theme?: "light" | "dark"; | ||
} | ||
|
||
const classes = stylesConfig(styles, "navigation"); | ||
|
||
const Navigation: React.FC<NavigationProps> = ({ theme = "light" }) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const [isClosing, setIsClosing] = useState(false); | ||
|
||
const midIndex = Math.floor(navLinks.length / 2) + 1; | ||
|
||
useEffect(() => { | ||
const handleKeyDown = (e: KeyboardEvent) => { | ||
if (e.key === "Escape") { | ||
setIsClosing(true); | ||
setTimeout(() => { | ||
setIsOpen(false); | ||
setIsClosing(false); | ||
}, 250); | ||
} | ||
}; | ||
|
||
if (isOpen) document.addEventListener("keydown", handleKeyDown); | ||
else document.removeEventListener("keydown", handleKeyDown); | ||
|
||
return () => document.removeEventListener("keydown", handleKeyDown); | ||
}, [isOpen]); | ||
|
||
return ( | ||
<> | ||
<button | ||
className={classes("-btn", `-btn-${theme}`, { | ||
"-btn--open": isOpen, | ||
})} | ||
onClick={() => { | ||
if (isOpen) { | ||
setIsClosing(true); | ||
setTimeout(() => { | ||
setIsOpen(false); | ||
setIsClosing(false); | ||
}, 250); | ||
} else setIsOpen(true); | ||
}} | ||
> | ||
<span /> | ||
</button> | ||
{isOpen ? ( | ||
<nav | ||
className={classes("-nav", `-nav-${theme}`, { | ||
"-nav--closing": isClosing, | ||
})} | ||
> | ||
<div className={classes("-nav-left")}> | ||
{navLinks.slice(0, midIndex).map((link, index) => ( | ||
<Link | ||
href={link.path} | ||
className={classes("-link")} | ||
key={index} | ||
data-index={`0${index + 1}`} | ||
> | ||
{link.label} | ||
</Link> | ||
))} | ||
</div> | ||
<div className={classes("-nav-right")}> | ||
{navLinks | ||
.slice(midIndex, navLinks.length) | ||
.map((link, index) => ( | ||
<Link | ||
href={link.path} | ||
className={classes("-link")} | ||
key={index} | ||
data-index={`0${index + midIndex + 1}`} | ||
> | ||
{link.label} | ||
</Link> | ||
))} | ||
</div> | ||
</nav> | ||
) : null} | ||
</> | ||
); | ||
}; | ||
|
||
export default Navigation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
@import "@/styles/config/mixins"; | ||
@import "@/styles/config/animations"; | ||
|
||
.navigation { | ||
&-btn { | ||
@include init-button; | ||
position: fixed; | ||
top: 56px; | ||
right: 56px; | ||
z-index: 100; | ||
width: 48px; | ||
height: 48px; | ||
|
||
span { | ||
width: 48px; | ||
height: 1px; | ||
background-color: var(--color-white); | ||
position: relative; | ||
|
||
&::before, | ||
&::after { | ||
content: ""; | ||
position: absolute; | ||
left: 0; | ||
width: 100%; | ||
height: 1px; | ||
background-color: var(--color-white); | ||
} | ||
|
||
&::before { | ||
transform: translateY(-12px); | ||
} | ||
|
||
&::after { | ||
transform: translateY(12px); | ||
} | ||
} | ||
|
||
&--open { | ||
span { | ||
background-color: transparent; | ||
|
||
&::before { | ||
transform: translateY(0.5px) rotate(45deg); | ||
} | ||
|
||
&::after { | ||
transform: translateY(-0.5px) rotate(-45deg); | ||
} | ||
} | ||
} | ||
} | ||
|
||
&-nav { | ||
width: 100%; | ||
height: 100vh; | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
z-index: 99; | ||
background-color: var(--theme-indigo); | ||
transition: transform 0.3s ease-in-out; | ||
display: flex; | ||
justify-content: flex-start; | ||
align-items: center; | ||
padding: 96px; | ||
animation: fade-bottom-in 0.4s ease-in-out; | ||
|
||
@include responsive(phone) { | ||
padding: 48px; | ||
flex-direction: column; | ||
gap: 16px; | ||
justify-content: center; | ||
} | ||
|
||
&-left, | ||
&-right { | ||
width: 50%; | ||
height: 100%; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
flex-direction: column; | ||
gap: 16px; | ||
padding: 0 5%; | ||
|
||
@include responsive(phone) { | ||
width: 100%; | ||
height: auto; | ||
padding: 0 32px; | ||
justify-content: center; | ||
} | ||
|
||
a { | ||
width: 100%; | ||
@include font( | ||
var(--font-red-hat-display), | ||
36px, | ||
400, | ||
150%, | ||
var(--color-white) | ||
); | ||
text-decoration: none; | ||
position: relative; | ||
|
||
&::before { | ||
content: attr(data-index); | ||
position: absolute; | ||
left: -80px; | ||
top: 50%; | ||
transform: translateY(-50%) rotate(-90deg); | ||
font-size: 16px; | ||
color: var(--color-white); | ||
|
||
@include responsive(phone) { | ||
left: -40px; | ||
} | ||
} | ||
|
||
&::after { | ||
content: ""; | ||
position: absolute; | ||
bottom: -4px; | ||
left: 0; | ||
width: 0; | ||
height: 1px; | ||
background-color: var(--theme-navy); | ||
} | ||
|
||
&:hover, | ||
&:focus, | ||
&:active { | ||
border: none; | ||
outline: none; | ||
color: var(--theme-navy); | ||
|
||
&::after { | ||
width: 70%; | ||
} | ||
} | ||
} | ||
} | ||
|
||
&--closing { | ||
animation: fade-bottom-out 0.4s ease-in-out; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters