()
| 43 | ) |
| 44 | |
| 45 | export default function Header() { |
| 46 | const { t } = useTranslation() |
| 47 | const ref = React.useRef<HTMLDivElement | null>(null) |
| 48 | const section = useActiveSection() |
| 49 | React.useEffect(() => { |
| 50 | function patchedScrollTo(x: number, y: number) { |
| 51 | if (y === 0) { |
| 52 | // We're trying to reset scroll. |
| 53 | // If we already scrolled past the banner, consider it as y = 0. |
| 54 | const bannerHeight = ref.current?.offsetHeight ?? 0 // Could be zero (e.g. mobile) |
| 55 | y = Math.min(window.scrollY, bannerHeight) |
| 56 | } |
| 57 | return realScrollTo(x, y) |
| 58 | } |
| 59 | const realScrollTo = window.scrollTo |
| 60 | ;(window as any).scrollTo = patchedScrollTo |
| 61 | return () => { |
| 62 | ;(window as any).scrollTo = realScrollTo |
| 63 | } |
| 64 | }, []) |
| 65 | return ( |
| 66 | <div |
| 67 | ref={ref} |
| 68 | tw="h-[64px] fixed lg:sticky bg-white text-primary dark:bg-primary dark:text-white hidden top-0 left-0 lg:flex w-full text-base md:text-lg px-5 py-2 sm:py-0 items-center z-[100] shadow" |
| 69 | > |
| 70 | <NextLink href="/"> |
| 71 | <a tw="text-lg dark:text-primary-dark mr-0 inline-flex items-center whitespace-nowrap py-1 font-normal sm:mr-3"> |
| 72 | <IconLogo tw="text-link dark:text-link-dark mr-2 text-xl" /> |
| 73 | {t('docs.title')} |
| 74 | </a> |
| 75 | </NextLink> |
| 76 | <div tw="flex gap-4 ml-[140px]"> |
| 77 | <NavLink href="/learn" isActive={section === 'learn' || section === 'home'}> |
| 78 | {t('docs.learn')} |
| 79 | </NavLink> |
| 80 | <NavLink href="/apis" isActive={section === 'apis'}> |
| 81 | {t('docs.api')} |
| 82 | </NavLink> |
| 83 | <NavLink href="/playground" target="_blank" isActive={section === 'playground'}> |
| 84 | Playground |
| 85 | </NavLink> |
| 86 | </div> |
| 87 | <div tw="justify-end flex flex-1 gap-4 items-center"> |
| 88 | <div tw="w-96"> |
| 89 | <Search /> |
| 90 | </div> |
| 91 | <div tw="block dark:hidden"> |
| 92 | <button |
| 93 | type="button" |
| 94 | aria-label="Use Dark Mode" |
| 95 | onClick={() => { |
| 96 | window.__setPreferredTheme('dark') |
| 97 | }} |
| 98 | tw="hidden h-full items-center lg:flex" |
| 99 | > |
| 100 | {darkIcon} |
| 101 | </button> |
| 102 | </div> |
nothing calls this directly
no test coverage detected
searching dependent graphs…