|
| 1 | +import NextLink from "next/link" |
| 2 | +import type { Item } from "nextra/normalize-pages" |
| 3 | +import type { ReactElement } from "react" |
| 4 | +import { useThemeConfig } from "nextra-theme-docs" |
| 5 | +import type { DocsThemeConfig } from "nextra-theme-docs" |
| 6 | + |
| 7 | +import { StripesDecoration } from "@/app/conf/_design-system/stripes-decoration" |
| 8 | +import { learnPages } from "@/components/learn-aggregator/learn-pages" |
| 9 | + |
| 10 | +import blurCorner from "./blur-corner.webp" |
| 11 | +import clsx from "clsx" |
| 12 | + |
| 13 | +interface NavLinkProps { |
| 14 | + currentIndex: number |
| 15 | + flatDocsDirectories: Item[] |
| 16 | +} |
| 17 | + |
| 18 | +export function NavLinks({ |
| 19 | + flatDocsDirectories, |
| 20 | + currentIndex, |
| 21 | +}: NavLinkProps): ReactElement | null { |
| 22 | + const themeConfig = useThemeConfig() |
| 23 | + const nav = themeConfig.navigation |
| 24 | + const navigation: Exclude<DocsThemeConfig["navigation"], boolean> = |
| 25 | + typeof nav === "boolean" ? { prev: nav, next: nav } : nav |
| 26 | + let prev = navigation.prev && flatDocsDirectories[currentIndex - 1] |
| 27 | + let next = navigation.next && flatDocsDirectories[currentIndex + 1] |
| 28 | + |
| 29 | + if (prev && !prev.isUnderCurrentDocsTree) prev = false |
| 30 | + if (next && !next.isUnderCurrentDocsTree) next = false |
| 31 | + |
| 32 | + if (!prev && !next) return null |
| 33 | + |
| 34 | + const displayPost = next || prev |
| 35 | + const isNext = !!next |
| 36 | + |
| 37 | + if (!displayPost) return null |
| 38 | + |
| 39 | + const pageKey = displayPost.route.split("/").pop() as keyof typeof learnPages |
| 40 | + const pageData = learnPages[pageKey] |
| 41 | + const section = pageData?.section |
| 42 | + |
| 43 | + return ( |
| 44 | + <div className="gql-container mb-8 print:hidden"> |
| 45 | + <NextLink |
| 46 | + href={displayPost.route} |
| 47 | + className="gql-focus-visible relative flex items-center gap-8 border border-neu-200 bg-neu-0 p-8 hover:ring hover:ring-neu-100 dark:border-neu-50 dark:hover:ring-neu-50/50" |
| 48 | + > |
| 49 | + <div |
| 50 | + className={clsx( |
| 51 | + "pointer-events-none absolute inset-0 left-4 overflow-hidden", |
| 52 | + section === "getting-started" && |
| 53 | + "[--start:var(--color-pri-lightest)] dark:[--start:var(--color-pri-darker)]", |
| 54 | + section === "best-practices" && |
| 55 | + "[--start:var(--color-sec-lighter)] dark:[--start:var(--color-sec-darker)]", |
| 56 | + )} |
| 57 | + style={{ |
| 58 | + maskImage: `url(${blurCorner.src})`, |
| 59 | + WebkitMaskImage: `url(${blurCorner.src})`, |
| 60 | + maskSize: "50% 50%", |
| 61 | + WebkitMaskSize: "50% 50%", |
| 62 | + maskPosition: "top right", |
| 63 | + WebkitMaskPosition: "top right", |
| 64 | + maskRepeat: "no-repeat", |
| 65 | + WebkitMaskRepeat: "no-repeat", |
| 66 | + }} |
| 67 | + > |
| 68 | + <StripesDecoration |
| 69 | + oddClassName="bg-[linear-gradient(180deg,hsl(var(--start))_0%,hsl(var(--color-neu-0)/0)_50%)]" |
| 70 | + stripeWidth="12px" |
| 71 | + /> |
| 72 | + </div> |
| 73 | + |
| 74 | + <div className="flex flex-1 flex-col gap-6"> |
| 75 | + <p className="typography-menu text-pri-base dark:text-pri-light"> |
| 76 | + {isNext ? "next lesson" : "previous lesson"} |
| 77 | + </p> |
| 78 | + |
| 79 | + <div className="flex flex-col gap-4 text-neu-900"> |
| 80 | + <h2 className="typography-h2">{displayPost.title}</h2> |
| 81 | + {pageData?.description && ( |
| 82 | + <p className="typography-body-lg max-w-[560px]"> |
| 83 | + {pageData.description} |
| 84 | + </p> |
| 85 | + )} |
| 86 | + </div> |
| 87 | + |
| 88 | + <div className="flex h-12 items-center justify-center self-start bg-neu-900 px-8 py-2"> |
| 89 | + <span className="typography-button text-neu-0"> |
| 90 | + Go to {isNext ? "next" : "previous"} lesson |
| 91 | + </span> |
| 92 | + </div> |
| 93 | + </div> |
| 94 | + |
| 95 | + {pageData?.icon && ( |
| 96 | + <div className="relative flex size-[222px] bg-neu-0"> |
| 97 | + <div |
| 98 | + className={clsx( |
| 99 | + "shrink-0 items-center justify-center p-12", |
| 100 | + section === "getting-started" && |
| 101 | + "bg-pri-lightest dark:bg-pri-lighter/5", |
| 102 | + section === "best-practices" && |
| 103 | + "bg-sec-lighter dark:bg-sec-lighter/10", |
| 104 | + )} |
| 105 | + > |
| 106 | + <img |
| 107 | + src={pageData.icon} |
| 108 | + alt="" |
| 109 | + className="size-full object-contain" |
| 110 | + /> |
| 111 | + </div> |
| 112 | + </div> |
| 113 | + )} |
| 114 | + </NextLink> |
| 115 | + </div> |
| 116 | + ) |
| 117 | +} |
0 commit comments