Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor VisuallyHidden component to use ChakraUI #7724

Merged
merged 3 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 35 additions & 37 deletions src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { LocaleProvider } from "gatsby-theme-i18n"
import { lightTheme, darkTheme } from "../theme"

import Footer from "./Footer"
import VisuallyHidden from "./VisuallyHidden"
import ZenMode from "./ZenMode"
import Nav from "./Nav"
import SideNav from "./SideNav"
import SideNavMobile from "./SideNavMobile"
Expand Down Expand Up @@ -149,43 +149,41 @@ const Layout: React.FC<IProps> = ({
<IntlProvider locale={locale!} key={locale} messages={messages}>
<ApolloProvider client={client}>
<ThemeProvider theme={theme}>
<SkipLink hrefId="#main-content" />
<TranslationBanner
shouldShow={shouldShowTranslationBanner}
isPageContentEnglish={isPageContentEnglish}
isPageRightToLeft={isPageRightToLeft}
originalPagePath={pageContext.originalPath!}
/>
<TranslationBannerLegal
shouldShow={isLegal}
isPageRightToLeft={isPageRightToLeft}
originalPagePath={pageContext.originalPath!}
/>
<ContentContainer>
<VisuallyHidden isHidden={isZenMode}>
<Nav path={path} />
{shouldShowSideNav && <SideNavMobile path={path} />}
</VisuallyHidden>
<SkipLinkAnchor id="main-content" />
<MainContainer>
{shouldShowSideNav && (
<VisuallyHidden isHidden={isZenMode}>
<SideNav path={path} />
</VisuallyHidden>
)}
<MainContent>
<ZenModeContext.Provider
value={{ isZenMode, handleZenModeChange }}
>
<ZenModeContext.Provider value={{ isZenMode, handleZenModeChange }}>
<SkipLink hrefId="#main-content" />
<TranslationBanner
shouldShow={shouldShowTranslationBanner}
isPageContentEnglish={isPageContentEnglish}
isPageRightToLeft={isPageRightToLeft}
originalPagePath={pageContext.originalPath!}
/>
<TranslationBannerLegal
shouldShow={isLegal}
isPageRightToLeft={isPageRightToLeft}
originalPagePath={pageContext.originalPath!}
/>
<ContentContainer>
<ZenMode>
<Nav path={path} />
{shouldShowSideNav && <SideNavMobile path={path} />}
</ZenMode>
<SkipLinkAnchor id="main-content" />
<MainContainer>
{shouldShowSideNav && (
<ZenMode>
<SideNav path={path} />
</ZenMode>
)}
<MainContent>
<Main>{children}</Main>
</ZenModeContext.Provider>
</MainContent>
</MainContainer>
<VisuallyHidden isHidden={isZenMode}>
<Footer />
</VisuallyHidden>
<FeedbackWidget />
</ContentContainer>
</MainContent>
</MainContainer>
<ZenMode>
<Footer />
</ZenMode>
<FeedbackWidget />
</ContentContainer>
</ZenModeContext.Provider>
</ThemeProvider>
</ApolloProvider>
</IntlProvider>
Expand Down
43 changes: 0 additions & 43 deletions src/components/VisuallyHidden.tsx

This file was deleted.

20 changes: 20 additions & 0 deletions src/components/ZenMode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { useContext } from "react"
import { VisuallyHidden as ChakraVisuallyHidden } from "@chakra-ui/react"

import { ZenModeContext } from "../contexts/ZenModeContext"

export interface IProps {
children?: React.ReactNode
}

const ZenMode: React.FC<IProps> = ({ children }) => {
const { isZenMode } = useContext(ZenModeContext)

return isZenMode ? (
<ChakraVisuallyHidden>{children}</ChakraVisuallyHidden>
) : (
<>{children}</>
)
}

export default ZenMode