Skip to content

Commit

Permalink
Merge pull request #465 from Raiden0456/navbar-remake
Browse files Browse the repository at this point in the history
feat(NavBar mobile): New Navbar for mobile
  • Loading branch information
mauro-balades authored Feb 9, 2025
2 parents 1d03ea9 + 8e34c44 commit 0bd8d62
Show file tree
Hide file tree
Showing 11 changed files with 406 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"date-fns": "^4.1.0",
"free-astro-components": "^1.1.1",
"lucide-astro": "^0.460.0",
"lucide-react": "^0.474.0",
"motion": "^11.13.5",
"postcss": "8.4.21",
"prettier": "^3.3.3",
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

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

6 changes: 3 additions & 3 deletions src/animations.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export function getTitleAnimation(delay = 0) {
export function getTitleAnimation(delay = 0, duration = 0.3, once = true) {
return {
initial: { opacity: 0, translateY: 20, filter: 'blur(4px)' },
whileInView: {
opacity: 1,
translateY: 0,
filter: 'blur(0px)',
transition: { duration: 0.3, delay },
transition: { duration, delay },
},
viewport: { once: true },
viewport: { once: once },
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/components/Logo.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---
const { class: className } = Astro.props
---

<svg
class={className}
width="32"
height="32"
viewBox="0 0 64 64"
Expand Down
159 changes: 159 additions & 0 deletions src/components/MobileNavBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import React, { useState } from 'react'
import MyLogo from './Mylogo'
import { Menu } from 'lucide-react'
import ThemeSwitch from './ThemeSwitch/ThemeSwitch'

const MobileNavbar: React.FC = () => {
const [isMenuOpen, setMenuOpen] = useState(false)

const menuTransformClass = isMenuOpen ? 'translate-x-0' : 'translate-x-full'

return (
<div className="lg:hidden">
{/* Mobile Header */}
<header className="flex items-center justify-between bg-paper px-4 py-2">
<a className="flex items-center gap-2" href="/">
<MyLogo className="h-8 w-8 text-coral" />
<span className="text-lg font-bold">zen browser</span>
</a>
<div className="flex flex-row gap-2">
<ThemeSwitch />
<button
id="burger-btn"
className="p-2 text-dark"
aria-label="Open menu"
onClick={() => setMenuOpen(true)}
>
<Menu className="h-6 w-6" />
</button>
</div>
</header>

{/* Mobile Slide Menu (slides in from the right) */}
<div
id="mobile-menu"
className={`fixed inset-y-0 right-0 z-40 w-64 transform bg-paper shadow-lg transition-transform duration-300 ${menuTransformClass}`}
>
<div className="flex items-center justify-between border-b border-dark px-4 py-2">
<div className="text-lg font-bold">Menu</div>
<button
id="close-btn"
className="p-2 text-dark"
aria-label="Close menu"
onClick={() => setMenuOpen(false)}
>
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
</div>
<nav className="px-4 py-2">
<ul className="space-y-4">
{/* Getting Started Links */}
<li>
<div className="mb-2 font-bold">Getting Started</div>
<ul className="ml-4 space-y-2">
<li>
<a href="/mods" className="block text-dark hover:text-coral">
Zen Mods
</a>
</li>
<li>
<a
href="/release-notes"
className="block text-dark hover:text-coral"
>
Release Notes
</a>
</li>
<li>
<a
href="https://discord.gg/zen-browser"
className="block text-dark hover:text-coral"
>
Discord
</a>
</li>
</ul>
</li>
{/* Useful Links */}
<li>
<div className="mb-2 font-bold">Useful Links</div>
<ul className="ml-4 space-y-2">
<li>
<a
href="/donate"
className="block text-dark hover:text-coral"
>
Donate ❤️
</a>
</li>
<li>
<a href="/about" className="block text-dark hover:text-coral">
About Us 🌟
</a>
</li>
<li>
<a
href="https://docs.zen-browser.app"
className="block text-dark hover:text-coral"
>
Documentation
</a>
</li>
<li>
<a
href="https://github.com/zen-browser"
target="_blank"
className="block text-dark hover:text-coral"
>
GitHub
</a>
</li>
</ul>
</li>
{/* Extra Links */}
<li>
<a
href="/mods"
className="block font-bold text-dark hover:text-coral"
>
Mods
</a>
</li>
<li>
<a
href="/download"
className="block font-bold text-dark hover:text-coral"
>
Download
</a>
</li>
</ul>
</nav>
</div>

{/* Overlay for Mobile Menu */}
{isMenuOpen && (
<div
id="overlay"
className="fixed inset-0 z-30 bg-black opacity-50"
onClick={() => setMenuOpen(false)}
/>
)}
</div>
)
}

export default MobileNavbar
37 changes: 37 additions & 0 deletions src/components/Mylogo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react'

interface MyLogoProps {
className?: string
}

const MyLogo: React.FC<MyLogoProps> = ({ className }) => (
<svg
className={className}
width="32"
height="32"
viewBox="0 0 64 64"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M32 44.3077C38.7974 44.3077 44.3077 38.7974 44.3077 32C44.3077 25.2027 38.7974 19.6923 32 19.6923C25.2027 19.6923 19.6923 25.2027 19.6923 32C19.6923 38.7974 25.2027 44.3077 32 44.3077ZM41.8462 32C41.8462 37.4379 37.4379 41.8462 32 41.8462C26.5621 41.8462 22.1538 37.4379 22.1538 32C22.1538 26.5621 26.5621 22.1538 32 22.1538C37.4379 22.1538 41.8462 26.5621 41.8462 32Z"
fill="currentColor"
/>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M53.3333 32C53.3333 43.7821 43.7821 53.3333 32 53.3333C20.2179 53.3333 10.6667 43.7821 10.6667 32C10.6667 20.2179 20.2179 10.6667 32 10.6667C43.7821 10.6667 53.3333 20.2179 53.3333 32ZM32 49.2308C41.5163 49.2308 49.2308 41.5163 49.2308 32C49.2308 22.4837 41.5163 14.7692 32 14.7692C22.4837 14.7692 14.7692 22.4837 14.7692 32C14.7692 41.5163 22.4837 49.2308 32 49.2308Z"
fill="currentColor"
/>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M64 32C64 49.6731 49.6731 64 32 64C14.3269 64 0 49.6731 0 32C0 14.3269 14.3269 0 32 0C49.6731 0 64 14.3269 64 32ZM32 58.2564C46.501 58.2564 58.2564 46.501 58.2564 32C58.2564 17.499 46.501 5.74359 32 5.74359C17.499 5.74359 5.74359 17.499 5.74359 32C5.74359 46.501 17.499 58.2564 32 58.2564Z"
fill="currentColor"
/>
</svg>
)

export default MyLogo
28 changes: 17 additions & 11 deletions src/components/NavBar.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
import { motion } from 'motion/react'
import Title from '../components/Title.astro'
import Description from '../components/Description.astro'
import Button from '../components/Button.astro'
Expand All @@ -13,18 +14,19 @@ import {
import { ArrowRight, ChevronDown, Download, DownloadCloud } from 'lucide-astro'
import Logo from './Logo.astro'
import { ThemeSwitch } from 'free-astro-components'
import { getTitleAnimation } from '../animations.ts'
---

<nav
id="nav-bar"
class="relative z-20 flex w-full items-center justify-between lg:px-6 lg:pt-3"
class="relative z-20 hidden w-full items-center justify-between lg:flex lg:px-6 lg:pt-3"
>
<Astronav>
<MenuItems
class="relative mx-auto flex w-full gap-2 bg-paper p-2 lg:w-3/4 lg:min-w-fit"
class="relative mx-auto flex w-full justify-between gap-2 bg-paper p-2 lg:w-3/4 lg:min-w-fit"
>
<a class="flex items-center gap-2 text-lg font-bold" href="/">
<Logo class="text-dark" />
<Logo class="text-coral" />
<span class="hidden lg:block">zen browser</span>
</a>
<div class="mx-auto flex">
Expand All @@ -37,8 +39,10 @@ import { ThemeSwitch } from 'free-astro-components'
/>
</button>
<DropdownItems>
<div
class="navbar-dropdown left-0 right-1/4 top-16 w-full lg:w-fit"
<motion.div
className="navbar-dropdown"
{...getTitleAnimation(0, 0.3, false)}
client:load
>
<a class="dropdown-item bg-dark/5 row-span-2" href="/mods">
<div class="dropdown-title">Zen Mods</div>
Expand All @@ -62,7 +66,7 @@ import { ThemeSwitch } from 'free-astro-components'
Join our community on Discord to chat with other Zen users!
</div>
</a>
</div>
</motion.div>
</DropdownItems>
</Dropdown>
<Dropdown class="group">
Expand All @@ -73,8 +77,10 @@ import { ThemeSwitch } from 'free-astro-components'
/>
</button>
<DropdownItems>
<div
class="navbar-dropdown left-0 top-16 w-full !grid-cols-1 gap-1 lg:left-1/3 lg:right-1/4 lg:w-fit"
<motion.div
className="navbar-dropdown !grid-cols-1 gap-1"
{...getTitleAnimation(0, 0.3, false)}
client:load
>
<a class="dropdown-item" href="/donate">
<div class="dropdown-title">Donate ❤️</div>
Expand Down Expand Up @@ -104,7 +110,7 @@ import { ThemeSwitch } from 'free-astro-components'
Contribute to the development of Zen Browser on GitHub.
</div>
</a>
</div>
</motion.div>
</DropdownItems>
</Dropdown>
<a class="hidden items-center lg:block" href="/mods">
Expand All @@ -129,10 +135,10 @@ import { ThemeSwitch } from 'free-astro-components'
</MenuItems>
</Astronav>
</nav>

<style>
.navbar-dropdown {
@apply absolute grid grid-cols-2 gap-2 rounded-lg border-2 border-dark bg-paper p-3 shadow-sm;

@apply absolute left-1/2 mt-2 grid !-translate-x-1/2 !transform grid-cols-2 gap-2 rounded-lg border-2 border-dark bg-paper p-3 shadow-sm;
& .dropdown-item {
@apply flex cursor-pointer select-none flex-col gap-2 rounded-lg p-4 transition-colors duration-200;

Expand Down
Loading

0 comments on commit 0bd8d62

Please sign in to comment.