|
@ -4,8 +4,8 @@ import useLocation from "wouter/use-location"; |
|
|
|
|
|
|
|
|
import { ReactComponent as Logo } from "../assets/logo.svg"; |
|
|
import { ReactComponent as Logo } from "../assets/logo.svg"; |
|
|
import { ReactComponent as Right } from "../assets/arrow-right.svg"; |
|
|
import { ReactComponent as Right } from "../assets/arrow-right.svg"; |
|
|
import { getTimeout } from "../util"; |
|
|
import { get, getTimeout } from "../util"; |
|
|
import Menu from "./Menu"; |
|
|
import Menu, { MenuEntries } from "./Menu"; |
|
|
import useMediaQuery from "../util/useMediaQuery"; |
|
|
import useMediaQuery from "../util/useMediaQuery"; |
|
|
|
|
|
|
|
|
const [timer, clear] = getTimeout(); |
|
|
const [timer, clear] = getTimeout(); |
|
@ -17,18 +17,9 @@ const Container: React.FC<{ |
|
|
| React.ReactElement |
|
|
| React.ReactElement |
|
|
)[]; |
|
|
)[]; |
|
|
hideNav?: boolean; |
|
|
hideNav?: boolean; |
|
|
end?: boolean; |
|
|
|
|
|
next?: string; |
|
|
|
|
|
className?: string; |
|
|
className?: string; |
|
|
}> = ({ |
|
|
}> = ({ children: _children, hideNav = false, className, ...props }) => { |
|
|
children: _children, |
|
|
const [location, navigate] = useLocation(); |
|
|
hideNav = false, |
|
|
|
|
|
end = false, |
|
|
|
|
|
next, |
|
|
|
|
|
className, |
|
|
|
|
|
...props |
|
|
|
|
|
}) => { |
|
|
|
|
|
const [, navigate] = useLocation(); |
|
|
|
|
|
|
|
|
|
|
|
const mobile = useMediaQuery("(max-width: 50rem)"); |
|
|
const mobile = useMediaQuery("(max-width: 50rem)"); |
|
|
|
|
|
|
|
@ -116,10 +107,9 @@ const Container: React.FC<{ |
|
|
return () => window.removeEventListener("resize", handleResize); |
|
|
return () => window.removeEventListener("resize", handleResize); |
|
|
}, []); |
|
|
}, []); |
|
|
|
|
|
|
|
|
// on first render
|
|
|
type MouseKb = React.MouseEvent | React.KeyboardEvent | KeyboardEvent; |
|
|
useLayoutEffect(handleResize, []); |
|
|
|
|
|
|
|
|
|
|
|
const handleNext: React.MouseEventHandler<HTMLButtonElement> = e => { |
|
|
const animateArrow = (e: MouseKb) => { |
|
|
if (containerChild.current) { |
|
|
if (containerChild.current) { |
|
|
( |
|
|
( |
|
|
[...containerChild.current.children] as (HTMLElement | SVGElement)[] |
|
|
[...containerChild.current.children] as (HTMLElement | SVGElement)[] |
|
@ -130,10 +120,46 @@ const Container: React.FC<{ |
|
|
} |
|
|
} |
|
|
document.body.style.maxHeight = "100vh"; |
|
|
document.body.style.maxHeight = "100vh"; |
|
|
document.body.style.overflow = "hidden"; |
|
|
document.body.style.overflow = "hidden"; |
|
|
e.currentTarget.style.width = "0"; |
|
|
try { |
|
|
|
|
|
const target = e.currentTarget! as HTMLButtonElement; |
|
|
|
|
|
target.style.width = "0"; |
|
|
|
|
|
} catch {} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const current = MenuEntries.findIndex(([, path]) => location === path); |
|
|
|
|
|
const next = get.next(MenuEntries, current)[1]; |
|
|
|
|
|
const prev = get.prev(MenuEntries, current)[1]; |
|
|
|
|
|
const end = current === MenuEntries.length - 1; |
|
|
|
|
|
|
|
|
|
|
|
const handlePrev = (e: MouseKb) => { |
|
|
|
|
|
animateArrow(e); |
|
|
|
|
|
timer(() => prev && navigate(prev), 300); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const handleNext = (e: MouseKb) => { |
|
|
|
|
|
animateArrow(e); |
|
|
timer(() => next && navigate(next), 300); |
|
|
timer(() => next && navigate(next), 300); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function kbnav(e: KeyboardEvent) { |
|
|
|
|
|
switch (e.key) { |
|
|
|
|
|
case "ArrowLeft": |
|
|
|
|
|
return handlePrev(e); |
|
|
|
|
|
case "ArrowRight": |
|
|
|
|
|
return handleNext(e); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
window.addEventListener("keydown", kbnav); |
|
|
|
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
|
|
return () => window.removeEventListener("keydown", kbnav); |
|
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
// on first render
|
|
|
|
|
|
useLayoutEffect(handleResize, []); |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<div |
|
|
<div |
|
|
className={css` |
|
|
className={css` |
|
@ -247,7 +273,6 @@ const Container: React.FC<{ |
|
|
<Menu show={showMenu} setShowMenu={setShowMenu} /> |
|
|
<Menu show={showMenu} setShowMenu={setShowMenu} /> |
|
|
</span> |
|
|
</span> |
|
|
)} |
|
|
)} |
|
|
{next && ( |
|
|
|
|
|
<button |
|
|
<button |
|
|
onClick={handleNext} |
|
|
onClick={handleNext} |
|
|
ref={nextBtn} |
|
|
ref={nextBtn} |
|
@ -281,7 +306,6 @@ const Container: React.FC<{ |
|
|
`}
|
|
|
`}
|
|
|
/> |
|
|
/> |
|
|
</button> |
|
|
</button> |
|
|
)} |
|
|
|
|
|
<div |
|
|
<div |
|
|
className={cx( |
|
|
className={cx( |
|
|
css` |
|
|
css` |
|
|