Skip to content

Commit 5efe704

Browse files
authored
Merge pull request #14508 from ashiskumar-1999/migrate-SideNav.tsx-to-Shadcn/Tailwind
feat: Migrate SideNav to Shadcn/Tailwind
2 parents ecca401 + 17946e7 commit 5efe704

File tree

1 file changed

+24
-53
lines changed

1 file changed

+24
-53
lines changed

src/components/SideNav.tsx

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

76
import { ChildOnlyProp } 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 { HStack } from "./ui/flex"
12+
import { BaseLink, LinkProps } from "./ui/Link"
13+
1414
export const dropdownIconContainerVariant = {
1515
open: {
1616
rotate: 90,
@@ -34,14 +34,7 @@ const innerLinksVariants = {
3434

3535
const LinkContainer = ({ children }: ChildOnlyProp) => {
3636
return (
37-
<HStack
38-
w="full"
39-
justify="space-between"
40-
py={2}
41-
pe={4}
42-
ps={8}
43-
_hover={{ bgColor: "ednBackground" }}
44-
>
37+
<HStack className="w-full justify-between py-2 pe-4 ps-8 hover:bg-background-highlight">
4538
{children}
4639
</HStack>
4740
)
@@ -50,12 +43,7 @@ const LinkContainer = ({ children }: ChildOnlyProp) => {
5043
const SideNavLink = ({ children, ...props }: LinkProps) => {
5144
return (
5245
<BaseLink
53-
w="full"
54-
textDecoration="none"
55-
color="text"
56-
fontWeight="normal"
57-
_hover={{ textDecoration: "none", color: "primary.base" }}
58-
_active={{ color: "primary.base" }}
46+
className="w-full font-normal text-body no-underline hover:text-primary"
5947
{...props}
6048
>
6149
{children}
@@ -86,35 +74,32 @@ const NavLink = ({ item, path, isTopLevel }: NavLinkProps) => {
8674

8775
if (item.items) {
8876
return (
89-
<Box>
77+
<div>
9078
<LinkContainer>
9179
{item.href && (
9280
<SideNavLink href={item.href} isPartiallyActive={false}>
9381
{t(item.id)}
9482
</SideNavLink>
9583
)}
9684
{!item.href && (
97-
<Box w="full" cursor="pointer" onClick={() => setIsOpen(!isOpen)}>
85+
<div
86+
className="w-full cursor-pointer"
87+
onClick={() => setIsOpen(!isOpen)}
88+
>
9889
{t(item.id)}
99-
</Box>
90+
</div>
10091
)}
101-
<Box
102-
as={motion.div}
92+
<motion.div
93+
className="flex cursor-pointer"
10394
onClick={() => setIsOpen(!isOpen)}
10495
variants={dropdownIconContainerVariant}
10596
animate={isOpen ? "open" : "closed"}
106-
cursor="pointer"
107-
display="flex"
10897
>
109-
<Icon as={MdChevronRight} boxSize={6} color="secondary" />
110-
</Box>
98+
<MdChevronRight className="h-6 w-6 text-body-medium" />
99+
</motion.div>
111100
</LinkContainer>
112-
<Box
113-
as={motion.div}
114-
fontSize="sm"
115-
lineHeight="tall"
116-
fontWeight="normal"
117-
ms={4}
101+
<motion.div
102+
className="ms-4 text-sm font-normal leading-relaxed"
118103
key={item.id}
119104
animate={isOpen ? "open" : "closed"}
120105
variants={innerLinksVariants}
@@ -123,18 +108,18 @@ const NavLink = ({ item, path, isTopLevel }: NavLinkProps) => {
123108
{item.items.map((childItem, idx) => (
124109
<NavLink item={childItem} path={path} key={idx} />
125110
))}
126-
</Box>
127-
</Box>
111+
</motion.div>
112+
</div>
128113
)
129114
}
130115
return (
131-
<Box>
116+
<div>
132117
<LinkContainer>
133118
<SideNavLink href={item.href} isPartiallyActive={false}>
134119
{t(item.id)}
135120
</SideNavLink>
136121
</LinkContainer>
137-
</Box>
122+
</div>
138123
)
139124
}
140125

@@ -149,28 +134,14 @@ const SideNav = ({ path }: SideNavProps) => {
149134
const { t } = useTranslation("page-developers-docs")
150135

151136
return (
152-
<Box
153-
as="nav"
154-
position="sticky"
155-
top="19"
156-
pt={8}
157-
pb={16}
158-
h="calc(100vh - 80px)" // TODO take footer into account for height?
159-
w="calc((100% - 1448px) / 2 + 256px)"
160-
minW="256px"
161-
overflowY="auto"
162-
transition="transform 0.2s ease"
163-
bgColor="background.base"
164-
boxShadow="1px 0px 0px rgba(0, 0, 0, 0.1)"
165-
borderInlineEnd="1px solid"
166-
borderInlineEndColor="border"
167-
display={{ base: "none", lg: "block" }}
137+
<nav
138+
className="sticky top-[4.75rem] hidden h-[calc(100vh-80px)] w-[calc((100%-1448px)/2+256px)] min-w-[256px] overflow-y-auto border-e bg-background pb-16 pt-8 shadow-[1px_0px_0px_rgba(0,0,0,0.1)] transition-transform duration-200 lg:block"
168139
aria-label={t("common:nav-developers-docs")}
169140
>
170141
{docLinks.map((item, idx) => (
171142
<NavLink item={item} path={path} key={idx} isTopLevel />
172143
))}
173-
</Box>
144+
</nav>
174145
)
175146
}
176147

0 commit comments

Comments
 (0)