From ee96afda033c6fef4fa398b9905065292fcff0bd Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 10 Sep 2022 00:44:57 +0100 Subject: [PATCH] [Beta] Top bar fixes (#5025) --- beta/src/components/Layout/Page.tsx | 4 ++- beta/src/components/SocialBanner.tsx | 47 +++++++++++++--------------- beta/src/styles/index.css | 2 +- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/beta/src/components/Layout/Page.tsx b/beta/src/components/Layout/Page.tsx index f46ea311..2ea423d5 100644 --- a/beta/src/components/Layout/Page.tsx +++ b/beta/src/components/Layout/Page.tsx @@ -37,10 +37,12 @@ export function Page({children, toc}: PageProps) {
-
+
+
+ {/* No fallback UI so need to be careful not to suspend directly inside. */}
diff --git a/beta/src/components/SocialBanner.tsx b/beta/src/components/SocialBanner.tsx index 67cd2b8b..c79d4289 100644 --- a/beta/src/components/SocialBanner.tsx +++ b/beta/src/components/SocialBanner.tsx @@ -4,40 +4,37 @@ */ import React from 'react'; +import cn from 'classnames'; import {ExternalLink} from './ExternalLink'; -// TODO: Unify with the old site settings. const bannerText = 'Support Ukraine πŸ‡ΊπŸ‡¦'; const bannerLink = 'https://opensource.fb.com/support-ukraine'; const bannerLinkText = 'Help Provide Humanitarian Aid to Ukraine'; -// Keep these synced: -const bannerHeightJs = 40; -const bannerHeightTw = 'h-[40px]'; - -if (typeof window !== 'undefined') { - // Assume it's Next.js scroll restoration. - const realScrollTo = window.scrollTo; - (window as any).scrollTo = function scrollToPatchedForSocialBanner( - x: number, - y: number - ) { - if (y === 0) { - // We're trying to reset scroll. - // If we already scrolled past the banner, consider it as y = 0. - y = Math.min(window.scrollY, bannerHeightJs); - } - return realScrollTo(x, y); - }; -} - export default function SocialBanner() { + const ref = React.useRef(null); + React.useEffect(() => { + function patchedScrollTo(x: number, y: number) { + if (y === 0) { + // We're trying to reset scroll. + // If we already scrolled past the banner, consider it as y = 0. + const bannerHeight = ref.current!.offsetHeight; // Could be zero (e.g. mobile) + y = Math.min(window.scrollY, bannerHeight); + } + return realScrollTo(x, y); + } + const realScrollTo = window.scrollTo; + (window as any).scrollTo = patchedScrollTo; + return () => { + (window as any).scrollTo = realScrollTo; + }; + }, []); return (
+ ref={ref} + className={cn( + `h-[40px] hidden lg:flex w-full bg-gray-100 dark:bg-gray-700 text-base md:text-lg py-2 sm:py-0 items-center justify-center flex-col sm:flex-row z-[100]` + )}>
{bannerText}