Skip to content

Commit

Permalink
chore: Add persistent close functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
LizBaker committed Feb 9, 2023
1 parent 110cfab commit 2832c53
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
16 changes: 14 additions & 2 deletions src/components/DocPageBanner.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// VSU
import React from 'react';
import { css } from '@emotion/react';
import { Button, Link } from '@newrelic/gatsby-theme-newrelic';
import { Button, Link, Icon } from '@newrelic/gatsby-theme-newrelic';
import lines from './bannerLines.svg';

const DocPageBanner = ({ text, cta, url, height }) => (
const DocPageBanner = ({ text, cta, url, height, onClose }) => (
<div
css={css`
height: ${height};
Expand Down Expand Up @@ -62,6 +62,18 @@ const DocPageBanner = ({ text, cta, url, height }) => (
>
{cta ?? 'Start now'}
</Button>
{onClose && (
<Icon
name="fe-x"
css={css`
color: white;
position: absolute;
top: 3px;
right: 3px;
`}
onClick={onClose}
/>
)}
</div>
</div>
);
Expand Down
26 changes: 23 additions & 3 deletions src/templates/docPage.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useMemo } from 'react';
import React, { useMemo, useState } from 'react';
import PropTypes from 'prop-types';
import { css } from '@emotion/react';
import { graphql } from 'gatsby';
import { takeWhile } from 'lodash';
import { createLocalStorageStateHook } from 'use-local-storage-state';
import PageTitle from '../components/PageTitle';
import DocPageBanner from '../components/DocPageBanner';
import MDXContainer from '../components/MDXContainer';
Expand All @@ -12,6 +13,7 @@ import {
RelatedResources,
ComplexFeedback,
TableOfContents,
useHasMounted,
} from '@newrelic/gatsby-theme-newrelic';
import MachineTranslationCallout from '../components/MachineTranslationCallout';
import SEO from '../components/SEO';
Expand Down Expand Up @@ -73,7 +75,6 @@ const BasicDoc = ({ data, location, pageContext }) => {
isTutorial,
signupBanner,
} = frontmatter;
console.log(signupBanner);

let { type } = frontmatter;

Expand All @@ -83,6 +84,23 @@ const BasicDoc = ({ data, location, pageContext }) => {
if (isTutorial) {
type = 'tutorial';
}
const useBannerDismissed = createLocalStorageStateHook(
`docBannerDismissed-${title}`
);

const [bannerDismissed, setBannerDismissed] = useBannerDismissed(null);
const [bannerVisible, setBannerVisible] = useState(bannerDismissed !== true);

const onCloseBanner = () => {
setBannerVisible(false);
setBannerDismissed(true);
};

const hasMounted = useHasMounted();

if (!hasMounted) {
return null;
}
return (
<>
<SEO
Expand All @@ -94,12 +112,13 @@ const BasicDoc = ({ data, location, pageContext }) => {
dataSource={dataSource}
disableSwiftype={disableSwiftype}
/>
{signupBanner && (
{signupBanner && bannerVisible && (
<DocPageBanner
height={bannerHeight}
text={signupBanner.text}
cta={signupBanner.cta}
url={signupBanner.url}
onClose={onCloseBanner}
/>
)}
<div
Expand All @@ -113,6 +132,7 @@ const BasicDoc = ({ data, location, pageContext }) => {
grid-column-gap: 2rem;
${signupBanner &&
bannerVisible &&
css`
margin-top: ${bannerHeight};
@media screen and (max-width: 760px) {
Expand Down

0 comments on commit 2832c53

Please sign in to comment.