2024-03-23 22:19:49 +00:00
|
|
|
import React from "react"
|
|
|
|
import { Center, Text } from "@chakra-ui/react"
|
2023-06-28 01:12:17 +00:00
|
|
|
|
2024-03-23 22:19:49 +00:00
|
|
|
export const ReactiveRightNav = (props) => {
|
|
|
|
const setNav = React.useCallback((active) => {
|
|
|
|
setMr(active ? "0%" : "-100%")
|
2023-06-28 01:12:17 +00:00
|
|
|
setNavActive(active)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
const [entered, setEntered] = React.useState(false)
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
// react to mouse move event
|
2024-03-23 22:19:49 +00:00
|
|
|
const listener = (event) => {
|
2023-06-28 01:12:17 +00:00
|
|
|
const windowWidth = window.innerWidth
|
|
|
|
if (!entered) {
|
|
|
|
if (event?.clientX >= windowWidth - 60) {
|
|
|
|
setNav(true)
|
|
|
|
} else if (event?.clientX <= windowWidth - 100) {
|
|
|
|
setNav(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-23 22:19:49 +00:00
|
|
|
window.addEventListener("mousemove", listener)
|
2023-06-28 01:12:17 +00:00
|
|
|
return () => {
|
2024-03-23 22:19:49 +00:00
|
|
|
window.removeEventListener("mousemove", listener)
|
2023-06-28 01:12:17 +00:00
|
|
|
}
|
|
|
|
}, [setNav, entered])
|
|
|
|
|
|
|
|
const [navActive, setNavActive] = React.useState(false)
|
|
|
|
|
|
|
|
// const defaultMr = '-100%'
|
2024-03-23 22:19:49 +00:00
|
|
|
const defaultMr = "0%"
|
2023-06-28 01:12:17 +00:00
|
|
|
|
|
|
|
const [mr, setMr] = React.useState(defaultMr)
|
|
|
|
|
|
|
|
const navItems = React.useMemo(() => {
|
2024-03-23 22:19:49 +00:00
|
|
|
return ["home", "imagine", "create", "share"]
|
2023-06-28 01:12:17 +00:00
|
|
|
}, [])
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Center
|
2024-03-23 22:19:49 +00:00
|
|
|
position="fixed"
|
2023-06-28 01:12:17 +00:00
|
|
|
top={0}
|
|
|
|
right={0}
|
2024-03-23 22:19:49 +00:00
|
|
|
flexDirection="column"
|
|
|
|
height="100%"
|
|
|
|
marginRight={mr}
|
|
|
|
transition="all 0.3s ease-in-out"
|
2023-06-28 01:12:17 +00:00
|
|
|
>
|
|
|
|
<Center
|
2024-03-23 22:19:49 +00:00
|
|
|
flexDirection="column"
|
|
|
|
minWidth="600px"
|
|
|
|
maxWidth="100%"
|
|
|
|
height="85%"
|
|
|
|
background="rgba(0, 0, 0, 0.01)"
|
|
|
|
borderLeftRadius="40px"
|
2023-06-28 01:12:17 +00:00
|
|
|
onMouseEnter={() => setEntered(true)}
|
|
|
|
onMouseLeave={() => setEntered(false)}
|
2024-03-23 22:19:49 +00:00
|
|
|
paddingX={100}
|
|
|
|
paddingY={80}
|
2023-06-28 01:12:17 +00:00
|
|
|
>
|
|
|
|
{navItems.map((navItem, idx) => {
|
|
|
|
return (
|
|
|
|
<Text
|
|
|
|
key={idx}
|
2024-03-23 22:19:49 +00:00
|
|
|
as="h2"
|
|
|
|
color="black"
|
|
|
|
fontSize="30px"
|
|
|
|
fontWeight="semibold"
|
|
|
|
textTransform="capitalize"
|
|
|
|
cursor="pointer"
|
|
|
|
marginY="auto"
|
2023-06-28 01:12:17 +00:00
|
|
|
>
|
|
|
|
{navItem}
|
|
|
|
</Text>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</Center>
|
|
|
|
</Center>
|
|
|
|
)
|
|
|
|
}
|