import React, { useState, useEffect } from "react";
import styled from "styled-components";
import { FaHome } from "react-icons/fa";
const HeaderContainer = styled.header`
/* Styling for the header container. */
position: fixed;
top: ${({ isFixed }) => (isFixed ? "0" : "-100px")};
left: 0;
right: 0;
z-index: 1000;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #333;
color: #fff;
padding: 20px 40px;
transition: top 0.7s ease-in-out;
`;
const LeftSection = styled.div`
/* Styling for the left section of the header. */
display: flex;
align-items: center;
`;
const CenterSection = styled.div`
/* Styling for the center section of the header. */
ul {
list-style: none;
display: flex;
margin: 0;
padding: 0;
}
li {
margin-right: 20px;
}
a {
text-decoration: none;
color: #fff;
font-weight: bold;
}
`;
const RightSection = styled.div`
/* Styling for the right section of the header. */
display: flex;
align-items: center;
`;
const Logo = styled.div`
/* Styling for the logo within the header. */
display: flex;
align-items: center;
margin-right: 20px;
svg {
margin-right: 10px;
}
`;
const Header = () => {
const [isFixed, setIsFixed] = useState(true);
useEffect(() => {
let prevScrollY = 0;
const handleScroll = () => {
const currentScrollY = window.scrollY;
if (currentScrollY > 200 && currentScrollY > prevScrollY) {
setIsFixed(false);
} else if (currentScrollY <= prevScrollY) {
setIsFixed(true);
}
prevScrollY = currentScrollY;
};
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
}, []);
return (
<HeaderContainer isFixed={isFixed}>
<LeftSection>
<Logo>
<FaHome size={24} />
<span>Company Name</span>
</Logo>
</LeftSection>
<CenterSection>
<ul>
<li>
<a href="/">Home</a>
</li>
<li>
<a href="/products">Products</a>
</li>
{}
</ul>
</CenterSection>
<RightSection>
<a href="/login">Login</a>
<span> | </span>
<a href="/signup">Sign Up</a>
</RightSection>
</HeaderContainer>
);
};
export default Header;