-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmobile-nav.js
More file actions
104 lines (97 loc) · 2.31 KB
/
mobile-nav.js
File metadata and controls
104 lines (97 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { ChevronDownIcon } from '@chakra-ui/icons'
import {
Collapse,
Flex,
Icon,
Stack,
Text,
useColorModeValue,
useDisclosure,
} from '@chakra-ui/react'
import { Link } from '@/components/mdx'
const MobileNavItem = ({ href, children, label }) => {
const { isOpen, onToggle } = useDisclosure()
const handleToggle = (e) => {
if (children) {
e.preventDefault()
onToggle()
}
}
return (
<Stack spacing={4} onClick={handleToggle}>
<Flex
py={2}
as={Link}
href={href ?? '/#'}
justify={'space-between'}
align={'center'}
_hover={{
textDecoration: 'none',
}}
>
<Text
fontWeight={600}
whiteSpace={'nowrap'}
color={useColorModeValue('gray.600', 'gray.200')}
>
{label}
</Text>
{children && (
<Icon
as={ChevronDownIcon}
transition={'all .25s ease-in-out'}
transform={isOpen ? 'rotate(180deg)' : ''}
w={6}
h={6}
/>
)}
</Flex>
<Collapse in={isOpen} animateOpacity style={{ marginTop: '0!important' }}>
<Stack
mt={2}
pl={4}
borderLeft={1}
borderStyle={'solid'}
whiteSpace={'nowrap'}
borderColor={useColorModeValue('gray.200', 'gray.700')}
align={'start'}
>
{' '}
{children &&
children.map((child, index) => (
<Link key={index} href={child.href ?? '#'} py={2}>
{child.label}
</Link>
))}
</Stack>
</Collapse>
</Stack>
)
}
export const MobileNav = ({ navItems, isOpen }) => {
if (!isOpen) return null
return (
<Stack
p={4}
display={{ md: 'none' }}
zIndex={9999}
pos='fixed'
top='60px'
w={'full'}
bg={'white'}
minH={'calc(100vh - 60px)'}
css={{
backdropFilter: 'saturate(180%) blur(5px)',
// eslint-disable-next-line react-hooks/rules-of-hooks
backgroundColor: useColorModeValue(
'rgba(255, 255, 255, 0.8)',
'rgba(26, 32, 44, 0.8)',
),
}}
>
{navItems.map((navItem) => (
<MobileNavItem key={navItem.label} {...navItem} />
))}
</Stack>
)
}