From 6b41a41a6130555881eaee9fbeb175d90fdd4434 Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Wed, 31 Jan 2024 17:21:21 -0800 Subject: [PATCH 1/2] Add React Conf banner --- src/components/Banner.tsx | 58 ++++++++++++++++++++++++++++++++++ src/components/Layout/Page.tsx | 8 +++++ 2 files changed, 66 insertions(+) create mode 100644 src/components/Banner.tsx diff --git a/src/components/Banner.tsx b/src/components/Banner.tsx new file mode 100644 index 00000000000..16c152b1c33 --- /dev/null +++ b/src/components/Banner.tsx @@ -0,0 +1,58 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + */ + +import {useState, useRef, useEffect} from 'react'; +import cn from 'classnames'; +import {ExternalLink} from './ExternalLink'; + +export default function Banner({ + text, + link, + linkText, +}: { + text: string; + link: string; + linkText: string; +}) { + const [isVisible, setIsVisible] = useState(true); + const ref = useRef(null); + 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 ?? 0; // 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; + }; + }, []); + if (!isVisible) return null; + return ( + + ); +} diff --git a/src/components/Layout/Page.tsx b/src/components/Layout/Page.tsx index 5194279c280..4e535c05c26 100644 --- a/src/components/Layout/Page.tsx +++ b/src/components/Layout/Page.tsx @@ -9,6 +9,7 @@ import {SidebarNav} from './SidebarNav'; import {Footer} from './Footer'; import {Toc} from './Toc'; import SocialBanner from '../SocialBanner'; +import Banner from '../Banner'; import {DocsPageFooter} from 'components/DocsFooter'; import {Seo} from 'components/Seo'; import ButtonLink from 'components/ButtonLink'; @@ -117,6 +118,13 @@ export function Page({children, toc, routeTree, meta, section}: PageProps) { image={`/images/og-` + section + '.png'} searchOrder={searchOrder} /> + Date: Wed, 31 Jan 2024 20:14:55 -0800 Subject: [PATCH 2/2] Remove previous banner --- src/components/Banner.tsx | 58 --------------------------------- src/components/Layout/Page.tsx | 8 ----- src/components/SocialBanner.tsx | 8 ++--- 3 files changed, 3 insertions(+), 71 deletions(-) delete mode 100644 src/components/Banner.tsx diff --git a/src/components/Banner.tsx b/src/components/Banner.tsx deleted file mode 100644 index 16c152b1c33..00000000000 --- a/src/components/Banner.tsx +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - */ - -import {useState, useRef, useEffect} from 'react'; -import cn from 'classnames'; -import {ExternalLink} from './ExternalLink'; - -export default function Banner({ - text, - link, - linkText, -}: { - text: string; - link: string; - linkText: string; -}) { - const [isVisible, setIsVisible] = useState(true); - const ref = useRef(null); - 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 ?? 0; // 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; - }; - }, []); - if (!isVisible) return null; - return ( - - ); -} diff --git a/src/components/Layout/Page.tsx b/src/components/Layout/Page.tsx index 4e535c05c26..5194279c280 100644 --- a/src/components/Layout/Page.tsx +++ b/src/components/Layout/Page.tsx @@ -9,7 +9,6 @@ import {SidebarNav} from './SidebarNav'; import {Footer} from './Footer'; import {Toc} from './Toc'; import SocialBanner from '../SocialBanner'; -import Banner from '../Banner'; import {DocsPageFooter} from 'components/DocsFooter'; import {Seo} from 'components/Seo'; import ButtonLink from 'components/ButtonLink'; @@ -118,13 +117,6 @@ export function Page({children, toc, routeTree, meta, section}: PageProps) { image={`/images/og-` + section + '.png'} searchOrder={searchOrder} /> - (null); @@ -39,9 +39,7 @@ export default function SocialBanner() { -
πŸ‡ΊπŸ‡¦
{bannerLinkText} - .
);