feat: clone navbar

This commit is contained in:
TrèsAbhi committed 2024-05-20 12:30:22 -05:00
1 parent 4062a09c05
commit bde1bd279d
1 file changed
+20 -6
+20 -6
View File
@@ -18,7 +18,7 @@ import {
Text, Text,
} from '@radix-ui/themes'; } from '@radix-ui/themes';
import Link from 'next/link'; import Link from 'next/link';
import { Suspense, useEffect, useState } from 'react'; import { Suspense, useEffect, useRef, 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';
@@ -37,7 +37,8 @@ export const NAVBAR_HEIGHT = 64;
export default function Navbar() { export default function Navbar() {
const wideFormat = useWideFormat(480); const wideFormat = useWideFormat(480);
const login = useApp((state) => state.login); const login = useApp((state) => state.login);
const [showHamburgerMenu, setShowHamburgerMenu] = useState(true); const [showHamburgerMenu, setShowHamburgerMenu] = useState(false);
const navbar = useRef<HTMLDivElement>(null);
useEffect(() => { useEffect(() => {
if (!login) return; if (!login) return;
@@ -85,8 +86,8 @@ export default function Navbar() {
); );
return ( return (
<>
<Box <Box
ref={navbar}
style={{ style={{
position: 'fixed', position: 'fixed',
top: 0, top: 0,
@@ -103,7 +104,19 @@ export default function Navbar() {
overflow: 'hidden', overflow: 'hidden',
}} }}
onPointerEnter={() => setShowHamburgerMenu(true)} onPointerEnter={() => setShowHamburgerMenu(true)}
onPointerLeave={() => setShowHamburgerMenu(false)} 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
@@ -213,7 +226,9 @@ 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,
width: 144, minWidth: 144,
maxWidth: 192,
flex: 1,
borderRadius: 8, borderRadius: 8,
textDecoration: 'none', textDecoration: 'none',
backgroundSize: 'cover', backgroundSize: 'cover',
@@ -243,6 +258,5 @@ export default function Navbar() {
</Flex> </Flex>
</Flex> </Flex>
</Box> </Box>
</>
); );
} }