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

Announcement Banner Fixes #725

Merged
merged 11 commits into from
Sep 9, 2020
5 changes: 4 additions & 1 deletion gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ exports.createPages = async ({ actions, graphql, reporter }) => {

const result = await graphql(`
{
allMdx(limit: 1000) {
allMdx(
limit: 1000
filter: { fileAbsolutePath: { regex: "/src/markdown-pages/" } }
) {
edges {
node {
fileAbsolutePath
Expand Down
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@emotion/styled": "^10.0.27",
"@mdx-js/mdx": "^1.6.16",
"@mdx-js/react": "^1.6.16",
"@newrelic/gatsby-theme-newrelic": "^1.9.1",
"@newrelic/gatsby-theme-newrelic": "^1.9.2",
"@splitsoftware/splitio-react": "^1.2.0",
"classnames": "^2.2.6",
"date-fns": "^2.15.0",
Expand Down
23 changes: 23 additions & 0 deletions src/hooks/useResizeObserver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useLayoutEffect, useState, useRef } from 'react';

const useResizeObserver = () => {
const ref = useRef(null);
const [height, setHeight] = useState(0);

// ResizeObserver is not available at build time
const ResizeObserver = global.ResizeObserver || class ResizeObserver {};

const resizeObserver = new ResizeObserver((entries) => {
entries.forEach((entry) => {
setHeight(entry.contentBoxSize.blockSize);
});
});

useLayoutEffect(() => {
resizeObserver.observe(ref.current);
}, [resizeObserver]);

return [ref, height];
};

export default useResizeObserver;
15 changes: 13 additions & 2 deletions src/layouts/MainLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Sidebar from '../components/Sidebar';
import CookieApprovalDialog from '../components/CookieApprovalDialog';
import '../components/styles.scss';
import usePageContext from '../hooks/usePageContext';
import useResizeObserver from '../hooks/useResizeObserver';
import { useLocation } from '@reach/router';

const gaTrackingId = 'UA-3047412-33';
Expand All @@ -36,6 +37,7 @@ const MainLayout = ({ children }) => {

const location = useLocation();
const { fileRelativePath } = usePageContext();
const [headerRef, headerHeight] = useResizeObserver();
const [cookieConsent, setCookieConsent] = useState(false);
const [isMobileNavOpen, setIsMobileNavOpen] = useState(false);
const isComponentDoc = fileRelativePath.includes(
Expand All @@ -57,7 +59,7 @@ const MainLayout = ({ children }) => {
return (
<div
css={css`
--global-header-height: 30px;
--global-header-height: ${headerHeight}px;
--sidebar-width: 300px;

min-height: 100vh;
Expand All @@ -79,7 +81,16 @@ const MainLayout = ({ children }) => {
</script>
) : null}
</Helmet>
<GlobalHeader editUrl={editUrl} />
<div
ref={headerRef}
css={css`
position: sticky;
z-index: 99;
top: 0;
`}
>
<GlobalHeader editUrl={editUrl} />
</div>
<MobileHeader
css={css`
@media (min-width: 761px) {
Expand Down