|
| 1 | +'use client'; |
| 2 | +import { Fragment } from 'react'; |
| 3 | +import { Disclosure, Menu, Transition } from '@headlessui/react'; |
| 4 | +import { Bars3Icon, BellIcon, XMarkIcon } from '@heroicons/react/24/outline'; |
| 5 | +import { ThemeToggle } from './theme-toggle'; |
| 6 | + |
| 7 | +const navigation = [ |
| 8 | + { name: 'Home', href: '#', current: true }, |
| 9 | + { name: 'About Me', href: '#', current: false }, |
| 10 | + { name: 'My Works', href: '#', current: false }, |
| 11 | + { name: 'Contact Me', href: '#', current: false }, |
| 12 | +]; |
| 13 | + |
| 14 | +function classNames(...classes: (string | undefined | null | false)[]): string { |
| 15 | + return classes.filter(Boolean).join(' '); |
| 16 | +} |
| 17 | + |
| 18 | +export default function Navbar() { |
| 19 | + return ( |
| 20 | + <Disclosure as="nav" className=""> |
| 21 | + {({ open }) => ( |
| 22 | + <> |
| 23 | + <div className="mx-auto max-w-7xl px-2 sm:px-6 lg:px-8"> |
| 24 | + <div className="relative flex h-16 items-center justify-between"> |
| 25 | + <div className="absolute inset-y-0 left-0 flex items-center sm:hidden"> |
| 26 | + {/* Mobile menu button*/} |
| 27 | + <Disclosure.Button className="relative inline-flex items-center justify-center rounded-md p-2 text-gray-400 hover:bg-gray-700 hover:text-white focus:outline-none focus:ring-2 focus:ring-inset focus:ring-white"> |
| 28 | + <span className="absolute -inset-0.5" /> |
| 29 | + <span className="sr-only">Open main menu</span> |
| 30 | + {open ? ( |
| 31 | + <XMarkIcon className="block h-6 w-6" aria-hidden="true" /> |
| 32 | + ) : ( |
| 33 | + <Bars3Icon className="block h-6 w-6" aria-hidden="true" /> |
| 34 | + )} |
| 35 | + </Disclosure.Button> |
| 36 | + </div> |
| 37 | + <div className="flex flex-1 items-center justify-center sm:items-stretch sm:justify-start"> |
| 38 | + <div className="flex flex-shrink-0 items-center"> |
| 39 | + <h1 className="">Mark.Z</h1> |
| 40 | + </div> |
| 41 | + <div className="hidden sm:ml-6 sm:block"> |
| 42 | + <div className="flex space-x-4"> |
| 43 | + {navigation.map(item => ( |
| 44 | + <a |
| 45 | + key={item.name} |
| 46 | + href={item.href} |
| 47 | + className={classNames( |
| 48 | + item.current |
| 49 | + ? 'bg-gray-900 text-white' |
| 50 | + : 'text-gray-300 hover:bg-gray-700 hover:text-white', |
| 51 | + 'rounded-md px-3 py-2 text-sm font-medium' |
| 52 | + )} |
| 53 | + aria-current={item.current ? 'page' : undefined} |
| 54 | + > |
| 55 | + {item.name} |
| 56 | + </a> |
| 57 | + ))} |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + <div className="absolute inset-y-0 right-0 flex items-center pr-2 sm:static sm:inset-auto sm:ml-6 sm:pr-0"> |
| 62 | + <Menu as="div" className="relative ml-3"> |
| 63 | + <div> |
| 64 | + <ThemeToggle /> |
| 65 | + </div> |
| 66 | + <Transition |
| 67 | + as={Fragment} |
| 68 | + enter="transition ease-out duration-100" |
| 69 | + enterFrom="transform opacity-0 scale-95" |
| 70 | + enterTo="transform opacity-100 scale-100" |
| 71 | + leave="transition ease-in duration-75" |
| 72 | + leaveFrom="transform opacity-100 scale-100" |
| 73 | + leaveTo="transform opacity-0 scale-95" |
| 74 | + > |
| 75 | + <Menu.Items className="absolute right-0 z-10 mt-2 w-48 origin-top-right rounded-md bg-white py-1 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"> |
| 76 | + <Menu.Item> |
| 77 | + {({ active }) => ( |
| 78 | + <a |
| 79 | + href="#" |
| 80 | + className={classNames( |
| 81 | + active ? 'bg-gray-100' : '', |
| 82 | + 'block px-4 py-2 text-sm text-gray-700' |
| 83 | + )} |
| 84 | + > |
| 85 | + Your Profile |
| 86 | + </a> |
| 87 | + )} |
| 88 | + </Menu.Item> |
| 89 | + <Menu.Item> |
| 90 | + {({ active }) => ( |
| 91 | + <a |
| 92 | + href="#" |
| 93 | + className={classNames( |
| 94 | + active ? 'bg-gray-100' : '', |
| 95 | + 'block px-4 py-2 text-sm text-gray-700' |
| 96 | + )} |
| 97 | + > |
| 98 | + Settings |
| 99 | + </a> |
| 100 | + )} |
| 101 | + </Menu.Item> |
| 102 | + <Menu.Item> |
| 103 | + {({ active }) => ( |
| 104 | + <a |
| 105 | + href="#" |
| 106 | + className={classNames( |
| 107 | + active ? 'bg-gray-100' : '', |
| 108 | + 'block px-4 py-2 text-sm text-gray-700' |
| 109 | + )} |
| 110 | + > |
| 111 | + Sign out |
| 112 | + </a> |
| 113 | + )} |
| 114 | + </Menu.Item> |
| 115 | + </Menu.Items> |
| 116 | + </Transition> |
| 117 | + </Menu> |
| 118 | + </div> |
| 119 | + </div> |
| 120 | + </div> |
| 121 | + |
| 122 | + <Disclosure.Panel className="sm:hidden"> |
| 123 | + <div className="space-y-1 px-2 pb-3 pt-2"> |
| 124 | + {navigation.map(item => ( |
| 125 | + <Disclosure.Button |
| 126 | + key={item.name} |
| 127 | + as="a" |
| 128 | + href={item.href} |
| 129 | + className={classNames( |
| 130 | + item.current |
| 131 | + ? 'bg-gray-900 text-white' |
| 132 | + : 'text-gray-300 hover:bg-gray-700 hover:text-white', |
| 133 | + 'block rounded-md px-3 py-2 text-base font-medium' |
| 134 | + )} |
| 135 | + aria-current={item.current ? 'page' : undefined} |
| 136 | + > |
| 137 | + {item.name} |
| 138 | + </Disclosure.Button> |
| 139 | + ))} |
| 140 | + </div> |
| 141 | + </Disclosure.Panel> |
| 142 | + </> |
| 143 | + )} |
| 144 | + </Disclosure> |
| 145 | + ); |
| 146 | +} |
0 commit comments