jonbio/components/MobileNav.tsx

79 lines
2.5 KiB
TypeScript
Raw Normal View History

2023-07-07 11:17:22 +08:00
'use client'
2024-06-19 14:32:32 -07:00
import { Dialog, Transition } from '@headlessui/react'
import { Fragment, useState } from 'react'
2021-01-09 17:50:45 +08:00
import Link from './Link'
import headerNavLinks from '@/data/headerNavLinks'
const MobileNav = () => {
const [navShow, setNavShow] = useState(false)
const onToggleNav = () => {
setNavShow((status) => {
if (status) {
document.body.style.overflow = 'auto'
} else {
// Prevent scrolling
document.body.style.overflow = 'hidden'
}
return !status
})
}
return (
2023-07-30 17:20:28 +08:00
<>
<button aria-label="Toggle Menu" onClick={onToggleNav} className="sm:hidden">
2021-01-09 17:50:45 +08:00
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
className="h-8 w-8 text-gray-900 dark:text-gray-100"
2021-01-09 17:50:45 +08:00
>
2022-05-28 21:31:43 +05:30
<path
fillRule="evenodd"
d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 15a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1z"
clipRule="evenodd"
/>
2021-01-09 17:50:45 +08:00
</svg>
</button>
<div
className={`fixed left-0 top-0 z-10 h-full w-full transform bg-white opacity-95 duration-300 ease-in-out dark:bg-gray-950 dark:opacity-[0.98] ${
navShow ? 'translate-x-0' : 'hidden translate-x-full'
2021-01-09 17:50:45 +08:00
}`}
>
2022-05-28 21:31:43 +05:30
<div className="flex justify-end">
2023-07-30 17:20:28 +08:00
<button className="mr-8 mt-11 h-8 w-8" aria-label="Toggle Menu" onClick={onToggleNav}>
2022-05-28 21:31:43 +05:30
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
className="text-gray-900 dark:text-gray-100"
>
<path
fillRule="evenodd"
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
clipRule="evenodd"
/>
</svg>
</button>
</div>
2022-01-31 23:58:10 +08:00
<nav className="fixed mt-8 h-full">
2021-01-09 17:50:45 +08:00
{headerNavLinks.map((link) => (
2021-01-12 23:35:36 +08:00
<div key={link.title} className="px-12 py-4">
2021-01-09 17:50:45 +08:00
<Link
href={link.href}
className="text-2xl font-bold tracking-widest text-gray-900 dark:text-gray-100"
onClick={onToggleNav}
>
{link.title}
</Link>
</div>
))}
</nav>
</div>
2023-07-30 17:20:28 +08:00
</>
2021-01-09 17:50:45 +08:00
)
}
export default MobileNav