|
@ -4,40 +4,37 @@ |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
import React from 'react'; |
|
|
import React from 'react'; |
|
|
|
|
|
import cn from 'classnames'; |
|
|
import {ExternalLink} from './ExternalLink'; |
|
|
import {ExternalLink} from './ExternalLink'; |
|
|
|
|
|
|
|
|
// TODO: Unify with the old site settings.
|
|
|
|
|
|
const bannerText = 'Support Ukraine 🇺🇦'; |
|
|
const bannerText = 'Support Ukraine 🇺🇦'; |
|
|
const bannerLink = 'https://opensource.fb.com/support-ukraine'; |
|
|
const bannerLink = 'https://opensource.fb.com/support-ukraine'; |
|
|
const bannerLinkText = 'Help Provide Humanitarian Aid to 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() { |
|
|
export default function SocialBanner() { |
|
|
|
|
|
const ref = React.useRef<HTMLDivElement | null>(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 ( |
|
|
return ( |
|
|
<div |
|
|
<div |
|
|
className={ |
|
|
ref={ref} |
|
|
bannerHeightTw + |
|
|
className={cn( |
|
|
` w-full bg-gray-100 dark:bg-gray-700 text-base md:text-lg py-2 sm:py-0 flex items-center justify-center flex-col sm:flex-row z-[100]` |
|
|
`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]` |
|
|
}> |
|
|
)}> |
|
|
<div className="hidden sm:block">{bannerText}</div> |
|
|
<div className="hidden sm:block">{bannerText}</div> |
|
|
<ExternalLink |
|
|
<ExternalLink |
|
|
className="ml-0 sm:ml-1 text-link dark:text-link-dark hover:underline" |
|
|
className="ml-0 sm:ml-1 text-link dark:text-link-dark hover:underline" |
|
|