Skip to content

Commit

Permalink
Added dynamic Nav gap on TopBar
Browse files Browse the repository at this point in the history
The `gap-1` class name now depends on whether the window is below 'lg' breakpoint or not.
  • Loading branch information
chrsrns committed Jan 30, 2024
1 parent 3602517 commit d724475
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src-frontend-react/src/components/TopBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ export const TopBar = () => {
const navigate = useNavigate();
const location = useLocation();

const [windowWidth, setWindowWidth] = useState(window.innerWidth);

useEffect(() => {
const handleResize = () => {
setWindowWidth(window.innerWidth);
};

window.addEventListener("resize", handleResize);

return () => {
window.removeEventListener("resize", handleResize);
};
}, []);

const isBelowLgBreakpoint = windowWidth < 992;

return (
<Navbar
expand={cookies.login_username ? "lg" : true}
Expand All @@ -102,7 +118,7 @@ export const TopBar = () => {
onSelect={(link) => {
navigate(link);
}}
className="me-auto gap-1"
className={`me-auto ${isBelowLgBreakpoint ? "gap-1" : ""}`}
>
{cookies.login_username
? radios.map((radio, idx) => (
Expand Down

0 comments on commit d724475

Please sign in to comment.