Skip to content

Commit

Permalink
Add mobile menu with drawer component
Browse files Browse the repository at this point in the history
  • Loading branch information
emirrtopaloglu committed Feb 24, 2024
1 parent e6e828a commit cbb3b83
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 33 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"@hookform/resolvers": "^3.3.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slot": "^1.0.2",
Expand All @@ -19,13 +20,15 @@
"axios": "^1.6.7",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"lucide-react": "^0.338.0",
"next": "14.1.0",
"react": "^18",
"react-dom": "^18",
"react-hook-form": "^7.50.1",
"react-redux": "^9.1.0",
"tailwind-merge": "^2.2.1",
"tailwindcss-animate": "^1.0.7",
"vaul": "^0.9.0",
"yup": "^1.3.3",
"zod": "^3.22.4"
},
Expand Down
90 changes: 59 additions & 31 deletions src/components/layout/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,79 @@
import Link from "next/link";
import { Button } from "@/src/components/ui/button";
import { MenuIcon, XIcon } from "lucide-react";
import { useState } from "react";
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@/src/components/ui/drawer";

const MenuItemsComponent = ({ navClassNames, buttonClassNames, children }) => {
return (
<nav className={navClassNames}>
<Button asChild variant="ghost" className={buttonClassNames}>
<Link href="/">Anasayfa</Link>
</Button>
<Button asChild variant="ghost" className={buttonClassNames}>
<Link href="/communities">Topluluklar</Link>
</Button>
<Button asChild variant="ghost" className={buttonClassNames}>
<Link href="/events">Etkinlikler</Link>
</Button>
<Button asChild variant="ghost" className={buttonClassNames}>
<Link href="/guide">Rehber</Link>
</Button>
{children}
</nav>
);
};

export default function HeaderComponent() {
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);

return (
<header className="inset-x-0 top-0 z-50 bg-white shadow-sm dark:bg-gray-900">
<div className="container flex items-center justify-between h-14 px-4 md:px-6">
<Link className="font-semibold text-base md:text-lg" href="#">
<span className="font-medium">Social</span>
</Link>
<nav className="flex items-center space-x-2">
<Button
asChild
variant="ghost"
className="text-gray-600 dark:text-gray-100"
>
<Link href="/">Anasayfa</Link>
</Button>
<Button
asChild
variant="ghost"
className="text-gray-600 dark:text-gray-100"
>
<Link href="/communities">Topluluklar</Link>
</Button>
<Button
asChild
variant="ghost"
className="text-gray-600 dark:text-gray-100"
>
<Link href="/events">Etkinlikler</Link>
</Button>
<Button
asChild
variant="ghost"
className="text-gray-600 dark:text-gray-100"
>
<Link href="/guide">Rehber</Link>
</Button>
</nav>
<div className="flex items-center space-x-4">
<MenuItemsComponent
navClassNames="flex items-center space-x-2 md:block hidden"
buttonClassNames="text-gray-600 dark:text-gray-100"
/>
<div className="flex items-center space-x-4 md:block hidden">
<Button asChild>
<Link href="/auth/login">Giriş Yap</Link>
</Button>
<Button asChild variant="outline">
<Link href="/auth/register">Kayıt Ol</Link>
</Button>
</div>
<Drawer>
<DrawerTrigger asChild className="md:hidden flex">
<Button variant="outline" size="icon">
<MenuIcon size={18} className="text-gray-600" />
</Button>
</DrawerTrigger>
<DrawerContent>
<MenuItemsComponent
navClassNames="flex flex-col items-center p-8 space-y-2"
buttonClassNames="sm:w-[50%] w-full"
>
<Button asChild className="sm:w-[50%] w-full">
<Link href="/auth/login">Giriş Yap</Link>
</Button>
<Button asChild className="sm:w-[50%] w-full">
<Link href="/auth/register">Kayıt Ol</Link>
</Button>
</MenuItemsComponent>
</DrawerContent>
</Drawer>
</div>
</header>
);
Expand Down
90 changes: 90 additions & 0 deletions src/components/ui/drawer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import * as React from "react"
import { Drawer as DrawerPrimitive } from "vaul"

import { cn } from "@/src/lib/utils"

const Drawer = ({
shouldScaleBackground = true,
...props
}) => (
<DrawerPrimitive.Root shouldScaleBackground={shouldScaleBackground} {...props} />
)
Drawer.displayName = "Drawer"

const DrawerTrigger = DrawerPrimitive.Trigger

const DrawerPortal = DrawerPrimitive.Portal

const DrawerClose = DrawerPrimitive.Close

const DrawerOverlay = React.forwardRef(({ className, ...props }, ref) => (
<DrawerPrimitive.Overlay
ref={ref}
className={cn("fixed inset-0 z-50 bg-black/80", className)}
{...props} />
))
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName

const DrawerContent = React.forwardRef(({ className, children, ...props }, ref) => (
<DrawerPortal>
<DrawerOverlay />
<DrawerPrimitive.Content
ref={ref}
className={cn(
"fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background",
className
)}
{...props}>
<div className="mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" />
{children}
</DrawerPrimitive.Content>
</DrawerPortal>
))
DrawerContent.displayName = "DrawerContent"

const DrawerHeader = ({
className,
...props
}) => (
<div
className={cn("grid gap-1.5 p-4 text-center sm:text-left", className)}
{...props} />
)
DrawerHeader.displayName = "DrawerHeader"

const DrawerFooter = ({
className,
...props
}) => (
<div className={cn("mt-auto flex flex-col gap-2 p-4", className)} {...props} />
)
DrawerFooter.displayName = "DrawerFooter"

const DrawerTitle = React.forwardRef(({ className, ...props }, ref) => (
<DrawerPrimitive.Title
ref={ref}
className={cn("text-lg font-semibold leading-none tracking-tight", className)}
{...props} />
))
DrawerTitle.displayName = DrawerPrimitive.Title.displayName

const DrawerDescription = React.forwardRef(({ className, ...props }, ref) => (
<DrawerPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props} />
))
DrawerDescription.displayName = DrawerPrimitive.Description.displayName

export {
Drawer,
DrawerPortal,
DrawerOverlay,
DrawerTrigger,
DrawerClose,
DrawerContent,
DrawerHeader,
DrawerFooter,
DrawerTitle,
DrawerDescription,
}
Loading

0 comments on commit cbb3b83

Please sign in to comment.