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
+90 -78

No files matched your search

+88 -77
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,8 +54,86 @@ export default function Navbar() {
} }
}); });
const plugs = ( return (
<> <Box
style={{
position: 'fixed',
top: 0,
left: 0,
width: '100%',
maxHeight:
showHamburgerMenu && !wideFormat ? '100%' : NAVBAR_HEIGHT + 1,
zIndex: 2,
padding: '1rem',
background: theme.colors.appBackground1_alpha,
borderBottom: theme.borderStyles.nonInteractive,
backdropFilter: 'blur(4rem)',
WebkitBackdropFilter: 'blur(4rem)',
boxSizing: 'border-box',
transition: 'max-height 0.2s ease-in-out',
overflow: 'hidden',
}}
>
<Flex direction="column" align="center" pt="2">
<Flex
justify="between"
align="center"
style={{ maxWidth: 800, width: '100%', padding: '0 16px' }}
gap="8"
>
<Flex align="center" gap="4">
{!wideFormat && (
<IconButton
size="4"
variant="ghost"
color="gray"
onClick={() => setShowHamburgerMenu((state) => !state)}
>
{showHamburgerMenu ? <Cross1Icon /> : <HamburgerMenuIcon />}
</IconButton>
)}
<Link
onClick={() => setShowHamburgerMenu(false)}
href="/"
style={{
color: 'inherit',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<BlitzkitWide />
</Link>
</Flex>
{wideFormat && (
<Flex justify="center" gap="4">
{TOOLS.filter((tool) => !tool.href).map((tool) => {
const selected = pathname.startsWith(`/tools/${tool.id}`);
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 <Link
onClick={() => setShowHamburgerMenu(false)} onClick={() => setShowHamburgerMenu(false)}
href="https://discord.gg/nDt7AjGJQH" href="https://discord.gg/nDt7AjGJQH"
@@ -82,78 +161,10 @@ export default function Navbar() {
> >
<PatreonIcon width={14} height={14} /> <PatreonIcon width={14} height={14} />
</Link> </Link>
</>
);
return (
<Box
ref={navbar}
style={{
position: 'fixed',
top: 0,
left: 0,
width: '100%',
maxHeight: showHamburgerMenu ? '100%' : NAVBAR_HEIGHT + 1, // extra pixel for frost bleeding
zIndex: 2,
padding: '1rem',
background: theme.colors.appBackground1_alpha,
borderBottom: theme.borderStyles.nonInteractive,
backdropFilter: 'blur(4rem)',
WebkitBackdropFilter: 'blur(4rem)',
boxSizing: 'border-box',
transition: 'max-height 0.5s ease',
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
justify="between"
align="center"
style={{ maxWidth: 1600, width: '100%', padding: '0 16px' }}
gap="4"
>
<IconButton
variant="ghost"
color="gray"
onClick={() => setShowHamburgerMenu((state) => !state)}
>
{showHamburgerMenu ? <Cross1Icon /> : <HamburgerMenuIcon />}
</IconButton>
<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)}> <Link href="/settings" onClick={() => setShowHamburgerMenu(false)}>
<Flex style={{ width: '100%', height: '100%' }} justify="center"> <Flex style={{ width: '100%', height: '100%' }} justify="center">
<IconButton variant="ghost" color="gray"> <IconButton size="4" variant="ghost" color="gray">
<GearIcon /> <GearIcon />
</IconButton> </IconButton>
</Flex> </Flex>
@@ -162,7 +173,7 @@ export default function Navbar() {
{login && ( {login && (
<Popover.Root> <Popover.Root>
<Popover.Trigger> <Popover.Trigger>
<IconButton variant="ghost" color="gray"> <IconButton size="4" variant="ghost" color="gray">
<PersonIcon /> <PersonIcon />
</IconButton> </IconButton>
</Popover.Trigger> </Popover.Trigger>
@@ -213,6 +224,7 @@ export default function Navbar() {
</Dialog.Root> </Dialog.Root>
)} )}
</Flex> </Flex>
</Flex>
<Flex mt="6" gap="3" justify="center" wrap="wrap"> <Flex mt="6" gap="3" justify="center" wrap="wrap">
{TOOLS.filter((tool) => !tool.href).map((tool) => ( {TOOLS.filter((tool) => !tool.href).map((tool) => (
@@ -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',