2024-06-20 13:59:27 +05:30
|
|
|
import { Box, Button, Container, Image } from "@chakra-ui/react";
|
2024-06-20 20:14:37 +05:30
|
|
|
import React, { useEffect, useState } from "react";
|
2024-06-21 12:37:32 +05:30
|
|
|
import { Link, NavLink, useNavigate } from "react-router-dom";
|
|
|
|
|
import { ChevronDownIcon } from "@chakra-ui/icons";
|
2024-06-21 13:59:13 +05:30
|
|
|
import { Link as ScrollLink, animateScroll as scroll } from "react-scroll";
|
2024-06-20 13:59:27 +05:30
|
|
|
import logo from "../assets/logo.png";
|
|
|
|
|
import earth from "../assets/earth.png";
|
2024-06-20 20:14:37 +05:30
|
|
|
|
2024-06-20 13:59:27 +05:30
|
|
|
export const nav = [
|
|
|
|
|
{
|
|
|
|
|
title: "Investment",
|
2024-06-21 12:37:32 +05:30
|
|
|
path: "investment",
|
2024-06-20 13:59:27 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: "How it works",
|
2024-06-21 12:37:32 +05:30
|
|
|
path: "how-it-works",
|
2024-06-20 13:59:27 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: "FAQ",
|
2024-06-21 12:37:32 +05:30
|
|
|
path: "faq",
|
2024-06-20 13:59:27 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: "About Us",
|
2024-06-21 12:37:32 +05:30
|
|
|
path: "aboutus",
|
2024-06-20 13:59:27 +05:30
|
|
|
},
|
|
|
|
|
];
|
2024-06-20 12:26:20 +05:30
|
|
|
|
|
|
|
|
const Header = () => {
|
2024-06-20 20:14:37 +05:30
|
|
|
const [showHeader, setShowHeader] = useState(true);
|
|
|
|
|
const [lastScrollY, setLastScrollY] = useState(0);
|
2024-06-21 12:37:32 +05:30
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const threshold = 0;
|
|
|
|
|
|
2024-06-20 20:14:37 +05:30
|
|
|
const controlHeader = () => {
|
|
|
|
|
if (window.scrollY > lastScrollY + threshold) {
|
|
|
|
|
setShowHeader(false);
|
|
|
|
|
} else if (window.scrollY < lastScrollY - threshold) {
|
|
|
|
|
setShowHeader(true);
|
|
|
|
|
}
|
|
|
|
|
setLastScrollY(window.scrollY);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
window.addEventListener("scroll", controlHeader);
|
|
|
|
|
return () => {
|
|
|
|
|
window.removeEventListener("scroll", controlHeader);
|
|
|
|
|
};
|
|
|
|
|
}, [lastScrollY]);
|
|
|
|
|
|
2024-06-21 12:37:32 +05:30
|
|
|
const handleNavClick = (path) => {
|
|
|
|
|
if (path === "aboutus") {
|
|
|
|
|
navigate(`/${path}`);
|
|
|
|
|
} else {
|
|
|
|
|
navigate("/");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleLanguageChange = (e) => {
|
|
|
|
|
const language = e.target.value;
|
2024-06-21 13:59:13 +05:30
|
|
|
const googleTranslateElement = document.querySelector(
|
|
|
|
|
"#google_translate_element select"
|
|
|
|
|
);
|
2024-06-21 12:37:32 +05:30
|
|
|
if (googleTranslateElement) {
|
|
|
|
|
googleTranslateElement.value = language;
|
|
|
|
|
googleTranslateElement.dispatchEvent(new Event("change"));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-20 12:26:20 +05:30
|
|
|
return (
|
2024-06-21 12:37:32 +05:30
|
|
|
<Box
|
|
|
|
|
zIndex={100}
|
|
|
|
|
top={showHeader ? 0 : "-80px"}
|
|
|
|
|
transition="top 0.3s"
|
|
|
|
|
position={"sticky"}
|
|
|
|
|
backgroundColor={"#002F0F"}
|
|
|
|
|
>
|
2024-06-20 13:59:27 +05:30
|
|
|
<Container
|
|
|
|
|
p={4}
|
|
|
|
|
display={"flex"}
|
|
|
|
|
justifyContent={"space-between"}
|
|
|
|
|
maxW="container.xl"
|
|
|
|
|
>
|
2024-06-21 13:59:13 +05:30
|
|
|
<Link to={"/"} onClick={() => scroll.scrollToTop()}>
|
2024-06-21 12:37:32 +05:30
|
|
|
<Image src={logo} h={8} />
|
|
|
|
|
</Link>
|
2024-06-20 13:59:27 +05:30
|
|
|
<Box display={"flex"} gap={6}>
|
2024-06-21 12:37:32 +05:30
|
|
|
{nav.map(({ title, path }, index) =>
|
|
|
|
|
path === "aboutus" ? (
|
|
|
|
|
<NavLink
|
|
|
|
|
key={index}
|
|
|
|
|
style={{
|
|
|
|
|
textDecoration: "none",
|
|
|
|
|
color: "white",
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
}}
|
|
|
|
|
to={`/${path}`}
|
|
|
|
|
onClick={() => handleNavClick(path)}
|
|
|
|
|
>
|
|
|
|
|
{title}
|
|
|
|
|
</NavLink>
|
|
|
|
|
) : (
|
|
|
|
|
<ScrollLink
|
|
|
|
|
key={index}
|
|
|
|
|
activeClass="active"
|
|
|
|
|
style={{
|
|
|
|
|
textDecoration: "none",
|
|
|
|
|
color: "white",
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
}}
|
|
|
|
|
to={path}
|
|
|
|
|
spy={true}
|
|
|
|
|
smooth={true}
|
|
|
|
|
offset={0}
|
|
|
|
|
duration={300}
|
|
|
|
|
onClick={() => handleNavClick(path)}
|
|
|
|
|
>
|
|
|
|
|
{title}
|
|
|
|
|
</ScrollLink>
|
|
|
|
|
)
|
|
|
|
|
)}
|
2024-06-20 13:59:27 +05:30
|
|
|
</Box>
|
|
|
|
|
<Box display={"flex"} alignItems={"center"} gap={4}>
|
2024-06-21 12:37:32 +05:30
|
|
|
<Box display={"flex"} alignItems={"center"} gap={1} color="white">
|
|
|
|
|
<Image src={earth} h={4} me={1} />
|
|
|
|
|
<Box
|
|
|
|
|
as="select"
|
|
|
|
|
onChange={handleLanguageChange}
|
|
|
|
|
bg="transparent"
|
|
|
|
|
color="white"
|
|
|
|
|
border="none"
|
|
|
|
|
cursor="pointer"
|
|
|
|
|
appearance="none"
|
|
|
|
|
>
|
2024-06-21 13:59:13 +05:30
|
|
|
<option className="rounded-0 text-dark" value="en">
|
|
|
|
|
En
|
|
|
|
|
</option>
|
|
|
|
|
<option value="ur text-dark">Ur</option>
|
2024-06-21 12:37:32 +05:30
|
|
|
</Box>
|
|
|
|
|
</Box>
|
2024-06-20 13:59:27 +05:30
|
|
|
<Button color={"#002F0F"} ps={6} pe={6} size={"sm"} rounded={"xl"}>
|
|
|
|
|
Contact Us
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
</Container>
|
2024-06-21 12:37:32 +05:30
|
|
|
<Box id="google_translate_element" display="block" />
|
2024-06-20 13:59:27 +05:30
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|
2024-06-20 12:26:20 +05:30
|
|
|
|
2024-06-20 13:59:27 +05:30
|
|
|
export default Header;
|