Skip to content

Commit 1579ac8

Browse files
feat: sticky navigation bar with style change on scroll
1 parent 5a3d1fa commit 1579ac8

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

ichub-frontend/src/assets/styles/config/_variables.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ $dark-blue-gradient-bg: linear-gradient(180deg, $dark-gradient-start 0%, $dark-g
3232
$header-gradient-end: rgba(0, 165, 255, 0.57);
3333
$header-gradient-bg: linear-gradient(180deg, $gradient-start 0%, $header-gradient-end 100%);
3434

35+
$opaque-gradient-start: rgb(0, 42, 126);
36+
$opaque-gradient-end: rgb(0, 108, 167);
37+
$header-opaque-gradient-bg: linear-gradient(180deg, $opaque-gradient-start 0%, $opaque-gradient-end 100%);
38+
3539
// Brand colors
3640
$brand-blue: rgb(1, 40, 119);
3741
$brand-light-blue: rgb(15, 113, 203);

ichub-frontend/src/assets/styles/layout/_Header.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ header.ichub-header {
3030
border-bottom: 5px solid $brand-header-blue;
3131
padding: 0 !important;
3232
position: sticky !important;
33+
transition: background-color 0.3s ease-in-out;
34+
35+
&.scrolled {
36+
background: $header-opaque-gradient-bg;
37+
}
3338

3439
button.user-button {
3540
background-color: $brand-border;

ichub-frontend/src/assets/styles/layout/_MainLayout.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
url('/stars-background.png') !important;
3030
}
3131

32+
.headerWrapper{
33+
position: sticky;
34+
top: 0;
35+
z-index: 1100;
36+
}
37+
3238
/* Content area styling */
3339
.contentArea {
3440
padding: 20px;

ichub-frontend/src/components/general/Header.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* SPDX-License-Identifier: Apache-2.0
2121
********************************************************************************/
2222

23-
import { useState } from 'react';
23+
import { useState, useEffect } from 'react';
2424
import AppBar from '@mui/material/AppBar';
2525
import Box from '@mui/material/Box';
2626
import Toolbar from '@mui/material/Toolbar';
@@ -38,6 +38,7 @@ import { Logout, Settings } from '@mui/icons-material';
3838
export default function PrimarySearchAppBar() {
3939
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
4040
const [mobileMoreAnchorEl, setMobileMoreAnchorEl] = useState<null | HTMLElement>(null);
41+
const [scrolled, setScrolled] = useState(false);
4142

4243
const isMenuOpen = Boolean(anchorEl);
4344
const isMobileMenuOpen = Boolean(mobileMoreAnchorEl);
@@ -59,6 +60,15 @@ export default function PrimarySearchAppBar() {
5960
setMobileMoreAnchorEl(event.currentTarget);
6061
};
6162

63+
useEffect(() => {
64+
const handleScroll = () => {
65+
setScrolled(window.scrollY > 50);
66+
};
67+
68+
window.addEventListener("scroll", handleScroll);
69+
return () => window.removeEventListener("scroll", handleScroll);
70+
}, []);
71+
6272
const menuId = 'primary-search-account-menu';
6373
const renderMenu = (
6474
<Menu
@@ -150,7 +160,7 @@ export default function PrimarySearchAppBar() {
150160

151161
return (
152162
<Box sx={{ flexGrow: 1 }}>
153-
<AppBar position="static" className='ichub-header'>
163+
<AppBar position="static" className={`ichub-header ${scrolled ? "scrolled" : ""}`}>
154164
<Toolbar>
155165
<a href="/">
156166
<img

ichub-frontend/src/layout/MainLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import Sidebar from '../components/general/Sidebar';
2929
function MainLayout() {
3030
return (
3131
<Grid2 container direction="column" className="contentWrapper">
32-
<Grid2>
32+
<Grid2 className="headerWrapper">
3333
<Header/>
3434
</Grid2>
3535
<Grid2 container className="pageWrapper" spacing={2}>

0 commit comments

Comments
 (0)