Skip to content

Commit 3f35537

Browse files
committed
Make navbar responsive
1 parent 4753580 commit 3f35537

File tree

4 files changed

+88
-10
lines changed

4 files changed

+88
-10
lines changed

apps/client/src/components/Layout/Navbar.tsx

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import { useContext } from 'react';
1+
import { useContext, useState } from 'react';
2+
import AnimateHeight from 'react-animate-height';
3+
import { BsList } from 'react-icons/bs';
24
import GoToDashboardButton from '../../GoToDashboardButton';
35
import { UserContext } from '../../context/UserContext';
6+
import ActionButton from '../ActionButton';
47
import Container from '../Container';
58
import StockedUpLogo from '../StockedUpLogo';
69
import TryDemoButton from '../TryDemoButton';
@@ -9,20 +12,40 @@ import NavbarNavigation from './NavbarNavigation';
912

1013
function Navbar() {
1114
const { isAuthenticated } = useContext(UserContext);
15+
16+
const [showHamburger, setShowHamburger] = useState(false);
17+
1218
return (
1319
<header className="border-b border-gray-200 bg-gray-100 p-4">
1420
<Container className="flex items-center justify-between">
1521
<StockedUpLogo
1622
variant="black"
17-
className="h-16 w-auto"
23+
className="h-12 w-auto lg:h-16"
1824
/>
19-
<div className="flex flex-row items-center gap-8">
25+
<div className="hidden flex-row items-center gap-8 lg:flex">
2026
{!isAuthenticated ? <NavbarNavigation /> : <UserInfo />}
2127
<div className="flex items-center gap-4">
2228
{!isAuthenticated && <TryDemoButton />}
2329
<GoToDashboardButton isAuthenticated={isAuthenticated} />
2430
</div>
2531
</div>
32+
<ActionButton
33+
icon={BsList}
34+
onClick={() => setShowHamburger((show) => !show)}
35+
className="border border-gray-300 text-2xl text-muted lg:hidden"
36+
/>
37+
</Container>
38+
<Container className="lg:hidden">
39+
<AnimateHeight
40+
duration={200}
41+
height={showHamburger ? 'auto' : 0}
42+
>
43+
<NavbarNavigation
44+
orientation="col"
45+
className="px-3 py-4"
46+
extendedOptions
47+
/>
48+
</AnimateHeight>
2649
</Container>
2750
</header>
2851
);

apps/client/src/components/Layout/NavbarNavigation.tsx

+45-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1+
import classNames from 'classnames';
2+
import { useContext } from 'react';
13
import { Link } from 'react-router-dom';
4+
import { UserContext } from '../../context/UserContext';
5+
import UserInfo from '../UserInfo';
6+
7+
export type NavigationLinks = 'features' | 'login' | 'register' | 'demo' | 'github';
8+
9+
export interface NavbarNavigationProps {
10+
orientation?: 'row' | 'col';
11+
className?: string;
12+
extendedOptions?: boolean;
13+
}
14+
15+
function NavbarNavigation({
16+
orientation = 'row',
17+
className,
18+
extendedOptions = false,
19+
}: NavbarNavigationProps) {
20+
const orientationClasses = {
21+
row: 'flex-row items-center gap-6',
22+
col: 'flex-col gap-4',
23+
};
224

3-
function NavbarNavigation() {
425
return (
5-
<nav className="flex-1">
6-
<ul className="flex items-center gap-6">
26+
<nav className={classNames('flex-1', className)}>
27+
<ul className={classNames('flex', orientationClasses[orientation])}>
728
<li>
829
<Link
930
to="#features"
@@ -14,12 +35,32 @@ function NavbarNavigation() {
1435
</li>
1536
<li>
1637
<Link
17-
to="login"
38+
to="/login"
1839
className="link-muted"
1940
>
2041
Login
2142
</Link>
2243
</li>
44+
{extendedOptions && (
45+
<>
46+
<li>
47+
<Link
48+
to="/register/demo"
49+
className="link-muted"
50+
>
51+
Try demo
52+
</Link>
53+
</li>
54+
<li>
55+
<Link
56+
to="/register"
57+
className="link-muted"
58+
>
59+
Get started
60+
</Link>
61+
</li>
62+
</>
63+
)}
2364
</ul>
2465
</nav>
2566
);

package-lock.json

+14-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"dependencies": {
2525
"dotenv-cli": "^7.3.0",
26-
"express-session": "^1.17.3"
26+
"express-session": "^1.17.3",
27+
"react-animate-height": "^3.2.3"
2728
}
28-
}
29+
}

0 commit comments

Comments
 (0)