feat: apple inspired navbar

This commit is contained in:
TrèsAbhi committed 2024-05-20 13:33:32 -05:00
1 parent 1db7354c1b
commit a7b2a0abe9
2 files changed
+152 -140

No files matched your search

+150 -139
View File
@@ -18,7 +18,8 @@ import {
Text, Text,
} from '@radix-ui/themes'; } from '@radix-ui/themes';
import Link from 'next/link'; import Link from 'next/link';
import { Suspense, useEffect, useRef, useState } from 'react'; import { usePathname } from 'next/navigation';
import { Suspense, useEffect, useState } from 'react';
import * as styles from '../../app/page.css'; import * as styles from '../../app/page.css';
import { REGIONS, UNLOCALIZED_REGION_NAMES } from '../../constants/regions'; import { REGIONS, UNLOCALIZED_REGION_NAMES } from '../../constants/regions';
import { TOOLS } from '../../constants/tools'; import { TOOLS } from '../../constants/tools';
@@ -35,10 +36,10 @@ import { LoggedIn } from './components/LoggedIn';
export const NAVBAR_HEIGHT = 64; export const NAVBAR_HEIGHT = 64;
export default function Navbar() { export default function Navbar() {
const wideFormat = useWideFormat(480); const wideFormat = useWideFormat(688 - 32 - 64);
const login = useApp((state) => state.login); const login = useApp((state) => state.login);
const [showHamburgerMenu, setShowHamburgerMenu] = useState(false); const [showHamburgerMenu, setShowHamburgerMenu] = useState(false);
const navbar = useRef<HTMLDivElement>(null); const pathname = usePathname();
useEffect(() => { useEffect(() => {
if (!login) return; if (!login) return;
@@ -53,47 +54,15 @@ export default function Navbar() {
} }
}); });
const plugs = (
<>
<Link
onClick={() => setShowHamburgerMenu(false)}
href="https://discord.gg/nDt7AjGJQH"
target="_blank"
style={{
color: 'inherit',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<DiscordLogoIcon width={16} height={16} />
</Link>
<Link
onClick={() => setShowHamburgerMenu(false)}
href="https://www.patreon.com/tresabhi"
target="_blank"
style={{
color: 'inherit',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<PatreonIcon width={14} height={14} />
</Link>
</>
);
return ( return (
<Box <Box
ref={navbar}
style={{ style={{
position: 'fixed', position: 'fixed',
top: 0, top: 0,
left: 0, left: 0,
width: '100%', width: '100%',
maxHeight: showHamburgerMenu ? '100%' : NAVBAR_HEIGHT + 1, // extra pixel for frost bleeding maxHeight:
showHamburgerMenu && !wideFormat ? '100%' : NAVBAR_HEIGHT + 1,
zIndex: 2, zIndex: 2,
padding: '1rem', padding: '1rem',
background: theme.colors.appBackground1_alpha, background: theme.colors.appBackground1_alpha,
@@ -101,117 +70,160 @@ export default function Navbar() {
backdropFilter: 'blur(4rem)', backdropFilter: 'blur(4rem)',
WebkitBackdropFilter: 'blur(4rem)', WebkitBackdropFilter: 'blur(4rem)',
boxSizing: 'border-box', boxSizing: 'border-box',
transition: 'max-height 0.5s ease', transition: 'max-height 0.2s ease-in-out',
overflow: 'hidden', overflow: 'hidden',
}} }}
onPointerEnter={() => setShowHamburgerMenu(true)}
onPointerLeave={(event) => {
if (
navbar.current ===
document.elementFromPoint(event.clientX, event.clientY)
) {
// false positive bug: https://stackoverflow.com/a/45267167/12294756
return;
}
setShowHamburgerMenu(false);
}}
onFocus={() => setShowHamburgerMenu(true)}
onBlur={() => setShowHamburgerMenu(false)}
> >
<Flex direction="column" align="center" pt="2"> <Flex direction="column" align="center" pt="2">
<Flex <Flex
justify="between" justify="between"
align="center" align="center"
style={{ maxWidth: 1600, width: '100%', padding: '0 16px' }} style={{ maxWidth: 800, width: '100%', padding: '0 16px' }}
gap="4" gap="8"
> >
<IconButton <Flex align="center" gap="4">
variant="ghost" {!wideFormat && (
color="gray" <IconButton
onClick={() => setShowHamburgerMenu((state) => !state)} size="4"
> variant="ghost"
{showHamburgerMenu ? <Cross1Icon /> : <HamburgerMenuIcon />} color="gray"
</IconButton> onClick={() => setShowHamburgerMenu((state) => !state)}
<Link
onClick={() => setShowHamburgerMenu(false)}
href="/"
style={{
color: 'inherit',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<BlitzkitWide />
</Link>
<div style={{ flex: 1 }} />
{wideFormat && plugs}
<Link href="/settings" onClick={() => setShowHamburgerMenu(false)}>
<Flex style={{ width: '100%', height: '100%' }} justify="center">
<IconButton variant="ghost" color="gray">
<GearIcon />
</IconButton>
</Flex>
</Link>
{login && (
<Popover.Root>
<Popover.Trigger>
<IconButton variant="ghost" color="gray">
<PersonIcon />
</IconButton>
</Popover.Trigger>
<Popover.Content align="center">
<Flex direction="column" gap="2">
<Suspense fallback={<Spinner />}>
<LoggedIn />
</Suspense>
</Flex>
</Popover.Content>
</Popover.Root>
)}
{/* TODO: re-enable in the future */}
{!login && false && (
<Dialog.Root>
<Dialog.Trigger>
<Button variant="ghost">Log in</Button>
</Dialog.Trigger>
<Dialog.Content
style={{
maxWidth: 360,
}}
> >
<Flex direction="column" gap="2" align="center"> {showHamburgerMenu ? <Cross1Icon /> : <HamburgerMenuIcon />}
<Heading size="3">Choose your region</Heading> </IconButton>
)}
<Flex gap="4" align="center" justify="center" wrap="wrap"> <Link
{REGIONS.map((region) => ( onClick={() => setShowHamburgerMenu(false)}
<LinkRadix href="/"
onClick={() => setShowHamburgerMenu(false)} style={{
key={region} color: 'inherit',
href={authURL( display: 'flex',
region, alignItems: 'center',
typeof window === 'undefined' justifyContent: 'center',
? undefined }}
: location.href, >
)} <BlitzkitWide />
> </Link>
{UNLOCALIZED_REGION_NAMES[region]} </Flex>
</LinkRadix>
))} {wideFormat && (
</Flex> <Flex justify="center" gap="4">
</Flex> {TOOLS.filter((tool) => !tool.href).map((tool) => {
</Dialog.Content> const selected = pathname.startsWith(`/tools/${tool.id}`);
</Dialog.Root>
return (
<LinkRadix
color="gray"
underline={selected ? 'always' : 'hover'}
href="#"
size="1"
onClick={(event) => event.preventDefault()}
>
<Link
style={{ all: 'inherit' }}
key={tool.id}
href={`/tools/${tool.id}`}
>
{tool.title}
</Link>
</LinkRadix>
);
})}
</Flex>
)} )}
<Flex align="center" gap="4">
<Link
onClick={() => setShowHamburgerMenu(false)}
href="https://discord.gg/nDt7AjGJQH"
target="_blank"
style={{
color: 'inherit',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<DiscordLogoIcon width={16} height={16} />
</Link>
<Link
onClick={() => setShowHamburgerMenu(false)}
href="https://www.patreon.com/tresabhi"
target="_blank"
style={{
color: 'inherit',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<PatreonIcon width={14} height={14} />
</Link>
<Link href="/settings" onClick={() => setShowHamburgerMenu(false)}>
<Flex style={{ width: '100%', height: '100%' }} justify="center">
<IconButton size="4" variant="ghost" color="gray">
<GearIcon />
</IconButton>
</Flex>
</Link>
{login && (
<Popover.Root>
<Popover.Trigger>
<IconButton size="4" variant="ghost" color="gray">
<PersonIcon />
</IconButton>
</Popover.Trigger>
<Popover.Content align="center">
<Flex direction="column" gap="2">
<Suspense fallback={<Spinner />}>
<LoggedIn />
</Suspense>
</Flex>
</Popover.Content>
</Popover.Root>
)}
{/* TODO: re-enable in the future */}
{!login && false && (
<Dialog.Root>
<Dialog.Trigger>
<Button variant="ghost">Log in</Button>
</Dialog.Trigger>
<Dialog.Content
style={{
maxWidth: 360,
}}
>
<Flex direction="column" gap="2" align="center">
<Heading size="3">Choose your region</Heading>
<Flex gap="4" align="center" justify="center" wrap="wrap">
{REGIONS.map((region) => (
<LinkRadix
onClick={() => setShowHamburgerMenu(false)}
key={region}
href={authURL(
region,
typeof window === 'undefined'
? undefined
: location.href,
)}
>
{UNLOCALIZED_REGION_NAMES[region]}
</LinkRadix>
))}
</Flex>
</Flex>
</Dialog.Content>
</Dialog.Root>
)}
</Flex>
</Flex> </Flex>
<Flex mt="6" gap="3" justify="center" wrap="wrap"> <Flex mt="6" gap="3" justify="center" wrap="wrap">
@@ -227,8 +239,7 @@ export default function Navbar() {
cursor: tool.disabled ? 'default' : 'pointer', cursor: tool.disabled ? 'default' : 'pointer',
opacity: tool.disabled ? 0.25 : 1, opacity: tool.disabled ? 0.25 : 1,
height: 64, height: 64,
minWidth: 144, minWidth: 176,
maxWidth: 192,
flex: 1, flex: 1,
borderRadius: 8, borderRadius: 8,
textDecoration: 'none', textDecoration: 'none',
+2 -1
View File
@@ -38,8 +38,9 @@ export const TOOLS: Tool[] = [
'Compare tanks statistics and loadouts in World of Tanks Blitz', 'Compare tanks statistics and loadouts in World of Tanks Blitz',
}, },
{ {
// TODO: rename to tracker
id: 'session', id: 'session',
title: 'Session tracker', title: 'Session',
description: 'Live session performance tracker', description: 'Live session performance tracker',
pageDescription: pageDescription:
'Track your stats in real time as you play World of Tanks Blitz', 'Track your stats in real time as you play World of Tanks Blitz',