2021-09-27 12:17:33 +02:00
|
|
|
import React, { Fragment } from 'react';
|
|
|
|
import { Disclosure, Menu, Transition } from '@headlessui/react';
|
|
|
|
import { MenuIcon, XIcon } from '@heroicons/react/outline';
|
|
|
|
import { useAuth } from 'src/services/auth';
|
2022-02-09 09:03:44 +00:00
|
|
|
import Gravatar from 'react-gravatar';
|
|
|
|
import { Link, useLocation } from 'react-router-dom';
|
|
|
|
import clsx from 'clsx';
|
2021-09-27 12:17:33 +02:00
|
|
|
|
|
|
|
const navigation = [
|
|
|
|
{ name: 'Dashboard', to: '/dashboard' },
|
|
|
|
{ name: 'Users', to: '/users' },
|
|
|
|
];
|
|
|
|
|
|
|
|
function classNames(...classes: any[]) {
|
|
|
|
return classes.filter(Boolean).join(' ');
|
|
|
|
}
|
|
|
|
|
2022-02-09 09:03:44 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
|
|
interface HeaderProps {}
|
2021-09-27 12:17:33 +02:00
|
|
|
|
|
|
|
const Header: React.FC<HeaderProps> = () => {
|
|
|
|
const { logOut } = useAuth();
|
|
|
|
|
2022-02-09 09:03:44 +00:00
|
|
|
const { pathname } = useLocation();
|
|
|
|
|
2021-09-27 12:17:33 +02:00
|
|
|
return (
|
2022-02-09 09:03:44 +00:00
|
|
|
<Disclosure as="nav" className="bg-white shadow relative z-10">
|
2021-09-27 12:17:33 +02:00
|
|
|
{({ open }) => (
|
2022-02-09 09:03:44 +00:00
|
|
|
<div className="relative">
|
2021-09-27 12:17:33 +02:00
|
|
|
<div className="max-w-7xl mx-auto px-2 sm:px-6 lg:px-8">
|
|
|
|
<div className="relative flex justify-between h-16">
|
|
|
|
<div className="absolute inset-y-0 left-0 flex items-center sm:hidden">
|
|
|
|
{/* Mobile menu button */}
|
|
|
|
<Disclosure.Button className="inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-primary-500">
|
|
|
|
<span className="sr-only">Open main menu</span>
|
|
|
|
{open ? (
|
|
|
|
<XIcon className="block h-6 w-6" aria-hidden="true" />
|
|
|
|
) : (
|
|
|
|
<MenuIcon className="block h-6 w-6" aria-hidden="true" />
|
|
|
|
)}
|
|
|
|
</Disclosure.Button>
|
|
|
|
</div>
|
|
|
|
<div className="flex-1 flex items-center justify-center sm:items-stretch sm:justify-start">
|
|
|
|
<div className="flex-shrink-0 flex items-center">
|
|
|
|
<img className="block lg:hidden" src="/assets/logo-small.svg" alt="Stackspin" />
|
|
|
|
<img className="hidden lg:block" src="/assets/logo.svg" alt="Stackspin" />
|
|
|
|
</div>
|
|
|
|
<div className="hidden sm:ml-6 sm:flex sm:space-x-8">
|
|
|
|
{/* Current: "border-primary-500 text-gray-900", Default: "border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700" */}
|
|
|
|
{navigation.map((item) => (
|
|
|
|
<Link
|
|
|
|
key={item.name}
|
|
|
|
to={item.to}
|
2022-02-09 09:03:44 +00:00
|
|
|
className={clsx(
|
|
|
|
'border-primary-50 text-gray-900 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium',
|
|
|
|
{
|
|
|
|
'border-primary-500 text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 text-sm font-medium':
|
|
|
|
pathname.includes(item.to),
|
|
|
|
},
|
|
|
|
)}
|
2021-09-27 12:17:33 +02:00
|
|
|
>
|
|
|
|
{item.name}
|
|
|
|
</Link>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="absolute inset-y-0 right-0 flex items-center pr-2 sm:static sm:inset-auto sm:ml-6 sm:pr-0">
|
|
|
|
{/* Profile dropdown */}
|
|
|
|
<Menu as="div" className="ml-3 relative">
|
|
|
|
<div>
|
|
|
|
<Menu.Button className="bg-white rounded-full flex text-sm focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary">
|
|
|
|
<span className="sr-only">Open user menu</span>
|
2022-02-09 09:03:44 +00:00
|
|
|
<span className="inline-flex items-center justify-center h-8 w-8 rounded-full bg-gray-500 overflow-hidden">
|
|
|
|
<Gravatar email="" size={32} rating="pg" protocol="https://" />
|
|
|
|
</span>
|
2021-09-27 12:17:33 +02:00
|
|
|
</Menu.Button>
|
|
|
|
</div>
|
|
|
|
<Transition
|
|
|
|
as={Fragment}
|
|
|
|
enter="transition ease-out duration-200"
|
|
|
|
enterFrom="transform opacity-0 scale-95"
|
|
|
|
enterTo="transform opacity-100 scale-100"
|
|
|
|
leave="transition ease-in duration-75"
|
|
|
|
leaveFrom="transform opacity-100 scale-100"
|
|
|
|
leaveTo="transform opacity-0 scale-95"
|
|
|
|
>
|
|
|
|
<Menu.Items className="origin-top-right absolute right-0 mt-2 w-48 rounded-md shadow-lg py-1 bg-white ring-1 ring-black ring-opacity-5 focus:outline-none">
|
|
|
|
<Menu.Item>
|
|
|
|
{({ active }) => (
|
|
|
|
<a
|
|
|
|
onClick={() => logOut()}
|
2022-02-09 09:03:44 +00:00
|
|
|
className={classNames(
|
|
|
|
active ? 'bg-gray-100 cursor-pointer' : '',
|
|
|
|
'block px-4 py-2 text-sm text-gray-700 cursor-pointer',
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
Configure profile
|
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item>
|
|
|
|
{({ active }) => (
|
|
|
|
<a
|
|
|
|
onClick={() => logOut()}
|
|
|
|
className={classNames(
|
|
|
|
active ? 'bg-gray-100 cursor-pointer' : '',
|
|
|
|
'block px-4 py-2 text-sm text-gray-700 cursor-pointer',
|
|
|
|
)}
|
2021-09-27 12:17:33 +02:00
|
|
|
>
|
|
|
|
Sign out
|
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</Menu.Item>
|
|
|
|
</Menu.Items>
|
|
|
|
</Transition>
|
|
|
|
</Menu>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Disclosure.Panel className="sm:hidden">
|
|
|
|
<div className="pt-2 pb-4 space-y-1">
|
|
|
|
{navigation.map((item) => (
|
|
|
|
<Link
|
|
|
|
key={item.name}
|
|
|
|
to={item.to}
|
2022-02-09 09:03:44 +00:00
|
|
|
// getProps={({ isCurrent }) => {
|
|
|
|
// // the object returned here is passed to the
|
|
|
|
// // anchor element's props
|
|
|
|
// return {
|
|
|
|
// className: isCurrent
|
|
|
|
// ? 'bg-primary-50 border-primary-400 text-primary-700 block pl-3 pr-4 py-2 border-l-4 text-base font-medium'
|
|
|
|
// : 'border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700 block pl-3 pr-4 py-2 border-l-4 text-base font-medium',
|
|
|
|
// 'aria-current': isCurrent ? 'page' : undefined,
|
|
|
|
// };
|
|
|
|
// }}
|
2021-09-27 12:17:33 +02:00
|
|
|
>
|
|
|
|
{item.name}
|
|
|
|
</Link>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</Disclosure.Panel>
|
2022-02-09 09:03:44 +00:00
|
|
|
</div>
|
2021-09-27 12:17:33 +02:00
|
|
|
)}
|
|
|
|
</Disclosure>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Header;
|