generated from theodorusclarence/ts-nextjs-tailwind-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
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
cc5deaf
commit ef5b359
Showing
10 changed files
with
400 additions
and
39 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
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,22 @@ | ||
import classNames from 'classnames'; | ||
|
||
export interface BurgerIconProps { | ||
isOpen: boolean; | ||
} | ||
|
||
const BurgerIcon = ({ isOpen }: BurgerIconProps) => { | ||
return ( | ||
<div | ||
className={classNames('burger-icon', { | ||
open: isOpen, | ||
})} | ||
> | ||
<span /> | ||
<span /> | ||
<span /> | ||
<span /> | ||
</div> | ||
); | ||
}; | ||
|
||
export { BurgerIcon }; |
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 @@ | ||
export * from './BurgerIcon'; |
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,50 @@ | ||
'use client'; | ||
|
||
import classNames from 'classnames'; | ||
import { motion, Variants } from 'framer-motion'; | ||
import Link from 'next/link'; | ||
import { usePathname } from 'next/navigation'; | ||
|
||
export interface NavigationItemProps { | ||
href: string; | ||
title: string; | ||
variants: Variants; | ||
initial: string; | ||
animate: string; | ||
customDelay?: number; | ||
} | ||
|
||
const NavigationItem = ({ | ||
href, | ||
title, | ||
variants, | ||
initial, | ||
animate, | ||
customDelay, | ||
}: NavigationItemProps) => { | ||
const pathname = usePathname(); | ||
const isActive = pathname?.startsWith(href); | ||
|
||
return ( | ||
<motion.li | ||
variants={variants} | ||
initial={initial} | ||
animate={animate} | ||
custom={customDelay} | ||
> | ||
<Link | ||
href={href} | ||
className={classNames( | ||
isActive | ||
? 'text-off-black dark:text-off-white font-bold' | ||
: 'hover:text-off-black dark:hover:text-off-white font-medium text-slate-700 dark:text-slate-400 md:text-slate-500 md:dark:text-slate-400', | ||
'md:underlined relative block whitespace-nowrap text-2xl transition md:text-lg' | ||
)} | ||
> | ||
{title} | ||
</Link> | ||
</motion.li> | ||
); | ||
}; | ||
|
||
export { NavigationItem }; |
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,3 @@ | ||
'use client'; | ||
|
||
export * from './NavigationItem'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use client'; | ||
|
||
import FocusTrap from 'focus-trap-react'; | ||
import { AnimatePresence, motion } from 'framer-motion'; | ||
import * as React from 'react'; | ||
|
||
import { NavigationItem } from '@/components/atoms/NavigationItem'; | ||
import ModeToggleButton from '@/components/buttons/ModeToggleButton'; | ||
import { links } from '@/components/layout/Header'; | ||
|
||
export interface MobileMenuProps { | ||
isOpen: boolean; | ||
} | ||
|
||
export const MobileMenu = ({ isOpen }: MobileMenuProps) => { | ||
const navigationVariants = { | ||
hidden: { opacity: 0, x: -50 }, | ||
visible: (custom: number) => ({ | ||
opacity: 1, | ||
x: 0, | ||
transition: { delay: custom }, | ||
}), | ||
}; | ||
|
||
return ( | ||
<AnimatePresence> | ||
{isOpen ? ( | ||
<motion.div | ||
className='from-grey-200 dark:from-grey-900 fixed top-0 z-40 h-screen w-screen gap-12 bg-gradient-to-b to-transparent p-4 backdrop-blur-xl transition-all delay-100 duration-700 ease-in-out md:hidden' | ||
initial={{ opacity: 0, y: '-50%', x: 0 }} | ||
animate={{ opacity: 1, y: 0, x: 0 }} | ||
exit={{ opacity: 0, y: '-50%' }} | ||
transition={{ duration: 0, delay: 0 }} | ||
> | ||
<FocusTrap | ||
focusTrapOptions={{ | ||
clickOutsideDeactivates: true, | ||
}} | ||
> | ||
<ul className='align-center flex h-full flex-col justify-center gap-4 text-center'> | ||
{links.map(({ href, label }, i) => ( | ||
<NavigationItem | ||
key={href} | ||
href={href} | ||
title={label} | ||
variants={navigationVariants} | ||
initial='hidden' | ||
animate='visible' | ||
customDelay={0.5 + (i + 1) * 0.1} | ||
/> | ||
))} | ||
<motion.li | ||
className='mt-12 flex justify-center' | ||
variants={navigationVariants} | ||
initial='hidden' | ||
animate='visible' | ||
custom={0.5 + (links.length + 1) * 0.1} | ||
> | ||
<ModeToggleButton /> | ||
</motion.li> | ||
</ul> | ||
</FocusTrap> | ||
</motion.div> | ||
) : null} | ||
</AnimatePresence> | ||
); | ||
}; |
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,17 @@ | ||
import { useEffect } from 'react'; | ||
|
||
export const useOnKeyDown = ( | ||
key: KeyboardEvent['key'], | ||
handler: () => void | ||
) => { | ||
useEffect(() => { | ||
const callHandlerOnKeyDown = (e: KeyboardEvent) => { | ||
if (e.key === key) { | ||
handler(); | ||
} | ||
}; | ||
window.addEventListener('keydown', callHandlerOnKeyDown); | ||
|
||
return () => window.removeEventListener('keydown', callHandlerOnKeyDown); | ||
}, [handler, key]); | ||
}; |
Oops, something went wrong.