Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make navbar sticky with conditional styling enhancements #442

Merged
merged 5 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 29 additions & 27 deletions frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#root {
max-width: 1366px;
margin: 0 auto;
overflow-x: hidden;
/* overflow-x: hidden; */
}

#Hero {
Expand All @@ -15,22 +15,26 @@
background-size: cover;
}

.error{
.error {
margin-top: 0 !important;
}

/* Animations */
.animated-text {
animation: scaleText .7s ease-in-out 1 alternate; /* Animation properties */
animation: scaleText .7s ease-in-out 1 alternate;
/* Animation properties */
transition: all smooth;
}

@keyframes scaleText {
from {
font-size: 8rem; /* Initial font size */
font-size: 8rem;
/* Initial font size */
}

to {
font-size: 4rem; /* Final font size */
font-size: 4rem;
/* Final font size */
}
}

Expand All @@ -42,17 +46,17 @@

/* Track */
::-webkit-scrollbar-track {
background: #fafafc;
background: #fafafc;
}

/* Handle */
::-webkit-scrollbar-thumb {
background: #B91C1C !important;
background: #B91C1C !important;
border-radius: 12px !important;
}

::-webkit-scrollbar-thumb:hover {
background: #B91C1C!important;
background: #B91C1C !important;
border-radius: 12px !important;
}

Expand All @@ -62,17 +66,17 @@

/* Track */
::-webkit-scrollbar-track {
background: #fafafc;
background: #fafafc;
}

/* Handle */
::-webkit-scrollbar-thumb {
background: #B91C1C !important;
background: #B91C1C !important;
border-radius: 12px !important;
}

::-webkit-scrollbar-thumb:hover {
background: #B91C1C!important;
background: #B91C1C !important;
border-radius: 12px !important;
}

Expand All @@ -86,9 +90,10 @@
}
}

