Skip to content

Commit 5d07a63

Browse files
authored
Merge pull request #14039 from saurabhburade/shadcn-migrate/DocsNav
Shadcn Migration - DocsNav
2 parents dfddcd1 + 26f2e05 commit 5d07a63

File tree

1 file changed

+30
-56
lines changed

1 file changed

+30
-56
lines changed

src/components/DocsNav.tsx

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,31 @@
11
import { useRouter } from "next/router"
22
import { useTranslation } from "next-i18next"
3-
import {
4-
Box,
5-
Flex,
6-
FlexProps,
7-
LinkBox,
8-
LinkOverlay,
9-
Spacer,
10-
} from "@chakra-ui/react"
113

124
import { TranslationKey } from "@/lib/types"
135
import type { DeveloperDocsLink } from "@/lib/interfaces"
146

157
import Emoji from "@/components/Emoji"
16-
import { BaseLink } from "@/components/Link"
17-
import Text from "@/components/OldText"
188

199
import { cn } from "@/lib/utils/cn"
2010
import { trackCustomEvent } from "@/lib/utils/matomo"
2111

2212
import docLinks from "@/data/developer-docs-links.yaml"
2313

14+
import { Stack } from "./ui/flex"
15+
import { LinkBox, LinkOverlay } from "./ui/link-box"
16+
2417
import { useRtlFlip } from "@/hooks/useRtlFlip"
2518

26-
const TextDiv = ({ children, ...props }: FlexProps) => (
27-
<Flex
28-
direction="column"
29-
justify="space-between"
30-
maxW="166px"
31-
h="100%"
32-
wordwrap="break-word"
33-
p={4}
34-
lineHeight={4}
19+
const TextDiv = ({ children, className, ...props }) => (
20+
<Stack
21+
className={cn(
22+
"h-full max-w-[166px] justify-between gap-0 break-words p-4",
23+
className
24+
)}
3525
{...props}
3626
>
3727
{children}
38-
</Flex>
28+
</Stack>
3929
)
4030

4131
type DocsArrayProps = {
@@ -53,46 +43,36 @@ const CardLink = ({ docData, isPrev, contentNotTranslated }: CardLinkProps) => {
5343
const { t } = useTranslation("page-developers-docs")
5444
const { isRtl } = useRtlFlip()
5545

56-
const xPadding = isPrev ? { ps: "0" } : { pe: 0 }
57-
5846
return (
5947
<LinkBox
60-
as={Flex}
61-
alignItems="center"
62-
w="full"
63-
flex="1"
64-
h="82px"
65-
bg="background.base"
66-
border="1px"
67-
borderColor="border"
68-
borderRadius={1}
69-
justify={isPrev ? "flex-start" : "flex-end"}
48+
className={cn(
49+
"flex w-full flex-1 items-center no-underline",
50+
"h-[82px] rounded-sm border bg-background",
51+
isPrev ? "justify-start" : "justify-end"
52+
)}
7053
>
71-
<Box textDecoration="none" p={4} h="100%" order={isPrev ? 0 : 1}>
54+
<div className={cn("h-full p-4", isPrev ? "order-[0]" : "order-1")}>
7255
<Emoji
7356
text={isPrev ? ":point_left:" : ":point_right:"}
7457
className={cn(
7558
"text-5xl",
7659
!contentNotTranslated && isRtl ? "-scale-x-100" : ""
7760
)}
7861
/>
79-
</Box>
80-
<TextDiv {...xPadding} {...(!isPrev && { textAlign: "end" })}>
81-
<Text textTransform="uppercase" m="0">
82-
{t(isPrev ? "previous" : "next")}
83-
</Text>
62+
</div>
63+
<TextDiv className={cn(!isPrev ? "pe-0 text-end" : "ps-0")}>
64+
<p className="uppercase text-body">{t(isPrev ? "previous" : "next")}</p>
8465
<LinkOverlay
85-
as={BaseLink}
8666
href={docData.href}
87-
textAlign={isPrev ? "start" : "end"}
88-
rel={isPrev ? "prev" : "next"}
8967
onClick={() => {
9068
trackCustomEvent({
9169
eventCategory: "next/previous article DocsNav",
9270
eventAction: "click",
9371
eventName: isPrev ? "previous" : "next",
9472
})
9573
}}
74+
className={cn("underline", isPrev ? "text-start" : "text-end")}
75+
rel={isPrev ? "prev" : "next"}
9676
>
9777
{t(docData.id)}
9878
</LinkOverlay>
@@ -145,19 +125,13 @@ const DocsNav = ({ contentNotTranslated }: DocsNavProps) => {
145125
currentIndex + 1 < docsArray.length ? docsArray[currentIndex + 1] : null
146126

147127
return (
148-
<Flex
149-
as="nav"
128+
<nav
129+
className={cn(
130+
"flex flex-col-reverse md:flex-row lg:flex-col-reverse xl:flex-row",
131+
"mt-8 justify-between gap-4",
132+
"items-center md:items-start"
133+
)}
150134
aria-label="Paginate to document"
151-
direction={{
152-
base: "column-reverse",
153-
md: "row",
154-
lg: "column-reverse",
155-
xl: "row",
156-
}}
157-
mt="8"
158-
gap="4"
159-
justify="space-between"
160-
alignItems={{ base: "center", md: "flex-start" }}
161135
>
162136
{previousDoc ? (
163137
<CardLink
@@ -166,17 +140,17 @@ const DocsNav = ({ contentNotTranslated }: DocsNavProps) => {
166140
isPrev
167141
/>
168142
) : (
169-
<Spacer />
143+
<div className="hidden flex-grow xl:block"></div>
170144
)}
171145
{nextDoc ? (
172146
<CardLink
173147
docData={nextDoc}
174148
contentNotTranslated={contentNotTranslated}
175149
/>
176150
) : (
177-
<Spacer />
151+
<div className="hidden flex-grow xl:block"></div>
178152
)}
179-
</Flex>
153+
</nav>
180154
)
181155
}
182156

0 commit comments

Comments
 (0)