1
+ import { ReactNode , useState } from "react" ;
1
2
import { useRouter } from "next/router" ;
2
- import React , { ReactNode } from "react" ;
3
- import { twMerge } from "tailwind-merge" ;
3
+ import Bars3Icon from "@heroicons/ react/24/solid/Bars3Icon " ;
4
+
4
5
import Link from "./Link" ;
6
+ import Button from "../controls/Button" ;
5
7
6
8
export interface HeaderProps {
7
9
@@ -11,26 +13,42 @@ const NavLink = ({ href, currentHref, children }: {
11
13
href : string ,
12
14
currentHref : string ,
13
15
children : ReactNode ;
14
- } ) => (
15
- < Link color = "primary" className = { "text-lg font-bold" + ( currentHref === href ? " text-primary-dark" : "" ) } href = { href } >
16
- { children }
17
- </ Link >
18
- ) ;
16
+ } ) => {
17
+ const active = currentHref === href ;
18
+
19
+ return (
20
+ < Link
21
+ className = "text-lg font-bold py-2 border-y border-primary hover:border-primary-light aria-[current='page']:text-primary-dark aria-[current='page']:border-primary first-of-type:border-t-2 last-of-type:border-b-2 md:border-0 md:first-of-type:border-t-0 md:last-of-type:border-b-0"
22
+ aria-current = { active ? "page" : undefined }
23
+ color = "primary"
24
+ href = { href }
25
+ >
26
+ { children }
27
+ </ Link >
28
+ ) ;
29
+ } ;
19
30
20
31
const Header = ( { } : HeaderProps ) => {
21
32
const router = useRouter ( ) ;
22
33
34
+ const [ open , setOpen ] = useState ( false ) ;
35
+
23
36
return (
24
- < header className = "flex items-center w-full gap-12 px-8 py-4" >
25
- < Link color = "primary" className = { "text-4xl font-bold" } href = "/" >
37
+ < header className = "relative flex items-center w-full gap-12 px-8 py-4" >
38
+ < Link color = "primary" className = "text-2xl font-bold lg:text-4xl" href = "/" >
26
39
Commit Rocket
27
40
</ Link >
28
- < NavLink href = "/" currentHref = { router . asPath } >
29
- Home
30
- </ NavLink >
31
- < NavLink href = "/about" currentHref = { router . asPath } >
32
- About
33
- </ NavLink >
41
+ < Button color = "secondary" className = "p-2 ml-auto rounded-full md:hidden" onClick = { ( ) => setOpen ( ! open ) } >
42
+ < Bars3Icon className = "w-6 h-6" />
43
+ </ Button >
44
+ < div aria-expanded = { open } className = "absolute flex flex-col bg-fill gap-0 p-4 top-full inset-x-4 rounded-md shadow shadow-primary z-10 aria-[expanded='false']:hidden md:aria-[expanded='false']:flex md:flex-row md:items-center md:p-0 md:shadow-none md:static md:bg-transparent md:gap-12" >
45
+ < NavLink href = "/" currentHref = { router . asPath } >
46
+ Home
47
+ </ NavLink >
48
+ < NavLink href = "/about" currentHref = { router . asPath } >
49
+ About
50
+ </ NavLink >
51
+ </ div >
34
52
</ header >
35
53
) ;
36
54
} ;
0 commit comments