.navbar{
background-color: #fed4d4;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
.navbar {
background-color: #fed4d4;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);

}

.text-\[4rem\] {
Expand All @@ -105,16 +110,13 @@

/* ADD THE CLASS OF CLAMPED-TEXT */
.clamped-text {
display: -webkit-box;
-webkit-box-orient: vertical; /* Define the orientation as vertical */
-webkit-line-clamp: 4; /* Limit the number of lines to 4 */
overflow: hidden; /* Hide any overflowed content */
text-overflow: ellipsis; /* Add ellipsis (...) for overflow */
}







display: -webkit-box;
-webkit-box-orient: vertical;
/* Define the orientation as vertical */
-webkit-line-clamp: 4;
/* Limit the number of lines to 4 */
overflow: hidden;
/* Hide any overflowed content */
text-overflow: ellipsis;
/* Add ellipsis (...) for overflow */
}
54 changes: 27 additions & 27 deletions frontend/src/Components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const Navbar = () => {

useEffect(() => {
const handleScroll = () => {
if (window.scrollY > window.innerHeight) {
console.log(window.scrollY);
if (window.scrollY > 0) {

setIsSticky(true);
} else {
setIsSticky(false);
Expand All @@ -68,10 +70,19 @@ const Navbar = () => {
};

return (
// <nav
// className={`z-50 relative navbar ${isSticky ? "fixed top-0 left-0 w-full bg-white shadow-md" : ""
// }`}
// >
<nav
className={`z-50 relative navbar ${
isSticky ? "fixed top-0 left-0 w-full bg-white shadow-md" : ""
}`}
style={{
position: "sticky",
top: 0,
zIndex: 1000,
backgroundColor: isSticky ? "#fed4d4" : "#fed4d4",
boxShadow: isSticky ? "0 4px 6px rgba(0, 0, 0, 0.3)" : "none",
transition: "background-color 0.3s, box-shadow 0.3s",
}}
>
<header className="text-gray-600 body-font">
<div className="container mx-auto flex items-center justify-between p-5">
Expand All @@ -84,9 +95,8 @@ const Navbar = () => {

{/* Slide-in Menu and Overlay */}
<div
className={`fixed inset-0 z-40 transition-all duration-300 transform ${
menuOpen ? "translate-x-0" : "-translate-x-full"
} flex flex-col top-0 left-0 bg-white w-[250px] h-full p-5`}
className={`fixed inset-0 z-40 transition-all duration-300 transform ${menuOpen ? "translate-x-0" : "-translate-x-full"
} flex flex-col top-0 left-0 bg-white w-[250px] h-full p-5`}
>
{/* Close button inside the menu */}
<div className="flex justify-end">
Expand All @@ -100,8 +110,7 @@ const Navbar = () => {
<NavLink
to="/recipes"
className={({ isActive }) =>
`hover:text-red-700 font-semibold ${
isActive ? "text-red-700" : "text-black"
`hover:text-red-700 font-semibold ${isActive ? "text-red-700" : "text-black"
}`
}
onClick={handleLinkClick}
Expand All @@ -111,8 +120,7 @@ const Navbar = () => {
<NavLink
to="/mainmeals"
className={({ isActive }) =>
`hover:text-red-700 font-semibold ${
isActive ? "text-red-700" : "text-black"
`hover:text-red-700 font-semibold ${isActive ? "text-red-700" : "text-black"
}`
}
onClick={handleLinkClick}
Expand All @@ -122,8 +130,7 @@ const Navbar = () => {
<NavLink
to="/smallbites"
className={({ isActive }) =>
`hover:text-red-700 font-semibold ${
isActive ? "text-red-700" : "text-black"
`hover:text-red-700 font-semibold ${isActive ? "text-red-700" : "text-black"
}`
}
onClick={handleLinkClick}
Expand All @@ -133,8 +140,7 @@ const Navbar = () => {
<NavLink
to="/healthy"
className={({ isActive }) =>
`hover:text-red-700 font-semibold ${
isActive ? "text-red-700" : "text-black"
`hover:text-red-700 font-semibold ${isActive ? "text-red-700" : "text-black"
}`
}
onClick={handleLinkClick}
Expand All @@ -144,8 +150,7 @@ const Navbar = () => {
<NavLink
to="/recipe-suggestions"
className={({ isActive }) =>
`mr-5 hover:text-red-700 font-semibold ${
isActive ? "text-red-700" : "text-black"
`mr-5 hover:text-red-700 font-semibold ${isActive ? "text-red-700" : "text-black"
}`
}
onClick={handleLinkClick}
Expand Down Expand Up @@ -181,8 +186,7 @@ const Navbar = () => {
<NavLink
to="/recipes"
className={({ isActive }) =>
`mr-5 hover:text-red-700 font-semibold ${
isActive ? "text-red-700" : "text-black"
`mr-5 hover:text-red-700 font-semibold ${isActive ? "text-red-700" : "text-black"
}`
}
>
Expand All @@ -191,8 +195,7 @@ const Navbar = () => {
<NavLink
to="/mainmeals"
className={({ isActive }) =>
`mr-5 hover:text-red-700 font-semibold ${
isActive ? "text-red-700" : "text-black"
`mr-5 hover:text-red-700 font-semibold ${isActive ? "text-red-700" : "text-black"
}`
}
>
Expand All @@ -201,8 +204,7 @@ const Navbar = () => {
<NavLink
to="/smallbites"
className={({ isActive }) =>
`mr-5 hover:text-red-700 font-semibold ${
isActive ? "text-red-700" : "text-black"
`mr-5 hover:text-red-700 font-semibold ${isActive ? "text-red-700" : "text-black"
}`
}
>
Expand All @@ -211,8 +213,7 @@ const Navbar = () => {
<NavLink
to="/healthy"
className={({ isActive }) =>
`mr-5 hover:text-red-700 font-semibold ${
isActive ? "text-red-700" : "text-black"
`mr-5 hover:text-red-700 font-semibold ${isActive ? "text-red-700" : "text-black"
}`
}
>
Expand All @@ -221,8 +222,7 @@ const Navbar = () => {
<NavLink
to="/recipe-suggestions"
className={({ isActive }) =>
`mr-5 hover:text-red-700 font-semibold ${
isActive ? "text-red-700" : "text-black"
`mr-5 hover:text-red-700 font-semibold ${isActive ? "text-red-700" : "text-black"
}`
}
onClick={handleLinkClick}
Expand Down