Spaces:
Running
Running
File size: 10,279 Bytes
21a686e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
"use client";
import { cn } from "@/lib/utils";
import { IconChevronDown, IconMenu2, IconX } from "@tabler/icons-react";
import { motion, AnimatePresence } from "motion/react";
import Image from "next/image";
import Link from "next/link";
import React, { useState } from "react";
export function NavbarWithChildren() {
return <Navbar />;
}
const Navbar = () => {
const navItems = [
{
name: "Services",
link: "#",
children: [
{ name: "Web Development", link: "#" },
{ name: "Interface Design", link: "#" },
{ name: "Search Engine Optimization", link: "#" },
{ name: "Branding", link: "#" },
],
},
{
name: "Products",
link: "#",
children: [
{ name: "Algochurn", link: "#" },
{ name: "Tailwind Master Kit", link: "#" },
],
},
{
name: "Pricing",
link: "#",
children: [
{ name: "Hobby", link: "#" },
{ name: "Individual", link: "#" },
{ name: "Team", link: "#" },
],
},
];
return (
<div className="w-full">
<DesktopNav navItems={navItems} />
<MobileNav navItems={navItems} />
</div>
);
};
const DesktopNav = ({ navItems }: any) => {
const [active, setActive] = useState<string | null>(null);
return (
<motion.div
className={cn(
"relative z-[60] mx-auto hidden w-full max-w-7xl flex-row items-center justify-between self-start rounded-full bg-white px-4 py-2 lg:flex dark:bg-neutral-950",
"sticky inset-x-0 top-40"
)}
>
<Logo />
<div className="hidden flex-1 flex-row items-center justify-center space-x-2 text-sm font-medium text-zinc-600 transition duration-200 hover:text-zinc-800 lg:flex lg:space-x-2">
<Menu setActive={setActive}>
<MenuItem setActive={setActive} active={active} item="Services">
<div className="flex flex-col space-y-4 text-sm">
<HoveredLink href="/#">Web Development</HoveredLink>
<HoveredLink href="/#">Interface Design</HoveredLink>
<HoveredLink href="/seo">Search Engine Optimization</HoveredLink>
<HoveredLink href="/branding">Branding</HoveredLink>
</div>
</MenuItem>
<MenuItem setActive={setActive} active={active} item="Products">
<div className="grid grid-cols-2 gap-10 p-4 text-sm">
<ProductItem
title="Algochurn"
href="https://algochurn.com"
src="https://assets.aceternity.com/demos/algochurn.webp"
description="Prepare for tech interviews like never before."
/>
<ProductItem
title="Tailwind Master Kit"
href="https://tailwindmasterkit.com"
src="https://assets.aceternity.com/demos/tailwindmasterkit.webp"
description="Production ready Tailwind css components for your next project"
/>
</div>
</MenuItem>
<MenuItem setActive={setActive} active={active} item="Pricing">
<div className="flex flex-col space-y-4 text-sm">
<HoveredLink href="/hobby">Hobby</HoveredLink>
<HoveredLink href="/individual">Individual</HoveredLink>
<HoveredLink href="/team">Team</HoveredLink>
<HoveredLink href="/enterprise">Enterprise</HoveredLink>
</div>
</MenuItem>
</Menu>
</div>
<button className="hidden rounded-full bg-black px-8 py-2 text-sm font-bold text-white shadow-[0px_-2px_0px_0px_rgba(255,255,255,0.4)_inset] md:block dark:bg-white dark:text-black">
Book a call
</button>
</motion.div>
);
};
const MobileNav = ({ navItems }: any) => {
const [open, setOpen] = useState(false);
return (
<>
<motion.div
animate={{ borderRadius: open ? "4px" : "2rem" }}
key={String(open)}
className="relative mx-auto flex w-full max-w-[calc(100vw-2rem)] flex-col items-center justify-between bg-white px-4 py-2 lg:hidden dark:bg-neutral-950"
>
<div className="flex w-full flex-row items-center justify-between">
<Logo />
{open ? (
<IconX
className="text-black dark:text-white"
onClick={() => setOpen(!open)}
/>
) : (
<IconMenu2
className="text-black dark:text-white"
onClick={() => setOpen(!open)}
/>
)}
</div>
<AnimatePresence>
{open && (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
className="absolute inset-x-0 top-16 z-20 flex w-full flex-col items-start justify-start gap-4 rounded-lg bg-white px-4 py-8 dark:bg-neutral-950"
>
{navItems.map((navItem: any, idx: number) => (
<div key={`navItem-${idx}`} className="w-full">
{navItem.children ? (
<MobileChildNavItems navItem={navItem} />
) : (
<Link
href={navItem.link}
className="relative text-neutral-600 dark:text-neutral-300"
>
<motion.span className="block">
{navItem.name}
</motion.span>
</Link>
)}
</div>
))}
<button className="w-full rounded-lg bg-black px-8 py-2 font-medium text-white shadow-[0px_-2px_0px_0px_rgba(255,255,255,0.4)_inset] dark:bg-white dark:text-black">
Book a call
</button>
</motion.div>
)}
</AnimatePresence>
</motion.div>
</>
);
};
const MobileChildNavItems = ({ navItem }: { navItem: any }) => {
const [open, setOpen] = useState(false);
return (
<motion.div className="overflow-hidden">
<button
onClick={() => setOpen(!open)}
className="relative flex w-full justify-between text-neutral-600 dark:text-neutral-300"
>
<motion.span className="block">{navItem.name}</motion.span>
<IconChevronDown className="text-neutral-700 dark:text-neutral-300" />
</button>
<AnimatePresence>
{open && (
<motion.div
initial={{ height: 0, opacity: 0 }}
animate={{ height: "auto", opacity: 1 }}
exit={{ height: 0 }}
className="pl-4"
>
{navItem.children.map((child: any, childIdx: number) => (
<Link
key={`child-${childIdx}`}
href={child.link}
className="relative text-neutral-600 dark:text-neutral-300"
>
<motion.span className="block">{child.name}</motion.span>
</Link>
))}
</motion.div>
)}
</AnimatePresence>
</motion.div>
);
};
const Logo = () => {
return (
<Link
href="/"
className="relative z-20 mr-4 flex items-center space-x-2 px-2 py-1 text-sm font-normal text-black"
>
<Image
src="https://assets.aceternity.com/logo-dark.png"
alt="logo"
width={30}
height={30}
/>
<span className="font-medium text-black dark:text-white">DevStudio</span>
</Link>
);
};
const transition = {
mass: 0.5,
damping: 11.5,
stiffness: 100,
restDelta: 0.001,
restSpeed: 0.001,
};
export const MenuItem = ({
setActive,
active,
item,
children,
}: {
setActive: (item: string) => void;
active: string | null;
item: string;
children?: React.ReactNode;
}) => {
return (
<div onMouseEnter={() => setActive(item)} className="relative">
<motion.p
transition={{ duration: 0.3 }}
className="cursor-pointer text-neutral-700 hover:opacity-[0.9] dark:text-neutral-300"
>
{item}
</motion.p>
{active !== null && (
<motion.div
initial={{ opacity: 0, scale: 0.85, y: 10 }}
animate={{ opacity: 1, scale: 1, y: 0 }}
transition={transition}
>
{active === item && (
<div className="absolute left-1/2 top-[calc(100%_+_0.2rem)] -translate-x-1/2 transform pt-4">
<div className="">
<motion.div
transition={transition}
layoutId="active" // layoutId ensures smooth animation
className="mt-4 overflow-hidden rounded-2xl bg-white shadow-xl backdrop-blur-sm dark:bg-neutral-950"
>
<motion.div
layout // layout ensures smooth animation
className="h-full w-max p-4"
>
{children}
</motion.div>
</motion.div>
</div>
</div>
)}
</motion.div>
)}
</div>
);
};
export const Menu = ({
setActive,
children,
}: {
setActive: (item: string | null) => void;
children: React.ReactNode;
}) => {
return (
<nav
onMouseLeave={() => setActive(null)} // resets the state
className="relative flex justify-center space-x-4 rounded-full bg-white px-4 py-3 dark:bg-neutral-950"
>
{children}
</nav>
);
};
export const ProductItem = ({
title,
description,
href,
src,
}: {
title: string;
description: string;
href: string;
src: string;
}) => {
return (
<Link href={href} className="flex gap-4">
<Image
src={src}
width={140}
height={70}
alt={title}
className="flex-shrink-0 rounded-md shadow-2xl"
/>
<div>
<h4 className="mb-1 text-base font-normal text-black dark:text-white">
{title}
</h4>
<p className="max-w-[10rem] text-sm text-neutral-700 dark:text-neutral-300">
{description}
</p>
</div>
</Link>
);
};
export const HoveredLink = ({ children, ...rest }: any) => {
return (
<Link
{...rest}
className="text-neutral-700 hover:text-black dark:text-neutral-200"
>
{children}
</Link>
);
};
|