Skip to content

Commit 5821b37

Browse files
authored
Merge pull request #14495 from ashiskumar-1999/migrate-sideNavMobile.tsx-to-Shadcn/Tailwind
feat: Migrate SideNavMobile to Shadcn/Tailwind
2 parents 6f166f1 + c6b6260 commit 5821b37

File tree

1 file changed

+39
-85
lines changed

1 file changed

+39
-85
lines changed

src/components/SideNavMobile.tsx

Lines changed: 39 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import React, { useState } from "react"
22
import { AnimatePresence, motion } from "framer-motion"
33
import { useTranslation } from "next-i18next"
44
import { MdChevronRight } from "react-icons/md"
5-
import { Box, Center, HStack, Icon } from "@chakra-ui/react"
65

76
import type { ChildOnlyProp, TranslationKey } from "@/lib/types"
87
import { DeveloperDocsLink } from "@/lib/interfaces"
98

10-
import { BaseLink, LinkProps } from "@/components/Link"
11-
129
import docLinks from "@/data/developer-docs-links.yaml"
1310

11+
import { Center, HStack } from "./ui/flex"
12+
import { BaseLink, LinkProps } from "./ui/Link"
1413
import {
1514
dropdownIconContainerVariant,
1615
type NavLinkProps as SideNavLinkProps,
@@ -48,16 +47,7 @@ const innerLinksVariants = {
4847

4948
const LinkContainer = ({ children }: ChildOnlyProp) => {
5049
return (
51-
<HStack
52-
w="full"
53-
justify="space-between"
54-
py={2}
55-
pe={8}
56-
ps={2}
57-
_hover={{
58-
bgColor: "ednBackground",
59-
}}
60-
>
50+
<HStack className="w-full justify-between py-2 pe-8 ps-2 hover:bg-[ednBackground]">
6151
{children}
6252
</HStack>
6353
)
@@ -66,16 +56,7 @@ const LinkContainer = ({ children }: ChildOnlyProp) => {
6656
const SideNavLink = ({ children, ...props }: LinkProps) => {
6757
return (
6858
<BaseLink
69-
w="full"
70-
textDecoration="none"
71-
color="text"
72-
_hover={{
73-
textDecoration: "none",
74-
color: "primary.base",
75-
}}
76-
_active={{
77-
color: "primary.base",
78-
}}
59+
className="w-full text-body no-underline hover:text-primary"
7960
{...props}
8061
>
8162
{children}
@@ -93,35 +74,32 @@ const NavLink = ({ item, path, toggle }: NavLinkProps) => {
9374

9475
if (item.items) {
9576
return (
96-
<Box>
77+
<div>
9778
<LinkContainer>
9879
{item.href && (
9980
<SideNavLink href={item.href} isPartiallyActive={false}>
10081
{t(item.id)}
10182
</SideNavLink>
10283
)}
10384
{!item.href && (
104-
<Box w="full" cursor="pointer" onClick={() => setIsOpen(!isOpen)}>
85+
<div
86+
className="w-full cursor-pointer"
87+
onClick={() => setIsOpen(!isOpen)}
88+
>
10589
{t(item.id)}
106-
</Box>
90+
</div>
10791
)}
108-
<Box
109-
as={motion.div}
110-
cursor="pointer"
111-
display="flex"
92+
<motion.div
93+
className="flex cursor-pointer"
11294
onClick={() => setIsOpen(!isOpen)}
11395
variants={dropdownIconContainerVariant}
11496
animate={isOpen ? "open" : "closed"}
11597
>
116-
<Icon as={MdChevronRight} boxSize={6} color="secondary" />
117-
</Box>
98+
<MdChevronRight className="h-6 w-6 text-body-medium" />
99+
</motion.div>
118100
</LinkContainer>
119-
<Box
120-
as={motion.div}
121-
fontSize="sm"
122-
lineHeight="tall"
123-
fontWeight="normal"
124-
ps={4}
101+
<motion.div
102+
className="ps-4 text-sm font-normal leading-relaxed"
125103
key={item.id}
126104
animate={isOpen ? "open" : "closed"}
127105
variants={innerLinksVariants}
@@ -130,18 +108,18 @@ const NavLink = ({ item, path, toggle }: NavLinkProps) => {
130108
{item.items.map((childItem, idx) => (
131109
<NavLink item={childItem} path={path} key={idx} toggle={toggle} />
132110
))}
133-
</Box>
134-
</Box>
111+
</motion.div>
112+
</div>
135113
)
136114
}
137115
return (
138-
<Box onClick={toggle}>
116+
<div onClick={toggle}>
139117
<LinkContainer>
140118
<SideNavLink href={item.href} isPartiallyActive={false}>
141119
{t(item.id)}
142120
</SideNavLink>
143121
</LinkContainer>
144-
</Box>
122+
</div>
145123
)
146124
}
147125

@@ -160,50 +138,26 @@ const SideNavMobile = ({ path }: SideNavMobileProps) => {
160138
getPageTitleId(path + "/", docLinks) || ("Change page" as TranslationKey)
161139

162140
return (
163-
<Box
164-
position="sticky"
165-
zIndex={2}
166-
top="75px"
167-
bgColor="ednBackground"
168-
height="auto"
169-
w="full"
170-
hideFrom="lg"
171-
>
172-
<Center
173-
as={motion.div}
174-
fontWeight="medium"
175-
color="primary.base"
176-
cursor="pointer"
177-
py={4}
178-
px={8}
179-
boxSizing="border-box"
180-
bg="ednBackground"
181-
borderBottom="1px solid"
182-
borderBottomColor="border"
183-
onClick={() => setIsOpen(!isOpen)}
184-
>
185-
<Box me={2}>{t(pageTitleId)}</Box>
186-
<Box
187-
as={motion.div}
188-
cursor="pointer"
189-
display="flex"
190-
variants={dropdownIconContainerVariant}
191-
animate={isOpen ? "open" : "closed"}
141+
<div className="sticky top-[75px] z-sticky h-auto w-full bg-background-highlight lg:hidden">
142+
<motion.div>
143+
<Center
144+
className="box-border cursor-pointer border-b bg-background-highlight px-8 py-4 font-medium text-primary"
145+
onClick={() => setIsOpen(!isOpen)}
192146
>
193-
<Icon as={MdChevronRight} boxSize={6} color="secondary" />
194-
</Box>
195-
</Center>
147+
<div>{t(pageTitleId)}</div>
148+
<motion.div
149+
className="flex cursor-pointer"
150+
variants={dropdownIconContainerVariant}
151+
animate={isOpen ? "open" : "closed"}
152+
>
153+
<MdChevronRight className="h-6 w-6 text-body-medium" />
154+
</motion.div>
155+
</Center>
156+
</motion.div>
196157
<AnimatePresence>
197158
{isOpen && (
198-
<Box
199-
as={motion.nav}
200-
h="auto"
201-
maxH="calc(100vh - 139px)" // full height minus primary nav
202-
overflowY="scroll"
203-
overflowX="hidden"
204-
borderBottom="1px solid"
205-
borderBottomColor="border"
206-
p={2}
159+
<motion.nav
160+
className="max-h-[calc(100vh - 139px)] h-auto overflow-x-hidden overflow-y-scroll border-b p-2"
207161
key="nav"
208162
initial={{ opacity: 0 }}
209163
animate={{
@@ -228,10 +182,10 @@ const SideNavMobile = ({ path }: SideNavMobileProps) => {
228182
toggle={() => setIsOpen(false)}
229183
/>
230184
))}
231-
</Box>
185+
</motion.nav>
232186
)}
233187
</AnimatePresence>
234-
</Box>
188+
</div>
235189
)
236190
}
237191

0 commit comments

Comments
 (0)