|
| 1 | +import NextLink from "next/link" |
| 2 | +import { useConfig, useThemeConfig } from "nextra-theme-docs" |
| 3 | + |
| 4 | +import { GraphQLWordmarkLogo } from "@/icons" |
| 5 | +import { SocialIcons } from "@/app/conf/_components/social-icons" |
| 6 | +import { StripesDecoration } from "@/app/conf/_design-system/stripes-decoration" |
| 7 | +import blurBean from "@/app/conf/2025/components/footer/blur-bean.webp" |
| 8 | + |
| 9 | +import { renderComponent } from "../utils" |
| 10 | +import { Anchor } from "@/app/conf/_design-system/anchor" |
| 11 | + |
| 12 | +interface FooterLink { |
| 13 | + title: string |
| 14 | + route: string |
| 15 | +} |
| 16 | + |
| 17 | +interface FooterSection { |
| 18 | + title?: string |
| 19 | + route?: string |
| 20 | + links: FooterLink[] |
| 21 | +} |
| 22 | + |
| 23 | +const FOOTER_SECTIONS_COUNT = 4 |
| 24 | +const MAX_LINKS_PER_SECTION = 5 |
| 25 | + |
| 26 | +function useFooterSections(): FooterSection[] { |
| 27 | + const { normalizePagesResult } = useConfig() |
| 28 | + |
| 29 | + const sections: FooterSection[] = [] |
| 30 | + const singleLinks: FooterLink[] = [] |
| 31 | + |
| 32 | + for (const item of normalizePagesResult.topLevelNavbarItems) { |
| 33 | + if ( |
| 34 | + (item.type === "page" || item.type === "menu") && |
| 35 | + item.children?.length && |
| 36 | + sections.length < FOOTER_SECTIONS_COUNT - 1 |
| 37 | + ) { |
| 38 | + sections.push({ |
| 39 | + title: item.title, |
| 40 | + route: item.route, |
| 41 | + links: (item.children || []) |
| 42 | + .slice(0, MAX_LINKS_PER_SECTION) |
| 43 | + .map(child => ({ title: child.title, route: child.route })), |
| 44 | + }) |
| 45 | + } else if (singleLinks.length < MAX_LINKS_PER_SECTION) { |
| 46 | + if (!item.route?.startsWith("/conf/")) { |
| 47 | + singleLinks.push({ title: item.title, route: item.route }) |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + sections.push({ links: singleLinks }) |
| 53 | + return sections |
| 54 | +} |
| 55 | + |
| 56 | +export function Footer() { |
| 57 | + const sections = useFooterSections() |
| 58 | + const themeConfig = useThemeConfig() |
| 59 | + |
| 60 | + // const footerSections: FooterSection[] = |
| 61 | + // normalizePagesResult.topLevelNavbarItems |
| 62 | + // .filter(item => item.type === "page" || item.type === "menu") |
| 63 | + // .filter(item => item.children) |
| 64 | + // .map(item => { |
| 65 | + // return { |
| 66 | + // title: item.title, |
| 67 | + // route: item.route, |
| 68 | + // links: (item.children || []) |
| 69 | + // .filter( |
| 70 | + // child => |
| 71 | + // child.type === "doc" && |
| 72 | + // child.route && |
| 73 | + // !child.name.startsWith("--"), |
| 74 | + // ) |
| 75 | + // .slice(0, MAX_LINKS_PER_SECTION) |
| 76 | + // .map(child => ({ |
| 77 | + // title: child.title || child.name, |
| 78 | + // route: child.route, |
| 79 | + // })), |
| 80 | + // } |
| 81 | + // }) |
| 82 | + |
| 83 | + return ( |
| 84 | + <footer className="typography-menu relative !bg-neu-100 text-neu-900 dark:!bg-neu-0 max-md:px-0 max-md:pt-0"> |
| 85 | + <Stripes /> |
| 86 | + |
| 87 | + <div className="mx-auto max-w-[120rem] border-neu-400 dark:border-neu-100 3xl:border-x"> |
| 88 | + {/* TODO: Move themeSwitch to the bottom section and remove padding. */} |
| 89 | + {/* Top section with logo and theme switch */} |
| 90 | + <div className="flex flex-wrap justify-between gap-4 p-4 max-md:w-full md:p-6 2xl:px-10"> |
| 91 | + <NextLink href="/" className="nextra-logo flex items-center"> |
| 92 | + <GraphQLWordmarkLogo className="h-6" title="GraphQL" /> |
| 93 | + </NextLink> |
| 94 | + {themeConfig.darkMode && ( |
| 95 | + <div className="flex items-center"> |
| 96 | + {renderComponent(themeConfig.themeSwitch.component)} |
| 97 | + </div> |
| 98 | + )} |
| 99 | + </div> |
| 100 | + |
| 101 | + {/* Navigation grid */} |
| 102 | + <ul className="grid grid-cols-2 gap-px bg-neu-400 py-px dark:bg-neu-100 lg:grid-cols-4"> |
| 103 | + {sections.map((section, i) => ( |
| 104 | + <li className="bg-neu-100 dark:bg-neu-0" key={i}> |
| 105 | + <div className="relative flex flex-col px-4 py-8 3xl:px-6 3xl:py-10"> |
| 106 | + {section.title && ( |
| 107 | + <h3 className="block h-full font-bold lg:mb-4 3xl:mb-10"> |
| 108 | + {section.route ? ( |
| 109 | + <Anchor |
| 110 | + className="gql-focus-visible block p-3 underline-offset-4 hover:underline" |
| 111 | + href={section.route} |
| 112 | + > |
| 113 | + {section.title} |
| 114 | + </Anchor> |
| 115 | + ) : ( |
| 116 | + <span className="block p-3">{section.title}</span> |
| 117 | + )} |
| 118 | + </h3> |
| 119 | + )} |
| 120 | + {section.links.map(link => ( |
| 121 | + <Anchor |
| 122 | + key={link.route} |
| 123 | + href={link.route} |
| 124 | + className="gql-focus-visible block h-full p-3 underline-offset-4 hover:underline" |
| 125 | + > |
| 126 | + {link.title} |
| 127 | + </Anchor> |
| 128 | + ))} |
| 129 | + </div> |
| 130 | + </li> |
| 131 | + ))} |
| 132 | + </ul> |
| 133 | + |
| 134 | + <div className="relative flex items-center justify-between gap-10 p-4 max-lg:flex-col md:px-6 2xl:px-10"> |
| 135 | + <div className="flex flex-col font-light max-md:gap-5"> |
| 136 | + <p>{renderComponent(themeConfig.footer.content)}</p> |
| 137 | + </div> |
| 138 | + <SocialIcons className="[&>a:focus]:text-current [&>a:focus]:ring-transparent [&>a:hover]:bg-neu-900/10 [&>a:hover]:text-current" /> |
| 139 | + </div> |
| 140 | + </div> |
| 141 | + </footer> |
| 142 | + ) |
| 143 | +} |
| 144 | + |
| 145 | +function Stripes() { |
| 146 | + return ( |
| 147 | + <div |
| 148 | + role="presentation" |
| 149 | + // prettier-ignore |
| 150 | + // false positive |
| 151 | + // eslint-disable-next-line tailwindcss/no-contradicting-classname |
| 152 | + className="pointer-events-none absolute inset-0 |
| 153 | + [--start-1:rgba(255,204,239,.05)] |
| 154 | + [--end-1:hsl(var(--color-pri-base)/.8)] |
| 155 | + dark:[--start-1:hsl(var(--color-pri-darker))] |
| 156 | + dark:[--end-1:hsl(var(--color-pri-base)/.9)] |
| 157 | +
|
| 158 | + [--start-2:transparent] |
| 159 | + [--end-2:hsl(var(--color-pri-base)/.6)] |
| 160 | + dark:[--start-2:rgba(255,204,239,.1)] |
| 161 | + dark:[--end-2:hsl(var(--color-pri-base)/.8)] |
| 162 | +
|
| 163 | + mix-blend-darken |
| 164 | + dark:mix-blend-lighten |
| 165 | + " |
| 166 | + style={{ |
| 167 | + maskImage: `url(${blurBean.src})`, |
| 168 | + WebkitMaskImage: `url(${blurBean.src})`, |
| 169 | + maskPosition: "center 260px", |
| 170 | + WebkitMaskPosition: "center 260px", |
| 171 | + maskSize: "200% 100%", |
| 172 | + WebkitMaskSize: "200% 100%", |
| 173 | + maskRepeat: "no-repeat", |
| 174 | + WebkitMaskRepeat: "no-repeat", |
| 175 | + maskOrigin: "top", |
| 176 | + }} |
| 177 | + > |
| 178 | + <StripesDecoration |
| 179 | + evenClassName="bg-[linear-gradient(180deg,var(--start-1)_0%,var(--end-1)_200%)]" |
| 180 | + oddClassName="bg-[linear-gradient(180deg,var(--start-2)_0%,var(--end-2)_200%)]" |
| 181 | + /> |
| 182 | + </div> |
| 183 | + ) |
| 184 | +} |
0 commit comments