Skip to content

refactor: make header menu code slightly more manageable #78

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

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 16 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"lint-staged": "^15.3.0",
"msw": "^2.7.0",
"postcss": "^8.4.49",
"prettier": "3.4.2",
"tailwindcss": "^3.4.15",
"typescript": "~5.7.2",
"typescript-eslint": "^8.15.0",
Expand Down
85 changes: 47 additions & 38 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@ import { Link } from "react-router-dom";
import { SidebarTrigger } from "./ui/sidebar";
import { Separator } from "./ui/separator";

function HeaderMenuItem({ children }: { children: React.ReactNode }) {
return (
<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">
{children}
</div>
);
}

function DropdownMenu({ children }: { children: React.ReactNode }) {
return (
<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">
<div className="py-1">{children}</div>
</div>
);
}

function DropdownMenuItem({
children,
to,
}: {
to: string;
children: React.ReactNode;
}) {
return (
<Link to={to} className="block px-5 py-3 text-gray-700 hover:bg-blue-50">
{children}
</Link>
);
}

export function Header({ hasError }: { hasError?: boolean }) {
return (
<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">
Expand All @@ -23,46 +53,25 @@ export function Header({ hasError }: { hasError?: boolean }) {
</div>
<div className="flex items-center gap-4 mr-16">
<div className="flex items-center relative group">
<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">
Certificates
</div>
<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">
<div className="py-1">
<Link
to="/certificates"
className="block px-5 py-3 text-gray-700 hover:bg-blue-50"
>
Download
</Link>
<Link
to="/certificates/security"
className="block px-5 py-3 text-gray-700 hover:bg-blue-50"
>
Certificate Security
</Link>
</div>
</div>
<HeaderMenuItem>Certificates</HeaderMenuItem>
<DropdownMenu>
<DropdownMenuItem to="/certificates">Download</DropdownMenuItem>
<DropdownMenuItem to="/certificates/security">
Certificate Security
</DropdownMenuItem>
</DropdownMenu>
</div>

<div className="flex items-center relative group">
<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">
Help
</div>
<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">
<div className="py-1">
<Link
to="/help/continue-setup"
className="block px-5 py-3 text-gray-700 hover:bg-blue-50"
>
Continue Setup
</Link>
<Link
to="/help/copilot-setup"
className="block px-5 py-3 text-gray-700 hover:bg-blue-50"
>
Copilot Setup
</Link>
</div>
</div>
<HeaderMenuItem>Help</HeaderMenuItem>
<DropdownMenu>
<DropdownMenuItem to="/help/continue-setup">
Continue Setup
</DropdownMenuItem>
<DropdownMenuItem to="/help/copilot-setup">
Copilot Setup
</DropdownMenuItem>
</DropdownMenu>
</div>

<div className="flex items-center relative group">
Expand Down
Loading