Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ShadCN]: Fix #13405 and end #13523 use shadcn #14811

Merged
merged 11 commits into from
Feb 26, 2025
87 changes: 44 additions & 43 deletions src/components/DocsNav.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import { FaChevronLeft, FaChevronRight } from "react-icons/fa"

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

import Emoji from "@/components/Emoji"
import { BaseLink } from "@/components/ui/Link"

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

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

import { Stack } from "./ui/flex"
import { LinkBox, LinkOverlay } from "./ui/link-box"

import { useRtlFlip } from "@/hooks/useRtlFlip"
import { useTranslation } from "@/hooks/useTranslation"
import { usePathname } from "@/i18n/routing"

const TextDiv = ({ children, className, ...props }) => (
<Stack
<div
className={cn(
"h-full max-w-[166px] justify-between gap-0 break-words p-4",
"flex h-full w-full flex-col justify-center break-words p-4",
className
)}
{...props}
>
{children}
</Stack>
</div>
)

type DocsArrayProps = {
Expand All @@ -40,43 +39,45 @@ type CardLinkProps = {

const CardLink = ({ docData, isPrev, contentNotTranslated }: CardLinkProps) => {
const { t } = useTranslation("page-developers-docs")
const { isRtl } = useRtlFlip()
const { twFlipForRtl } = useRtlFlip()

return (
<LinkBox
<BaseLink
href={docData.href}
className={cn(
"flex w-full flex-1 items-center no-underline",
"h-[82px] rounded-sm border bg-background",
isPrev ? "justify-start" : "justify-end"
"group flex w-full items-center rounded-sm border border-primary bg-background !no-underline",
isPrev ? "justify-start" : "justify-end",
"hover:border-primary-hover"
)}
rel={isPrev ? "prev" : "next"}
onClick={() => {
trackCustomEvent({
eventCategory: "next/previous article DocsNav",
eventAction: "click",
eventName: isPrev ? "previous" : "next",
})
}}
>
<div className={cn("h-full p-4", isPrev ? "order-[0]" : "order-1")}>
<Emoji
text={isPrev ? ":point_left:" : ":point_right:"}
className={cn(
"text-5xl",
!contentNotTranslated && isRtl ? "-scale-x-100" : ""
)}
/>
<div
className={cn(
"p-4",
isPrev ? "order-0" : "order-1",
!contentNotTranslated && twFlipForRtl
)}
>
{isPrev ? (
<FaChevronLeft className="text-xl group-hover:fill-primary-hover" />
) : (
<FaChevronRight className="text-xl group-hover:fill-primary-hover" />
)}
</div>
<TextDiv className={cn(!isPrev ? "pe-0 text-end" : "ps-0")}>
<p className="uppercase text-body">{t(isPrev ? "previous" : "next")}</p>
<LinkOverlay
href={docData.href}
onClick={() => {
trackCustomEvent({
eventCategory: "next/previous article DocsNav",
eventAction: "click",
eventName: isPrev ? "previous" : "next",
})
}}
className={cn("underline", isPrev ? "text-start" : "text-end")}
rel={isPrev ? "prev" : "next"}
>
{t(docData.id)}
</LinkOverlay>
<TextDiv className={cn(isPrev ? "ps-0" : "pe-0 text-end")}>
<p className="btn-txt !m-0 text-lg text-primary group-hover:text-primary-hover">
{t(isPrev ? "previous" : "next")}
</p>
<p className="!mb-0 text-sm no-underline">{t(docData.id)}</p>
</TextDiv>
</LinkBox>
</BaseLink>
)
}

Expand All @@ -89,11 +90,11 @@ const DocsNav = ({ contentNotTranslated }: DocsNavProps) => {
// Construct array of all linkable documents in order recursively
const docsArray: DocsArrayProps[] = []
const getDocs = (links: Array<DeveloperDocsLink>): void => {
// If object has 'items' key
for (const item of links) {
// If object has 'items' key
// And if item has a 'to' key
// Add 'to' path and 'id' to docsArray
if (item.items) {
// And if item has a 'to' key
// Add 'to' path and 'id' to docsArray
item.href && docsArray.push({ href: item.href, id: item.id })
// Then recursively add sub-items
getDocs(item.items)
Expand Down Expand Up @@ -128,7 +129,7 @@ const DocsNav = ({ contentNotTranslated }: DocsNavProps) => {
className={cn(
"flex flex-col-reverse md:flex-row lg:flex-col-reverse xl:flex-row",
"mt-8 justify-between gap-4",
"items-center md:items-start"
"items-stretch"
)}
aria-label="Paginate to document"
>
Expand All @@ -139,15 +140,15 @@ const DocsNav = ({ contentNotTranslated }: DocsNavProps) => {
isPrev
/>
) : (
<div className="hidden flex-grow xl:block"></div>
<div className="hidden flex-grow xl:block" />
)}
{nextDoc ? (
<CardLink
docData={nextDoc}
contentNotTranslated={contentNotTranslated}
/>
) : (
<div className="hidden flex-grow xl:block"></div>
<div className="hidden flex-grow xl:block" />
)}
</nav>
)
Expand Down