import Icon from "./icons"; import { Disclosure, Menu, Transition } from "@headlessui/react"; import { XMarkIcon, Bars3Icon, BellIcon, MoonIcon, SunIcon, } from "@heroicons/react/24/outline"; import { Fragment } from "react"; import { appContext } from "../hooks/provider"; import { Link } from "gatsby"; import React from "react"; function classNames(...classes: string[]) { return classes.filter(Boolean).join(" "); } const Header = ({ meta, link }: any) => { const { user, logout } = React.useContext(appContext); const userName = user ? user.name : "Unknown"; const userAvatarUrl = user ? user.avatar_url : ""; const user_id = user ? user.username : "unknown"; const links: any[] = [ { name: "Build", href: "/build" }, { name: "Playground", href: "/" }, // { name: "Gallery", href: "/gallery" }, // { name: "Data Explorer", href: "/explorer" }, ]; const DarkModeToggle = () => { return ( {(context: any) => { return ( ); }} ); }; return ( {({ open }) => ( <>
{" "}
{" "}
{meta.title}
{meta.description}
{/* Current: "border-accent text-gray-900", Default: "border-transparent text-secondary hover:border-gray-300 hover:text-primary" */} {links.map((data, index) => { const isActive = data.href === link; const activeClass = isActive ? "bg-accent " : "bg-secondary "; return (
{data.name}
); })}
{/* Mobile menu button */} Open main menu {open ? (
{
{user && ( <>
{userName}
{user_id}
{/* Profile dropdown */}
Open user menu {userAvatarUrl && ( )} {!userAvatarUrl && userName && (
{userName[0]}
)}
{/* {({ active }) => ( Your Profile )} */} {({ active }) => ( { logout(); }} className={classNames( active ? "bg-secondary" : "", "block px-4 py-2 text-sm text-primary" )} > Sign out )}
)}
}
{/* Current: "bg-indigo-50 border-accent text-accent", Default: "border-transparent text-gray-600 hover:bg-primary hover:border-gray-300 hover:text-primary" */} {links.map((data, index) => { return ( {data.name} ); })}
{" "} Dark mode {" "}
{user && (
{userAvatarUrl && ( )} {!userAvatarUrl && userName && (
{userName[0]}
)}
{userName}
{user_id}
logout()} className="block px-4 py-2 text-base font-medium text-secondary hover:text-primary " > Sign out
)}
)}
); }; export default Header;