Nav #4
@@ -1,14 +1,14 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Box, SimpleGrid } from "@chakra-ui/react";
|
import { Box, SimpleGrid } from "@chakra-ui/react";
|
||||||
import { endOfMonth, getDate } from 'date-fns';
|
import { endOfMonth, getDate } from "date-fns";
|
||||||
|
|
||||||
const Calender = (): JSX.Element => {
|
const Calender = (): JSX.Element => {
|
||||||
const today = new Date;
|
const today = new Date();
|
||||||
|
|
||||||
const endOfCurrMonth = endOfMonth(today);
|
const endOfCurrMonth = endOfMonth(today);
|
||||||
const lastDay = getDate(endOfCurrMonth);
|
const lastDay = getDate(endOfCurrMonth);
|
||||||
|
|
||||||
console.info(`This month has ${lastDay} days.`);
|
// console.info(`This month has ${lastDay} days.`);
|
||||||
|
|
||||||
const daysArr = [];
|
const daysArr = [];
|
||||||
for (let i = daysArr.length; i < lastDay; i++) {
|
for (let i = daysArr.length; i < lastDay; i++) {
|
||||||
|
|||||||
@@ -2,11 +2,7 @@ import React, { FC } from "react";
|
|||||||
import { Button, HStack, Link } from "@chakra-ui/react";
|
import { Button, HStack, Link } from "@chakra-ui/react";
|
||||||
import navItems, { NavItem } from "./navItems";
|
import navItems, { NavItem } from "./navItems";
|
||||||
|
|
||||||
interface DesktopNavProps {
|
const DesktopNav: FC<DesktopNavProps> = () => {
|
||||||
sticky?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const DesktopNav: FC<DesktopNavProps> = ({ sticky }: DesktopNavProps) => {
|
|
||||||
return (
|
return (
|
||||||
<HStack
|
<HStack
|
||||||
as="nav"
|
as="nav"
|
||||||
@@ -22,7 +18,7 @@ const DesktopNav: FC<DesktopNavProps> = ({ sticky }: DesktopNavProps) => {
|
|||||||
{navItems.map((navItem: NavItem) => {
|
{navItems.map((navItem: NavItem) => {
|
||||||
return (
|
return (
|
||||||
<Link id={"dekstop-" + navItem[0]} key={navItem[0]} href={navItem[1]}>
|
<Link id={"dekstop-" + navItem[0]} key={navItem[0]} href={navItem[1]}>
|
||||||
<Button variant={sticky ? "stickyNav" : "nav"}>{navItem[0]}</Button>
|
<Button variant="nav">{navItem[0]}</Button>
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -13,34 +13,23 @@ import DesktopNav from "./DesktopNav";
|
|||||||
import MobileNav from "./MobileNav";
|
import MobileNav from "./MobileNav";
|
||||||
|
|
||||||
const Header = (): JSX.Element => {
|
const Header = (): JSX.Element => {
|
||||||
// Sticky Navbar, Scroll Direction, and Back to Top Button Visibility
|
// Add transparency while not at the top of the page.
|
||||||
const [stickyNavbar, setStickyNavbar] = useState<boolean>(false);
|
const [transparentNavbar, setTransparentNavbar] = useState<boolean>(false);
|
||||||
const lastScroll = useRef<number>(0);
|
const lastScroll = useRef<number>(0);
|
||||||
const [scrollDirection, setScrollDirection] = useState<"up" | "down" | "top">(
|
|
||||||
"top"
|
|
||||||
);
|
|
||||||
// const [scroll, setScroll] = useState<number>(0);
|
|
||||||
|
|
||||||
const handleScroll = (): void => {
|
const handleScroll = (): void => {
|
||||||
// Sticky Nav
|
// Sticky Nav
|
||||||
if (window.scrollY >= 20) {
|
if (window.scrollY >= 20) {
|
||||||
setStickyNavbar(true);
|
setTransparentNavbar(true);
|
||||||
} else {
|
} else {
|
||||||
setStickyNavbar(false);
|
setTransparentNavbar(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll Direction
|
// Scroll Position.
|
||||||
const currentScroll =
|
const currentScroll =
|
||||||
window.scrollY || window.pageYOffset || document.body.scrollTop;
|
window.scrollY || window.pageYOffset || document.body.scrollTop;
|
||||||
|
|
||||||
if (currentScroll > lastScroll.current) {
|
// Update Scroll Position Reference
|
||||||
setScrollDirection("down");
|
|
||||||
} else if (currentScroll <= 20) {
|
|
||||||
setScrollDirection("top");
|
|
||||||
} else {
|
|
||||||
setScrollDirection("up");
|
|
||||||
}
|
|
||||||
|
|
||||||
lastScroll.current = currentScroll <= 0 ? 0 : currentScroll;
|
lastScroll.current = currentScroll <= 0 ? 0 : currentScroll;
|
||||||
// setScroll(lastScroll.current = currentScroll <= 0 ? 0 : currentScroll)
|
// setScroll(lastScroll.current = currentScroll <= 0 ? 0 : currentScroll)
|
||||||
};
|
};
|
||||||
@@ -85,29 +74,22 @@ const Header = (): JSX.Element => {
|
|||||||
boxShadow={
|
boxShadow={
|
||||||
open
|
open
|
||||||
? "none"
|
? "none"
|
||||||
: stickyNavbar
|
: "rgba(0, 134, 255, 0.75) 0px 0px 15px, rgba(0, 134, 255, 0.5) 0px 0px 3px 1px"
|
||||||
? "rgba(0, 134, 255, 0.75) 0px 0px 15px, rgba(0, 134, 255, 0.5) 0px 0px 3px 1px"
|
|
||||||
: "none"
|
|
||||||
}
|
}
|
||||||
bg={
|
bg={
|
||||||
open
|
open
|
||||||
? "brand.main"
|
? "brand.main"
|
||||||
: stickyNavbar
|
: transparentNavbar
|
||||||
? "rgba(49, 56, 220, 0.9)"
|
? "rgba(49, 56, 220, 0.9)"
|
||||||
: "transparent"
|
: "brand.main"
|
||||||
}
|
|
||||||
d={
|
|
||||||
scrollDirection === "up" || scrollDirection === "top" ? "block" : "none"
|
|
||||||
}
|
}
|
||||||
transition=".5s ease"
|
transition=".5s ease"
|
||||||
borderRadius="0px 0px 10px 10px"
|
borderRadius="0px 0px 10px 10px"
|
||||||
_hover={{
|
_hover={{
|
||||||
bg: open ? "brand.main" : stickyNavbar ? "brand.main" : "transparent",
|
bg: "brand.main",
|
||||||
boxShadow: open
|
boxShadow: open
|
||||||
? "none"
|
? "none"
|
||||||
: stickyNavbar
|
: "rgba(0, 134, 255, 0.9) 0px 0px 15px, rgba(0, 134, 255, 0.7) 0px 0px 3px 1px",
|
||||||
? "rgba(0, 134, 255, 0.9) 0px 0px 15px, rgba(0, 134, 255, 0.7) 0px 0px 3px 1px"
|
|
||||||
: "none",
|
|
||||||
}}
|
}}
|
||||||
h={open ? "125px" : "auto"}
|
h={open ? "125px" : "auto"}
|
||||||
>
|
>
|
||||||
@@ -142,7 +124,7 @@ const Header = (): JSX.Element => {
|
|||||||
LCM Potty Chart
|
LCM Potty Chart
|
||||||
</Heading>
|
</Heading>
|
||||||
</Box>
|
</Box>
|
||||||
<DesktopNav sticky={stickyNavbar} />
|
<DesktopNav />
|
||||||
</HStack>
|
</HStack>
|
||||||
<Menu isLazy lazyBehavior="unmount" isOpen={open}>
|
<Menu isLazy lazyBehavior="unmount" isOpen={open}>
|
||||||
<MenuButton
|
<MenuButton
|
||||||
@@ -154,9 +136,11 @@ const Header = (): JSX.Element => {
|
|||||||
onMouseLeave={() => setHover(false)}
|
onMouseLeave={() => setHover(false)}
|
||||||
d={{ base: "inline-flex", lg: "none" }}
|
d={{ base: "inline-flex", lg: "none" }}
|
||||||
variant="mobileNav"
|
variant="mobileNav"
|
||||||
bg={stickyNavbar ? "transparent" : "rgba(255, 255, 255, .15)"}
|
bg={
|
||||||
|
transparentNavbar ? "transparent" : "rgba(255, 255, 255, .15)"
|
||||||
|
}
|
||||||
type="button"
|
type="button"
|
||||||
border={stickyNavbar ? "1px solid #0068ff" : "none"}
|
border={transparentNavbar ? "1px solid #0068ff" : "none"}
|
||||||
id="mobile-menu-button"
|
id="mobile-menu-button"
|
||||||
/>
|
/>
|
||||||
<MobileNav updateOpen={setOpen} />
|
<MobileNav updateOpen={setOpen} />
|
||||||
|
|||||||
Reference in New Issue
Block a user