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

feat: add option to remove site switcher from header #1132

Merged
merged 2 commits into from
Jun 8, 2021
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
5 changes: 2 additions & 3 deletions packages/example/src/pages/guides/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,8 @@ plugins: [

- `mdxExtensions` – change the file extensions processed by `gatsby-mdx`
(default ['.mdx', '.md']).
- `pngCompressionSpeed` - a speed/quality trade-off from 1 (brute-force) to 10
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option doesn't work any more, removing the documentation ahead of actually removing it in the next major.

(fastest). Speed 10 has 5% lower quality, but is 8 times faster than the
default (4).
- `isSwitcherEnabled` - pass `false` to remove the Site switcher from the header
navigation.
- `titleType` – pick between four formats for the `<title>` element for your
site. Here are the four options using this page as an example:

Expand Down
2 changes: 2 additions & 0 deletions packages/gatsby-theme-carbon/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = (themeOptions) => {
remarkPlugins = [],
gatsbyPluginSharpOptions = {},
isServiceWorkerEnabled = false,
isSwitcherEnabled = true,
} = themeOptions;

const theme = { ...defaultTheme, ...themeOption };
Expand Down Expand Up @@ -78,6 +79,7 @@ module.exports = (themeOptions) => {
homepageTheme: theme.homepage,
interiorTheme: theme.interior,
isServiceWorkerEnabled,
isSwitcherEnabled,
title: 'Gatsby Theme Carbon',
description:
'Add a description by supplying it to siteMetadata in your gatsby-config.js file.',
Expand Down
30 changes: 16 additions & 14 deletions packages/gatsby-theme-carbon/src/components/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Header = ({ children }) => {
searchIsOpen,
switcherTooltipText = 'Switch sites',
} = useContext(NavContext);
const { isSearchEnabled, navigationStyle } = useMetadata();
const { isSearchEnabled, navigationStyle, isSwitcherEnabled } = useMetadata();

return (
<ShellHeader
Expand Down Expand Up @@ -55,19 +55,21 @@ const Header = ({ children }) => {
<HeaderGlobalBar
className={cx({ [styles.searchIsOpenOnBar]: searchIsOpen })}>
{isSearchEnabled && <GlobalSearch />}
<HeaderGlobalAction
className={cx(styles.headerButton, styles.switcherButton, {
[styles.switcherButtonOpen]: switcherIsOpen,
})}
aria-label={switcherTooltipText}
tooltipAlignment="end"
onClick={() => {
toggleNavState('switcherIsOpen');
toggleNavState('searchIsOpen', 'close');
toggleNavState('leftNavIsOpen', 'close');
}}>
{switcherIsOpen ? <Close20 /> : <Switcher20 />}
</HeaderGlobalAction>
{isSwitcherEnabled && (
<HeaderGlobalAction
className={cx(styles.headerButton, styles.switcherButton, {
[styles.switcherButtonOpen]: switcherIsOpen,
})}
aria-label={switcherTooltipText}
tooltipAlignment="end"
onClick={() => {
toggleNavState('switcherIsOpen');
toggleNavState('searchIsOpen', 'close');
toggleNavState('leftNavIsOpen', 'close');
}}>
{switcherIsOpen ? <Close20 /> : <Switcher20 />}
</HeaderGlobalAction>
)}
</HeaderGlobalBar>
</ShellHeader>
);
Expand Down
6 changes: 4 additions & 2 deletions packages/gatsby-theme-carbon/src/components/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Header from './Header';
import Switcher from './Switcher';
import Footer from './Footer';
import Container from './Container';
import useMetadata from '../util/hooks/useMetadata';

import '../styles/index.scss';

Expand All @@ -21,6 +22,7 @@ const Layout = ({
tabs,
}) => {
const is404 = children.key === null;
const { isSwitcherEnabled } = useMetadata();

useLayoutEffect(() => {
// eslint-disable-next-line global-require
Expand All @@ -43,8 +45,8 @@ const Layout = ({
pageDescription={pageDescription}
pageKeywords={pageKeywords}
/>
<Header />
<Switcher />
<Header isSwitcherEnabled={isSwitcherEnabled} />
{isSwitcherEnabled && <Switcher />}
<LeftNav homepage={homepage} is404Page={is404} theme={theme} />
<Container homepage={homepage} theme={theme}>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const useMetadata = () => {
description
keywords
isSearchEnabled
isSwitcherEnabled
homepageTheme
interiorTheme
navigationStyle
Expand Down