Skip to content

Commit c37ca09

Browse files
authored
refactor: make header menu code slightly more manageable (#78)
* refactor: extract <HeaderMenuItem /> * refactor: extract <DropdownMenu /> * refactor: extract <DropdownMenuItem /> * chore: add prettier
1 parent d787eec commit c37ca09

File tree

3 files changed

+64
-38
lines changed

3 files changed

+64
-38
lines changed

package-lock.json

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

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"lint-staged": "^15.3.0",
7272
"msw": "^2.7.0",
7373
"postcss": "^8.4.49",
74+
"prettier": "3.4.2",
7475
"tailwindcss": "^3.4.15",
7576
"typescript": "~5.7.2",
7677
"typescript-eslint": "^8.15.0",

src/components/Header.tsx

+47-38
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,36 @@ import { Link } from "react-router-dom";
22
import { SidebarTrigger } from "./ui/sidebar";
33
import { Separator } from "./ui/separator";
44

5+
function HeaderMenuItem({ children }: { children: React.ReactNode }) {
6+
return (
7+
<div className="text-black hover:text-gray-800 font-semibold cursor-pointer text-base px-2 py-1 rounded-md hover:bg-blue-50 transition-colors">
8+
{children}
9+
</div>
10+
);
11+
}
12+
13+
function DropdownMenu({ children }: { children: React.ReactNode }) {
14+
return (
15+
<div className="absolute right-0 top-full mt-2 w-56 bg-white rounded-lg shadow-lg opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-50 border border-gray-100">
16+
<div className="py-1">{children}</div>
17+
</div>
18+
);
19+
}
20+
21+
function DropdownMenuItem({
22+
children,
23+
to,
24+
}: {
25+
to: string;
26+
children: React.ReactNode;
27+
}) {
28+
return (
29+
<Link to={to} className="block px-5 py-3 text-gray-700 hover:bg-blue-50">
30+
{children}
31+
</Link>
32+
);
33+
}
34+
535
export function Header({ hasError }: { hasError?: boolean }) {
636
return (
737
<header className="flex-shrink-0 h-16 px-3 items-center flex w-full bg-teal-25 opacity-1 border-b-blue-200 border-b">
@@ -23,46 +53,25 @@ export function Header({ hasError }: { hasError?: boolean }) {
2353
</div>
2454
<div className="flex items-center gap-4 mr-16">
2555
<div className="flex items-center relative group">
26-
<div className="text-black hover:text-gray-800 font-semibold cursor-pointer text-base px-2 py-1 rounded-md hover:bg-blue-50 transition-colors">
27-
Certificates
28-
</div>
29-
<div className="absolute right-0 top-full mt-2 w-56 bg-white rounded-lg shadow-lg opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-50 border border-gray-100">
30-
<div className="py-1">
31-
<Link
32-
to="/certificates"
33-
className="block px-5 py-3 text-gray-700 hover:bg-blue-50"
34-
>
35-
Download
36-
</Link>
37-
<Link
38-
to="/certificates/security"
39-
className="block px-5 py-3 text-gray-700 hover:bg-blue-50"
40-
>
41-
Certificate Security
42-
</Link>
43-
</div>
44-
</div>
56+
<HeaderMenuItem>Certificates</HeaderMenuItem>
57+
<DropdownMenu>
58+
<DropdownMenuItem to="/certificates">Download</DropdownMenuItem>
59+
<DropdownMenuItem to="/certificates/security">
60+
Certificate Security
61+
</DropdownMenuItem>
62+
</DropdownMenu>
4563
</div>
64+
4665
<div className="flex items-center relative group">
47-
<div className="text-black hover:text-gray-800 font-semibold cursor-pointer text-base px-2 py-1 rounded-md hover:bg-blue-50 transition-colors">
48-
Help
49-
</div>
50-
<div className="absolute right-0 top-full mt-2 w-56 bg-white rounded-lg shadow-lg opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-50 border border-gray-100">
51-
<div className="py-1">
52-
<Link
53-
to="/help/continue-setup"
54-
className="block px-5 py-3 text-gray-700 hover:bg-blue-50"
55-
>
56-
Continue Setup
57-
</Link>
58-
<Link
59-
to="/help/copilot-setup"
60-
className="block px-5 py-3 text-gray-700 hover:bg-blue-50"
61-
>
62-
Copilot Setup
63-
</Link>
64-
</div>
65-
</div>
66+
<HeaderMenuItem>Help</HeaderMenuItem>
67+
<DropdownMenu>
68+
<DropdownMenuItem to="/help/continue-setup">
69+
Continue Setup
70+
</DropdownMenuItem>
71+
<DropdownMenuItem to="/help/copilot-setup">
72+
Copilot Setup
73+
</DropdownMenuItem>
74+
</DropdownMenu>
6675
</div>
6776

6877
<div className="flex items-center relative group">

0 commit comments

Comments
 (0)