Skip to content

Commit

Permalink
feat(navbar): add moble layout navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
DikDns committed Oct 8, 2024
1 parent b2f34f1 commit e863697
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type Metadata } from "next";
import { GeistSans } from "geist/font/sans";

import { Navbar } from "@/components/common/navbar";
import { ReactLenis } from "@/components/common/react-lenis";
import { env } from "@/env";

Expand Down Expand Up @@ -29,7 +30,10 @@ export default function RootLayout({
>
<body>
{env.NODE_ENV === "development" ? (
<ReactLenis>{children}</ReactLenis>
<>
<Navbar />
<ReactLenis>{children}</ReactLenis>
</>
) : (
<main className="flex h-screen items-center justify-center">
<h1 className="text-center font-bonobo text-2xl font-semibold">
Expand Down
13 changes: 10 additions & 3 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const SponsorMediaPartnerCard = ({ logo }: { logo: string }) => {
export default function HomePage() {
return (
<main
id="main"
className="relative min-h-screen overflow-hidden bg-[length:512px_512px] bg-repeat"
style={{
backgroundImage: "url(./assets/main-pattern.webp)",
Expand Down Expand Up @@ -117,7 +118,10 @@ export default function HomePage() {
<Wave className="absolute -left-32 top-[700px] rotate-180 opacity-50" />

<div className="bg-primary-700/95 pt-96">
<section className="relative z-10 space-y-4 rounded-md bg-neutral-50 px-6 py-8 text-center">
<section
id="kelompok"
className="relative z-10 space-y-4 rounded-md bg-neutral-50 px-6 py-8 text-center"
>
<BorderCorner />

<h2 className="text-center font-rock-n-roll-one text-3xl font-normal leading-tight tracking-wider text-neutral-950">
Expand Down Expand Up @@ -147,7 +151,10 @@ export default function HomePage() {

{/* New Timeline Section */}
<div className="bg-primary-700/95 pt-64">
<section className="relative z-10 rounded-md bg-neutral-50">
<section
id="timeline"
className="relative z-10 rounded-md bg-neutral-50"
>
<BorderCorner />
<h2 className="p-10 text-center font-rock-n-roll-one text-3xl font-normal leading-tight tracking-wider text-neutral-950">
TIMELINE
Expand Down Expand Up @@ -251,7 +258,7 @@ export default function HomePage() {
</div>

<div className="bg-primary-700/95 pt-64">
<section className="relative z-10 space-y-4 px-3">
<section id="faq" className="relative z-10 space-y-4 px-3">
<h2 className="text-center font-rock-n-roll-one text-3xl font-normal leading-tight tracking-wider text-neutral-50">
FAQ
</h2>
Expand Down
92 changes: 92 additions & 0 deletions src/components/common/navbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"use client";

import { useState } from "react";
import Image from "next/image";
import Link from "next/link";
import { useLenis } from "lenis/react";

import LogoMabim from "@/assets/logo-mabim.svg";
import { MenuIndicator } from "@/components/ornament/indicator";
import { Button, buttonVariants } from "@/components/ui/button";
import {
Sheet,
SheetContent,
SheetTrigger,
} from "@/components/ui/medieval-sheet";
import { cn } from "@/lib/utils";

const navLinks = [
{
name: "Beranda",
href: "#main",
},
{
name: "Countdown",
href: "#countdown",
},
{
name: "Kelompok",
href: "#kelompok",
},
{
name: "Timeline",
href: "#timeline",
},
{
name: "FAQ",
href: "#faq",
},
];

export function Navbar() {
const lenis = useLenis();
const [isOpen, setIsOpen] = useState(false);

return (
<div className="fixed left-0 right-0 top-0 z-50 mx-auto">
<nav className="container flex items-center justify-between bg-primary-950">
<div className="flex items-center gap-x-4">
<div className="relative h-12 w-12">
<Image
// eslint-disable-next-line
src={LogoMabim}
alt="Logo Mabim"
className="absolute -bottom-2 left-0 h-12 w-12"
/>
</div>
<h3 className="font-zelda text-2xl tracking-tight text-primary-50">
MABIMRPL 2024
</h3>
</div>

<Sheet open={isOpen} onOpenChange={setIsOpen}>
<SheetTrigger asChild>
<Button size="icon" className="bg-primary-950 hover:bg-primary-900">
<MenuIndicator pathClassName="fill-primary-50" />
</Button>
</SheetTrigger>
<SheetContent>
<div className="relative z-50 mt-4 flex flex-col gap-4 text-neutral-50">
{navLinks.map((link) => (
<Link
key={link.name}
href={link.href}
className={cn(buttonVariants(), "w-full")}
onClick={(e) => {
e.preventDefault();
setIsOpen(false);
lenis?.scrollTo(link.href, {
offset: link.href !== "#main" ? -64 : 0,
});
}}
>
{link.name}
</Link>
))}
</div>
</SheetContent>
</Sheet>
</nav>
</div>
);
}
7 changes: 5 additions & 2 deletions src/components/ui/countdown-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export function CountdownTabs({ tabs }: TabsProps) {
const [activeTab, setActiveTab] = useState(0);

return (
<div className="relative z-10 flex flex-col items-center space-y-4 px-3 py-6">
<section
id="countdown"
className="relative z-10 flex flex-col items-center space-y-4 px-3 py-6"
>
<h2 className="pb-4 text-center font-rock-n-roll-one text-3xl font-normal leading-tight tracking-wider text-neutral-50">
COUNTDOWN
</h2>
Expand Down Expand Up @@ -123,7 +126,7 @@ export function CountdownTabs({ tabs }: TabsProps) {
<p className="w-full text-right font-bonobo text-sm text-neutral-300">
*Geser tab untuk melihat hari lainnya
</p>
</div>
</section>
);
}

Expand Down
173 changes: 173 additions & 0 deletions src/components/ui/medieval-sheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
"use client";

import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { AnimatePresence, motion } from "framer-motion";

import {
BottomLeftCorner,
BottomRightCorner,
TopLeftCorner,
TopRightCorner,
} from "@/components/ornament/border";
import { cn } from "@/lib/utils";
import * as SheetPrimitive from "@radix-ui/react-dialog";
import { Cross2Icon } from "@radix-ui/react-icons";

const Sheet = SheetPrimitive.Root;

const SheetTrigger = SheetPrimitive.Trigger;

const SheetClose = SheetPrimitive.Close;

const SheetPortal = SheetPrimitive.Portal;

const SheetOverlay = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Overlay
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className,
)}
{...props}
ref={ref}
/>
));
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName;

const sheetVariants = cva(
"fixed z-50 gap-4 text-neutral-50 bg-neutral-900 pt-12 px-6 pb-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
{
variants: {
side: {
top: "inset-x-0 top-0 data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",
bottom:
"inset-x-0 bottom-0 data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",
left: "inset-y-0 left-0 h-full w-3/4 data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",
right:
"inset-y-0 right-0 h-full w-3/4 data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",
},
},
defaultVariants: {
side: "right",
},
},
);

interface SheetContentProps
extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,
VariantProps<typeof sheetVariants> {}

const SheetContent = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Content>,
SheetContentProps
>(({ side = "right", className, children, ...props }, ref) => (
<SheetPortal>
<SheetOverlay />
<SheetPrimitive.Content
ref={ref}
className={cn(sheetVariants({ side }), className)}
{...props}
>
<AnimatePresence>
<motion.div
className="absolute inset-0 m-2 border border-neutral-100/25"
initial={{ opacity: 0, scale: 0.95 }}
animate={{ opacity: 1, scale: 1 }}
exit={{ opacity: 0, scale: 0.95 }}
transition={{ duration: 0.3 }}
>
<TopLeftCorner
pathClassName="fill-neutral-100"
className="absolute -left-2 -top-2 scale-50"
/>
<TopRightCorner
pathClassName="fill-neutral-100"
className="absolute -right-2 -top-2 scale-50"
/>
<BottomLeftCorner
pathClassName="fill-neutral-100"
className="absolute -bottom-2 -left-2 scale-50"
/>
<BottomRightCorner
pathClassName="fill-neutral-100"
className="absolute -bottom-2 -right-2 scale-50"
/>
</motion.div>
</AnimatePresence>
{children}
<SheetPrimitive.Close className="absolute right-6 top-6 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
<Cross2Icon className="h-4 w-4" />
<span className="sr-only">Close</span>
</SheetPrimitive.Close>
</SheetPrimitive.Content>
</SheetPortal>
));
SheetContent.displayName = SheetPrimitive.Content.displayName;

const SheetHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-2 text-center sm:text-left",
className,
)}
{...props}
/>
);
SheetHeader.displayName = "SheetHeader";

const SheetFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className,
)}
{...props}
/>
);
SheetFooter.displayName = "SheetFooter";

const SheetTitle = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Title>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Title
ref={ref}
className={cn("text-lg font-semibold text-foreground", className)}
{...props}
/>
));
SheetTitle.displayName = SheetPrimitive.Title.displayName;

const SheetDescription = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Description>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
));
SheetDescription.displayName = SheetPrimitive.Description.displayName;

export {
Sheet,
SheetClose,
SheetContent,
SheetDescription,
SheetFooter,
SheetHeader,
SheetOverlay,
SheetPortal,
SheetTitle,
SheetTrigger,
};

0 comments on commit e863697

Please sign in to comment.