mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
add hamburger for mobile
This commit is contained in:
@@ -1,17 +1,47 @@
|
||||
import { useState } from 'react'
|
||||
import Head from 'next/head'
|
||||
import Link from 'next/link'
|
||||
import { useRouter } from 'next/router'
|
||||
import User from './user'
|
||||
|
||||
const NAV_ENTRIES = [
|
||||
{
|
||||
label: 'Home',
|
||||
href: '/',
|
||||
},
|
||||
{
|
||||
label: 'Buchungsanfrage',
|
||||
href: '/book',
|
||||
},
|
||||
{
|
||||
label: 'Preise',
|
||||
href: '/prices',
|
||||
},
|
||||
{
|
||||
label: 'Mietbedingungen',
|
||||
href: '/terms',
|
||||
},
|
||||
]
|
||||
|
||||
export default function Header() {
|
||||
const router = useRouter()
|
||||
const [hamburgerOpen, setHamburgerOpen] = useState(false)
|
||||
|
||||
function changeRoute(event: React.PointerEvent<HTMLAnchorElement>) {
|
||||
event.preventDefault()
|
||||
setHamburgerOpen(false)
|
||||
router.push(event.currentTarget.href)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Pfadi-Bussle</title>
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
<div className="relative bg-white">
|
||||
<div className="">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6">
|
||||
<div className="flex justify-between items-center border-b-2 border-gray-100 py-6 md:justify-start md:space-x-10">
|
||||
<div className="relative flex justify-between items-center border-b-2 border-gray-100 py-6 md:justify-start md:space-x-10">
|
||||
<div className="flex justify-start lg:w-0 flex-1">
|
||||
<Link href="/">
|
||||
<a className="text-lg tracking-tight font-extrabold text-blue-800 sm:text-xl md:text-2xl">
|
||||
@@ -20,26 +50,26 @@ export default function Header() {
|
||||
</Link>
|
||||
</div>
|
||||
<nav className="hidden space-x-10 sm:flex">
|
||||
<Link href="/book">
|
||||
<a className="text-base font-medium text-gray-500 hover:text-gray-900">
|
||||
Buchungsanfrage
|
||||
</a>
|
||||
</Link>
|
||||
<Link href="/prices">
|
||||
<a className="text-base font-medium text-gray-500 hover:text-gray-900">
|
||||
Preise
|
||||
</a>
|
||||
</Link>
|
||||
<Link href="/terms">
|
||||
<a className="text-base font-medium text-gray-500 hover:text-gray-900">
|
||||
Mitbedingungen
|
||||
</a>
|
||||
</Link>
|
||||
{NAV_ENTRIES.map(({ label, href }) => {
|
||||
return (
|
||||
<a
|
||||
key={href}
|
||||
href={href}
|
||||
onClick={changeRoute}
|
||||
className="text-base font-medium text-gray-500 hover:text-gray-900"
|
||||
>
|
||||
{label}
|
||||
</a>
|
||||
)
|
||||
})}
|
||||
</nav>
|
||||
<nav className="sm:hidden">
|
||||
<nav
|
||||
onClick={() => setHamburgerOpen(!hamburgerOpen)}
|
||||
className="flex flex-col sm:hidden text-gray-500 hover:text-gray-900 cursor-pointer"
|
||||
>
|
||||
<svg
|
||||
className="w-5"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
@@ -51,6 +81,28 @@ export default function Header() {
|
||||
d="M4 6h16M4 12h16M4 18h16"
|
||||
/>
|
||||
</svg>
|
||||
<div
|
||||
className={`${
|
||||
hamburgerOpen || 'hidden'
|
||||
} absolute z-10 mt-5 transform right-0`}
|
||||
>
|
||||
<div className="rounded-lg shadow-lg ring-1 ring-black ring-opacity-5 overflow-hidden">
|
||||
<div className="relative grid gap-2 bg-white px-4 py-2">
|
||||
{NAV_ENTRIES.map(({ label, href }) => {
|
||||
return (
|
||||
<a
|
||||
key={href}
|
||||
href={href}
|
||||
onClick={changeRoute}
|
||||
className="text-base font-medium text-gray-500 hover:text-gray-900"
|
||||
>
|
||||
{label}
|
||||
</a>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<User />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user