Files
xtreamium/frontend/src/components/header.component.tsx
2022-04-11 17:10:49 +01:00

157 lines
5.8 KiB
TypeScript

import React from "react";
import { VscDebug } from "react-icons/vsc";
import { BsFillMoonStarsFill, BsFillSunFill, BsSearch } from "react-icons/bs";
import { BiLogOutCircle, BiCog } from "react-icons/bi";
import { IoMdPerson } from "react-icons/io";
import { AiOutlineMenu, AiOutlineBell } from "react-icons/ai";
import { SidebarContext, ThemeContext } from "../context";
import { toast } from "react-toastify";
import { Avatar, Badge, Input, Dropdown, DropdownItem } from "./widgets";
const Header = () => {
const { toggleSidebar } = React.useContext(SidebarContext);
const { theme, toggleTheme } = React.useContext(ThemeContext);
const [isNotificationsMenuOpen, setIsNotificationsMenuOpen] =
React.useState(false);
const [isProfileMenuOpen, setIsProfileMenuOpen] = React.useState(false);
const _debuggles = () => {
toast("🦄 Wow so easy!", {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
});
};
const handleNotificationsClick = () => {
setIsNotificationsMenuOpen(!isNotificationsMenuOpen);
};
const handleProfileClick = () => {
setIsProfileMenuOpen(!isProfileMenuOpen);
};
return (
<header className="z-40 py-4 bg-white shadow-bottom dark:bg-gray-800">
<div className="container flex items-center justify-between h-full px-6 mx-auto text-purple-600 dark:text-purple-300">
<button
className="p-1 mr-5 -ml-1 rounded-md lg:hidden focus:outline-none focus:shadow-outline-purple"
onClick={toggleSidebar}
aria-label="Menu"
>
<AiOutlineMenu className="w-6 h-6" aria-hidden="true" />
</button>
<div className="flex justify-center flex-1 lg:mr-32">
<div className="relative w-full max-w-xl mr-6 focus-within:text-purple-500">
<div className="absolute inset-y-0 flex items-center pl-2">
<BsSearch className="w-4 h-4" aria-hidden="true" />
</div>
<Input
className="h-8 pl-8 text-gray-700"
placeholder="Search for channels"
aria-label="Search"
/>
</div>
</div>
<ul className="flex items-center flex-shrink-0 space-x-6">
<li className="flex">
<button
className="rounded-md focus:outline-none focus:shadow-outline-purple"
onClick={_debuggles}
aria-label="Toggle color mode"
>
<VscDebug className="w-4 h-4" aria-hidden="true" />
</button>
</li>
<li className="flex">
<button
className="rounded-md focus:outline-none focus:shadow-outline-purple"
onClick={toggleTheme}
aria-label="Toggle color mode"
>
{theme === "dark" ? (
<BsFillSunFill className="w-5 h-5" aria-hidden="true" />
) : (
<BsFillMoonStarsFill className="w-5 h-5" aria-hidden="true" />
)}
</button>
</li>
{/* <!-- Notifications menu --> */}
<li className="relative">
<button
className="relative align-middle rounded-md focus:outline-none focus:shadow-outline-purple"
onClick={handleNotificationsClick}
aria-label="Notifications"
aria-haspopup="true"
>
<AiOutlineBell className="w-5 h-5" aria-hidden="true" />
{/* <!-- Notification badge --> */}
<span
aria-hidden="true"
className="absolute top-0 right-0 inline-block w-3 h-3 transform translate-x-1 -translate-y-1 bg-red-600 border-2 border-white rounded-full dark:border-gray-800"
></span>
</button>
<Dropdown
align="right"
isOpen={isNotificationsMenuOpen}
onClose={() => setIsNotificationsMenuOpen(false)}
>
<DropdownItem tag="a" href="#" className="justify-between">
<span>Messages</span>
<Badge type="danger">13</Badge>
</DropdownItem>
<DropdownItem tag="a" href="#" className="justify-between">
<span>Sales</span>
<Badge type="danger">2</Badge>
</DropdownItem>
<DropdownItem onClick={() => alert("Alerts!")}>
<span>Alerts</span>
</DropdownItem>
</Dropdown>
</li>
{/* <!-- Profile menu --> */}
<li className="relative">
<button
className="rounded-full focus:shadow-outline-purple focus:outline-none"
onClick={handleProfileClick}
aria-label="Account"
aria-haspopup="true"
>
<Avatar
className="align-middle"
src="https://placebeard.it/32/32"
alt=""
aria-hidden="true"
/>
</button>
<Dropdown
align="right"
isOpen={isProfileMenuOpen}
onClose={() => setIsProfileMenuOpen(false)}
>
<DropdownItem tag="a" href="#">
<IoMdPerson className="w-4 h-4 mr-3" aria-hidden="true" />
<span>Profile</span>
</DropdownItem>
<DropdownItem tag="a" href="#">
<BiCog className="w-4 h-4 mr-3" aria-hidden="true" />
<span>Settings</span>
</DropdownItem>
<DropdownItem onClick={() => alert("Log out!")}>
<BiLogOutCircle className="w-4 h-4 mr-3" aria-hidden="true" />
<span>Log out</span>
</DropdownItem>
</Dropdown>
</li>
</ul>
</div>
</header>
);
};
export default Header;