-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve site header with responsive hooks and hamburger menu
- Extract hamburger menu into separate component - Replace hidden classes with useBreakpoint hook - Add menu/close icon toggle animation References: shadcn-ui/ui#761 (comment)
- Loading branch information
Showing
2 changed files
with
87 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Button } from "@/components/ui/button" | ||
import { Menu, X } from "lucide-react" | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuTrigger, | ||
} from "@/components/ui/dropdown-menu" | ||
import { Link } from '@tanstack/react-router' | ||
import { useState } from 'react' | ||
|
||
type MenuItem = { | ||
name: string | ||
to: string | ||
} | ||
|
||
interface HamburgerMenuProps { | ||
items: MenuItem[] | ||
} | ||
|
||
export function HamburgerMenu({ items }: HamburgerMenuProps) { | ||
const [isOpen, setIsOpen] = useState(false) | ||
|
||
return ( | ||
<DropdownMenu open={isOpen} onOpenChange={setIsOpen}> | ||
<DropdownMenuTrigger asChild> | ||
<Button variant="outline" size="icon"> | ||
{isOpen ? ( | ||
<X strokeWidth={3} /> | ||
) : ( | ||
<Menu /> | ||
)} | ||
<span className="sr-only">Toggle navigation menu</span> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent align="start" className="w-48"> | ||
{items.map((item) => ( | ||
<DropdownMenuItem key={item.to} asChild> | ||
<Link | ||
to={item.to} | ||
className="w-full cursor-pointer font-medium text-muted-foreground [&.active]:text-foreground" | ||
> | ||
{item.name} | ||
</Link> | ||
</DropdownMenuItem> | ||
))} | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters